From: Ethan G. <ega...@us...> - 2002-03-15 03:01:51
|
Update of /cvsroot/nagios/nagios/xdata In directory usw-pr-cvs1:/tmp/cvs-serv5515/xdata Modified Files: xrddefault.c xrddefault.h Log Message: Retention fix for next notification time Index: xrddefault.c =================================================================== RCS file: /cvsroot/nagios/nagios/xdata/xrddefault.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -r1.1.1.1 -r1.2 *** xrddefault.c 26 Feb 2002 04:04:11 -0000 1.1.1.1 --- xrddefault.c 15 Mar 2002 03:01:48 -0000 1.2 *************** *** 3,8 **** * XRDDEFAULT.C - Default external state retention routines for Nagios * ! * Copyright (c) 1999-2001 Ethan Galstad (na...@na...) ! * Last Modified: 10-20-2001 * * License: --- 3,8 ---- * XRDDEFAULT.C - Default external state retention routines for Nagios * ! * Copyright (c) 1999-2002 Ethan Galstad (na...@na...) ! * Last Modified: 03-14-2002 * * License: *************** *** 38,50 **** #include "xrddefault.h" ! #define XRDDEFAULT_VERSION_UNKNOWN 0 ! #define XRDDEFAULT_VERSION_1 1 ! #define XRDDEFAULT_VERSION_2 2 - int xrddefault_file_version=XRDDEFAULT_VERSION_UNKNOWN; /******************************************************************/ /**************** DEFAULT STATE OUTPUT FUNCTION *******************/ /******************************************************************/ --- 38,105 ---- #include "xrddefault.h" ! char xrddefault_retention_file[MAX_FILENAME_LENGTH]=""; /******************************************************************/ + /********************* CONFIG INITIALIZATION *********************/ + /******************************************************************/ + + int xrddefault_grab_config_info(char *main_config_file){ + char temp_buffer[MAX_INPUT_BUFFER]; + char *temp_ptr; + FILE *fp; + + + /* initialize the location of the retention file */ + strncpy(xrddefault_retention_file,DEFAULT_RETENTION_FILE,sizeof(xrddefault_retention_file)-1); + xrddefault_retention_file[sizeof(xrddefault_retention_file)-1]='\x0'; + + /* open the main config file for reading */ + fp=fopen(main_config_file,"r"); + if(fp==NULL){ + #ifdef DEBUG1 + printf("Error: Cannot open main configuration file '%s' for reading!\n",main_config_file); + #endif + return ERROR; + } + + /* read in all lines from the main config file */ + while(fgets(temp_buffer,sizeof(temp_buffer)-1,fp)){ + + if(feof(fp)) + break; + + /* skip blank lines and comments */ + if(temp_buffer[0]=='#' || temp_buffer[0]=='\x0' || temp_buffer[0]=='\n' || temp_buffer[0]=='\r') + continue; + + strip(temp_buffer); + + temp_ptr=my_strtok(temp_buffer,"="); + if(temp_ptr==NULL) + continue; + + /* skip lines that don't specify the host config file location */ + if(strcmp(temp_ptr,"xrddefault_retention_file") && strcmp(temp_ptr,"state_retention_file")) + continue; + + /* get the retention file name */ + temp_ptr=my_strtok(NULL,"\n"); + if(temp_ptr==NULL) + continue; + + strncpy(xrddefault_retention_file,temp_ptr,sizeof(xrddefault_retention_file)-1); + xrddefault_retention_file[sizeof(xrddefault_retention_file)-1]='\x0'; + } + + fclose(fp); + + return OK; + } + + + /******************************************************************/ /**************** DEFAULT STATE OUTPUT FUNCTION *******************/ /******************************************************************/ *************** *** 52,56 **** int xrddefault_save_state_information(char *main_config_file){ char temp_buffer[MAX_INPUT_BUFFER]; - char retention_file[MAX_FILENAME_LENGTH]=""; char *temp_ptr; time_t current_time; --- 107,110 ---- *************** *** 97,146 **** #endif ! /* open the main config file for reading */ ! fp=fopen(main_config_file,"r"); ! if(fp==NULL){ ! #ifdef DEBUG1 ! printf("Error: Cannot open main configuration file '%s' for reading!\n",main_config_file); ! #endif ! return ERROR; ! } ! ! /* read in all lines from the main config file */ ! while(fgets(temp_buffer,sizeof(temp_buffer)-1,fp)){ ! ! if(feof(fp)) ! break; ! ! /* skip blank lines and comments */ ! if(temp_buffer[0]=='#' || temp_buffer[0]=='\x0' || temp_buffer[0]=='\n' || temp_buffer[0]=='\r') ! continue; ! ! strip(temp_buffer); ! ! temp_ptr=my_strtok(temp_buffer,"="); ! if(temp_ptr==NULL) ! continue; ! ! /* skip lines that don't specify the host config file location */ ! if(strcmp(temp_ptr,"xrddefault_retention_file") && strcmp(temp_ptr,"state_retention_file")) ! continue; ! ! /* get the retention file name */ ! temp_ptr=my_strtok(NULL,"\n"); ! if(temp_ptr==NULL) ! continue; ! strncpy(retention_file,temp_ptr,sizeof(retention_file)-1); ! retention_file[sizeof(retention_file)-1]='\x0'; } - fclose(fp); - /* open the retention file for writing */ ! fp=fopen(retention_file,"w"); if(fp==NULL){ #ifdef DEBUG1 ! printf("Error: Cannot open state retention file '%s' for writing!\n",retention_file); #endif return ERROR; --- 151,169 ---- #endif + /* grab config info */ + if(xrddefault_grab_config_info(main_config_file)==ERROR){ ! snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Failed to grab configuration information for retention data\n"); ! temp_buffer[sizeof(temp_buffer)-1]='\x0'; ! write_to_logs_and_console(temp_buffer,NSLOG_RUNTIME_ERROR,TRUE); ! return ERROR; } /* open the retention file for writing */ ! fp=fopen(xrddefault_retention_file,"w"); if(fp==NULL){ #ifdef DEBUG1 ! printf("Error: Cannot open state retention file '%s' for writing!\n",xrddefault_retention_file); #endif return ERROR; *************** *** 164,169 **** /* save host state information */ ! temp_host=get_host_state_information(NULL,&host_name,&state,&plugin_output,&last_check,&checks_enabled,&time_up,&time_down,&time_unreachable,&last_notification,¤t_notification_number,¬ifications_enabled,&event_handler_enabled,&problem_has_been_acknowledged,&flap_detection_enabled,&failure_prediction_enabled,&process_performance_data,&last_state_change); ! while(temp_host!=NULL){ snprintf(temp_buffer,sizeof(temp_buffer)-1,"HOST: %s;%d;%lu;%d;%lu;%lu;%lu;%lu;%d;%d;%d;%d;%d;%d;%d;%lu;%s\n",host_name,state,last_check,checks_enabled,time_up,time_down,time_unreachable,last_notification,current_notification_number,notifications_enabled,event_handler_enabled,problem_has_been_acknowledged,flap_detection_enabled,failure_prediction_enabled,process_performance_data,last_state_change,plugin_output); --- 187,192 ---- /* save host state information */ ! temp_host=NULL; ! while((temp_host=get_host_state_information(temp_host,&host_name,&state,&plugin_output,&last_check,&checks_enabled,&time_up,&time_down,&time_unreachable,&last_notification,¤t_notification_number,¬ifications_enabled,&event_handler_enabled,&problem_has_been_acknowledged,&flap_detection_enabled,&failure_prediction_enabled,&process_performance_data,&last_state_change))!=NULL){ snprintf(temp_buffer,sizeof(temp_buffer)-1,"HOST: %s;%d;%lu;%d;%lu;%lu;%lu;%lu;%d;%d;%d;%d;%d;%d;%d;%lu;%s\n",host_name,state,last_check,checks_enabled,time_up,time_down,time_unreachable,last_notification,current_notification_number,notifications_enabled,event_handler_enabled,problem_has_been_acknowledged,flap_detection_enabled,failure_prediction_enabled,process_performance_data,last_state_change,plugin_output); *************** *** 171,181 **** fputs(temp_buffer,fp); - - temp_host=get_host_state_information(temp_host,&host_name,&state,&plugin_output,&last_check,&checks_enabled,&time_up,&time_down,&time_unreachable,&last_notification,¤t_notification_number,¬ifications_enabled,&event_handler_enabled,&problem_has_been_acknowledged,&flap_detection_enabled,&failure_prediction_enabled,&process_performance_data,&last_state_change); } /* save service state information */ ! temp_service=get_service_state_information(NULL,&host_name,&service_description,&state,&plugin_output,&last_check,&check_type,&time_ok,&time_warning,&time_unknown,&time_critical,&last_notification,¤t_notification_number,¬ifications_enabled,&checks_enabled,&accept_passive_checks,&event_handler_enabled,&problem_has_been_acknowledged,&flap_detection_enabled,&failure_prediction_enabled,&process_performance_data,&obsess_over_service,&last_state_change); ! while(temp_service!=NULL){ snprintf(temp_buffer,sizeof(temp_buffer)-1,"SERVICE: %s;%s;%d;%lu;%d;%lu;%lu;%lu;%lu;%lu;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%lu;%s\n",host_name,service_description,state,last_check,check_type,time_ok,time_warning,time_unknown,time_critical,last_notification,current_notification_number,notifications_enabled,checks_enabled,accept_passive_checks,event_handler_enabled,problem_has_been_acknowledged,flap_detection_enabled,failure_prediction_enabled,process_performance_data,obsess_over_service,last_state_change,plugin_output); --- 194,202 ---- fputs(temp_buffer,fp); } /* save service state information */ ! temp_service=NULL; ! while((temp_service=get_service_state_information(temp_service,&host_name,&service_description,&state,&plugin_output,&last_check,&check_type,&time_ok,&time_warning,&time_unknown,&time_critical,&last_notification,¤t_notification_number,¬ifications_enabled,&checks_enabled,&accept_passive_checks,&event_handler_enabled,&problem_has_been_acknowledged,&flap_detection_enabled,&failure_prediction_enabled,&process_performance_data,&obsess_over_service,&last_state_change))!=NULL){ snprintf(temp_buffer,sizeof(temp_buffer)-1,"SERVICE: %s;%s;%d;%lu;%d;%lu;%lu;%lu;%lu;%lu;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%lu;%s\n",host_name,service_description,state,last_check,check_type,time_ok,time_warning,time_unknown,time_critical,last_notification,current_notification_number,notifications_enabled,checks_enabled,accept_passive_checks,event_handler_enabled,problem_has_been_acknowledged,flap_detection_enabled,failure_prediction_enabled,process_performance_data,obsess_over_service,last_state_change,plugin_output); *************** *** 183,188 **** fputs(temp_buffer,fp); - - temp_service=get_service_state_information(temp_service,&host_name,&service_description,&state,&plugin_output,&last_check,&check_type,&time_ok,&time_warning,&time_unknown,&time_critical,&last_notification,¤t_notification_number,¬ifications_enabled,&checks_enabled,&accept_passive_checks,&event_handler_enabled,&problem_has_been_acknowledged,&flap_detection_enabled,&failure_prediction_enabled,&process_performance_data,&obsess_over_service,&last_state_change); } --- 204,207 ---- *************** *** 207,211 **** int xrddefault_read_state_information(char *main_config_file){ char temp_buffer[MAX_INPUT_BUFFER]; - char retention_file[MAX_FILENAME_LENGTH]=""; char *temp_ptr; time_t current_time; --- 226,229 ---- *************** *** 250,298 **** #endif ! /* open the main config file for reading */ ! fp=fopen(main_config_file,"r"); ! if(fp==NULL){ ! #ifdef DEBUG1 ! printf("Error: Cannot open main configuration file '%s' for reading!\n",main_config_file); ! #endif ! return ERROR; ! } ! /* read in all lines from the main config file */ ! while(fgets(temp_buffer,sizeof(temp_buffer)-1,fp)){ ! ! if(feof(fp)) ! break; ! ! /* skip blank lines and comments */ ! if(temp_buffer[0]=='#' || temp_buffer[0]=='\x0' || temp_buffer[0]=='\n' || temp_buffer[0]=='\r') ! continue; ! ! strip(temp_buffer); ! ! temp_ptr=my_strtok(temp_buffer,"="); ! if(temp_ptr==NULL) ! continue; ! ! /* skip lines that don't specify the host config file location */ ! if(strcmp(temp_ptr,"xrddefault_retention_file") && strcmp(temp_ptr,"state_retention_file")) ! continue; ! ! /* get the retention file name */ ! temp_ptr=my_strtok(NULL,"\n"); ! if(temp_ptr==NULL) ! continue; ! strncpy(retention_file,temp_ptr,sizeof(retention_file)-1); ! retention_file[sizeof(retention_file)-1]='\x0'; } - fclose(fp); - /* open the retention file for reading */ ! fp=fopen(retention_file,"r"); if(fp==NULL){ #ifdef DEBUG1 ! printf("Error: Cannot open state retention file '%s' for reading!\n",retention_file); #endif return ERROR; --- 268,286 ---- #endif ! /* grab config info */ ! if(xrddefault_grab_config_info(main_config_file)==ERROR){ ! snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Failed to grab configuration information for retention data\n"); ! temp_buffer[sizeof(temp_buffer)-1]='\x0'; ! write_to_logs_and_console(temp_buffer,NSLOG_RUNTIME_ERROR,TRUE); ! return ERROR; } /* open the retention file for reading */ ! fp=fopen(xrddefault_retention_file,"r"); if(fp==NULL){ #ifdef DEBUG1 ! printf("Error: Cannot open state retention file '%s' for reading!\n",xrddefault_retention_file); #endif return ERROR; *************** *** 312,329 **** if(temp_buffer[0]=='\x0' || temp_buffer[0]=='\n' || temp_buffer[0]=='\r') continue; - - /* check comments for file version info */ - if(temp_buffer[0]=='#'){ - - /* pre-0.0.7a5 file version */ - if(strstr(temp_buffer,"Nagios Host/Service")) - xrddefault_file_version=XRDDEFAULT_VERSION_UNKNOWN; - - /* else get version info */ - else if(strstr(temp_buffer,"Retention File")) - xrddefault_file_version=XRDDEFAULT_VERSION_2; - - continue; - } strip(temp_buffer); --- 300,303 ---- Index: xrddefault.h =================================================================== RCS file: /cvsroot/nagios/nagios/xdata/xrddefault.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -r1.1.1.1 -r1.2 *** xrddefault.h 26 Feb 2002 04:04:11 -0000 1.1.1.1 --- xrddefault.h 15 Mar 2002 03:01:48 -0000 1.2 *************** *** 3,8 **** * XRDDEFAULT.H - Header file for default state retention routines * ! * Copyright (c) 1999-2001 Ethan Galstad (na...@na...) ! * Last Modified: 05-07-2001 * * License: --- 3,8 ---- * XRDDEFAULT.H - Header file for default state retention routines * ! * Copyright (c) 1999-2002 Ethan Galstad (na...@na...) ! * Last Modified: 03-14-2002 * * License: *************** *** 25,28 **** --- 25,29 ---- + int xrddefault_grab_config_info(char *); int xrddefault_save_state_information(char *); /* saves all host and service state information */ int xrddefault_read_state_information(char *); /* reads in initial host and service state information */ |