![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /***************************************************************************** 00002 * 00003 * XSDDEFAULT.C - Default external status data input routines for Icinga 00004 * 00005 * Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org) 00006 * Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors 00007 * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) 00008 * 00009 * License: 00010 * 00011 * This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License version 2 as 00013 * published by the Free Software Foundation. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00023 * 00024 *****************************************************************************/ 00025 00026 00027 /*********** COMMON HEADER FILES ***********/ 00028 00029 #include "../include/config.h" 00030 #include "../include/common.h" 00031 #include "../include/locations.h" 00032 #include "../include/statusdata.h" 00033 #include "../include/comments.h" 00034 #include "../include/downtime.h" 00035 #include "../include/macros.h" 00036 #include "../include/skiplist.h" 00037 00038 /* make sure gcc3 won't hit here */ 00039 #ifndef GCCTOOOLD 00040 #include "../include/statsprofiler.h" 00041 #include "../include/profiler.h" 00042 #endif 00043 00044 #ifdef NSCORE 00045 #include "../include/icinga.h" 00046 #endif 00047 00048 #ifdef NSCGI 00049 #include "../include/cgiutils.h" 00050 #endif 00051 00052 00053 /**** IMPLEMENTATION SPECIFIC HEADER FILES ****/ 00054 #include "xsddefault.h" 00055 00056 00057 00058 #ifdef NSCGI 00059 time_t program_start; 00060 int daemon_mode; 00061 time_t last_command_check; 00062 time_t last_log_rotation; 00063 int enable_notifications; 00064 int execute_service_checks; 00065 int accept_passive_service_checks; 00066 int execute_host_checks; 00067 int accept_passive_host_checks; 00068 int enable_event_handlers; 00069 int obsess_over_services; 00070 int obsess_over_hosts; 00071 int check_service_freshness; 00072 int check_host_freshness; 00073 int enable_flap_detection; 00074 int enable_failure_prediction; 00075 int process_performance_data; 00076 int nagios_pid; 00077 int buffer_stats[1][3]; 00078 int program_stats[MAX_CHECK_STATS_TYPES][3]; 00079 /* make sure gcc3 won't hit here */ 00080 #ifndef GCCTOOOLD 00081 int event_profiling_enabled; 00082 profile_object* profiled_data = NULL; 00083 #endif 00084 #endif 00085 00086 #ifdef NSCORE 00087 extern time_t program_start; 00088 extern int nagios_pid; 00089 extern int daemon_mode; 00090 extern time_t last_command_check; 00091 extern time_t last_log_rotation; 00092 extern int enable_notifications; 00093 extern int execute_service_checks; 00094 extern int accept_passive_service_checks; 00095 extern int execute_host_checks; 00096 extern int accept_passive_host_checks; 00097 extern int enable_event_handlers; 00098 extern int obsess_over_services; 00099 extern int obsess_over_hosts; 00100 extern int check_service_freshness; 00101 extern int check_host_freshness; 00102 extern int enable_flap_detection; 00103 extern int enable_failure_prediction; 00104 extern int process_performance_data; 00105 extern int aggregate_status_updates; 00106 extern int check_external_commands; 00107 00108 extern int external_command_buffer_slots; 00109 extern circular_buffer external_command_buffer; 00110 00111 extern host *host_list; 00112 extern service *service_list; 00113 extern contact *contact_list; 00114 extern comment *comment_list; 00115 extern scheduled_downtime *scheduled_downtime_list; 00116 00117 extern skiplist *object_skiplists[NUM_OBJECT_SKIPLISTS]; 00118 00119 extern unsigned long next_comment_id; 00120 extern unsigned long next_downtime_id; 00121 extern unsigned long next_event_id; 00122 extern unsigned long next_problem_id; 00123 extern unsigned long next_notification_id; 00124 00125 extern unsigned long modified_host_process_attributes; 00126 extern unsigned long modified_service_process_attributes; 00127 extern char *global_host_event_handler; 00128 extern char *global_service_event_handler; 00129 00130 extern check_stats check_statistics[MAX_CHECK_STATS_TYPES]; 00131 /* make sure gcc3 won't hit here */ 00132 #ifndef GCCTOOOLD 00133 extern int event_profiling_enabled; 00134 #endif 00135 #endif 00136 00137 00138 char *xsddefault_status_log=NULL; 00139 char *xsddefault_temp_file=NULL; 00140 00141 00142 00143 /******************************************************************/ 00144 /***************** COMMON CONFIG INITIALIZATION ******************/ 00145 /******************************************************************/ 00146 00147 /* grab configuration information */ 00148 int xsddefault_grab_config_info(char *config_file){ 00149 char *input=NULL; 00150 mmapfile *thefile; 00151 #ifdef NSCGI 00152 char *input2=NULL; 00153 mmapfile *thefile2; 00154 char *temp_buffer; 00155 #else 00156 icinga_macros *mac; 00157 #endif 00158 00159 00160 /*** CORE PASSES IN MAIN CONFIG FILE, CGIS PASS IN CGI CONFIG FILE! ***/ 00161 00162 /* open the config file for reading */ 00163 if((thefile=mmap_fopen(config_file))==NULL) 00164 return ERROR; 00165 00166 /* read in all lines from the main config file */ 00167 while(1){ 00168 00169 /* free memory */ 00170 my_free(input); 00171 00172 /* read the next line */ 00173 if((input=mmap_fgets_multiline(thefile))==NULL) 00174 break; 00175 00176 strip(input); 00177 00178 /* skip blank lines and comments */ 00179 if(input[0]=='#' || input[0]=='\x0') 00180 continue; 00181 00182 #ifdef NSCGI 00183 /* CGI needs to find and read contents of main config file, since it was passed the name of the CGI config file */ 00184 if(strstr(input,"main_config_file")==input){ 00185 00186 temp_buffer=strtok(input,"="); 00187 temp_buffer=strtok(NULL,"\n"); 00188 if(temp_buffer==NULL) 00189 continue; 00190 00191 if((thefile2=mmap_fopen(temp_buffer))==NULL) 00192 continue; 00193 00194 /* read in all lines from the main config file */ 00195 while(1){ 00196 00197 /* free memory */ 00198 my_free(input2); 00199 00200 /* read the next line */ 00201 if((input2=mmap_fgets_multiline(thefile2))==NULL) 00202 break; 00203 00204 strip(input2); 00205 00206 /* skip blank lines and comments */ 00207 if(input2[0]=='#' || input2[0]=='\x0') 00208 continue; 00209 00210 xsddefault_grab_config_directives(input2); 00211 } 00212 00213 /* free memory and close the file */ 00214 my_free(input2); 00215 mmap_fclose(thefile2); 00216 } 00217 #endif 00218 00219 #ifdef NSCORE 00220 /* core reads variables directly from the main config file */ 00221 xsddefault_grab_config_directives(input); 00222 #endif 00223 } 00224 00225 /* free memory and close the file */ 00226 my_free(input); 00227 mmap_fclose(thefile); 00228 00229 /* initialize locations if necessary */ 00230 if(xsddefault_status_log==NULL) 00231 xsddefault_status_log=(char *)strdup(DEFAULT_STATUS_FILE); 00232 if(xsddefault_temp_file==NULL) 00233 xsddefault_temp_file=(char *)strdup(DEFAULT_TEMP_FILE); 00234 00235 /* make sure we have what we need */ 00236 if(xsddefault_status_log==NULL) 00237 return ERROR; 00238 if(xsddefault_temp_file==NULL) 00239 return ERROR; 00240 00241 #ifdef NSCORE 00242 mac = get_global_macros(); 00243 00244 /* save the status file macro */ 00245 my_free(mac->x[MACRO_STATUSDATAFILE]); 00246 if((mac->x[MACRO_STATUSDATAFILE]=(char *)strdup(xsddefault_status_log))) 00247 strip(mac->x[MACRO_STATUSDATAFILE]); 00248 #endif 00249 00250 return OK; 00251 } 00252 00253 00254 /* processes a single directive */ 00255 int xsddefault_grab_config_directives(char *input){ 00256 char *temp_ptr=NULL; 00257 char *varname=NULL; 00258 char *varvalue=NULL; 00259 00260 /* get the variable name */ 00261 if((temp_ptr=my_strtok(input,"="))==NULL) 00262 return ERROR; 00263 if((varname=(char *)strdup(temp_ptr))==NULL) 00264 return ERROR; 00265 00266 /* get the variable value */ 00267 if((temp_ptr=my_strtok(NULL,"\n"))==NULL){ 00268 my_free(varname); 00269 return ERROR; 00270 } 00271 if((varvalue=(char *)strdup(temp_ptr))==NULL){ 00272 my_free(varname); 00273 return ERROR; 00274 } 00275 00276 /* status log definition */ 00277 if(!strcmp(varname,"status_file") || !strcmp(varname,"xsddefault_status_log")) 00278 xsddefault_status_log=(char *)strdup(temp_ptr); 00279 00280 /* temp file definition */ 00281 else if(!strcmp(varname,"temp_file")) 00282 xsddefault_temp_file=(char *)strdup(temp_ptr); 00283 00284 /* free memory */ 00285 my_free(varname); 00286 my_free(varvalue); 00287 00288 return OK; 00289 } 00290 00291 00292 00293 #ifdef NSCORE 00294 00295 /******************************************************************/ 00296 /********************* INIT/CLEANUP FUNCTIONS *********************/ 00297 /******************************************************************/ 00298 00299 00300 /* initialize status data */ 00301 int xsddefault_initialize_status_data(char *config_file){ 00302 int result; 00303 00304 /* grab configuration data */ 00305 result=xsddefault_grab_config_info(config_file); 00306 if(result==ERROR) 00307 return ERROR; 00308 00309 /* delete the old status log (it might not exist) */ 00310 if(xsddefault_status_log) 00311 unlink(xsddefault_status_log); 00312 00313 return OK; 00314 } 00315 00316 00317 /* cleanup status data before terminating */ 00318 int xsddefault_cleanup_status_data(char *config_file, int delete_status_data){ 00319 00320 /* delete the status log */ 00321 if(delete_status_data==TRUE && xsddefault_status_log){ 00322 if(unlink(xsddefault_status_log)) 00323 return ERROR; 00324 } 00325 00326 /* free memory */ 00327 my_free(xsddefault_status_log); 00328 my_free(xsddefault_temp_file); 00329 00330 return OK; 00331 } 00332 00333 00334 /******************************************************************/ 00335 /****************** STATUS DATA OUTPUT FUNCTIONS ******************/ 00336 /******************************************************************/ 00337 00338 /* write all status data to file */ 00339 int xsddefault_save_status_data(void){ 00340 char *temp_file=NULL; 00341 customvariablesmember *temp_customvariablesmember=NULL; 00342 host *temp_host=NULL; 00343 service *temp_service=NULL; 00344 contact *temp_contact=NULL; 00345 comment *temp_comment=NULL; 00346 scheduled_downtime *temp_downtime=NULL; 00347 time_t current_time; 00348 int fd=0; 00349 int dummy; /* reduce compiler warnings */ 00350 FILE *fp=NULL; 00351 int used_external_command_buffer_slots=0; 00352 int high_external_command_buffer_slots=0; 00353 int result=OK; 00354 00355 log_debug_info(DEBUGL_FUNCTIONS,0,"save_status_data()\n"); 00356 00357 /* open a safe temp file for output */ 00358 if(xsddefault_temp_file==NULL) 00359 return ERROR; 00360 dummy=asprintf(&temp_file,"%sXXXXXX",xsddefault_temp_file); 00361 if(temp_file==NULL) 00362 return ERROR; 00363 00364 log_debug_info(DEBUGL_STATUSDATA,2,"Writing status data to temp file '%s'\n",temp_file); 00365 00366 if((fd=mkstemp(temp_file))==-1){ 00367 00368 /* log an error */ 00369 logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Unable to create temp file for writing status data: %s\n", strerror(errno)); 00370 00371 /* free memory */ 00372 my_free(temp_file); 00373 00374 return ERROR; 00375 } 00376 fp=(FILE *)fdopen(fd,"w"); 00377 if(fp==NULL){ 00378 00379 close(fd); 00380 unlink(temp_file); 00381 00382 /* log an error */ 00383 logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Unable to open temp file '%s' for writing status data: %s\n",temp_file, strerror(errno)); 00384 00385 /* free memory */ 00386 my_free(temp_file); 00387 00388 return ERROR; 00389 } 00390 00391 /* get number of items in the command buffer */ 00392 if(check_external_commands==TRUE){ 00393 pthread_mutex_lock(&external_command_buffer.buffer_lock); 00394 used_external_command_buffer_slots=external_command_buffer.items; 00395 high_external_command_buffer_slots=external_command_buffer.high; 00396 pthread_mutex_unlock(&external_command_buffer.buffer_lock); 00397 } 00398 else{ 00399 used_external_command_buffer_slots=0; 00400 high_external_command_buffer_slots=0; 00401 } 00402 00403 /* generate check statistics */ 00404 generate_check_stats(); 00405 00406 /* write version info to status file */ 00407 fprintf(fp,"########################################\n"); 00408 fprintf(fp,"# %s STATUS FILE\n", PROGRAM_NAME_UC); 00409 fprintf(fp,"#\n"); 00410 fprintf(fp,"# THIS FILE IS AUTOMATICALLY GENERATED\n"); 00411 fprintf(fp,"# BY %s. DO NOT MODIFY THIS FILE!\n", PROGRAM_NAME_UC); 00412 fprintf(fp,"########################################\n\n"); 00413 00414 time(¤t_time); 00415 00416 /* write file info */ 00417 fprintf(fp,"info {\n"); 00418 fprintf(fp,"\tcreated=%lu\n",current_time); 00419 fprintf(fp,"\tversion=%s\n",PROGRAM_VERSION); 00420 fprintf(fp,"\t}\n\n"); 00421 00422 /* save program status data */ 00423 fprintf(fp,"programstatus {\n"); 00424 fprintf(fp,"\tmodified_host_attributes=%lu\n",modified_host_process_attributes); 00425 fprintf(fp,"\tmodified_service_attributes=%lu\n",modified_service_process_attributes); 00426 fprintf(fp,"\ticinga_pid=%d\n",nagios_pid); 00427 fprintf(fp,"\tdaemon_mode=%d\n",daemon_mode); 00428 fprintf(fp,"\tprogram_start=%lu\n",program_start); 00429 fprintf(fp,"\tlast_command_check=%lu\n",last_command_check); 00430 fprintf(fp,"\tlast_log_rotation=%lu\n",last_log_rotation); 00431 fprintf(fp,"\tenable_notifications=%d\n",enable_notifications); 00432 fprintf(fp,"\tactive_service_checks_enabled=%d\n",execute_service_checks); 00433 fprintf(fp,"\tpassive_service_checks_enabled=%d\n",accept_passive_service_checks); 00434 fprintf(fp,"\tactive_host_checks_enabled=%d\n",execute_host_checks); 00435 fprintf(fp,"\tpassive_host_checks_enabled=%d\n",accept_passive_host_checks); 00436 fprintf(fp,"\tenable_event_handlers=%d\n",enable_event_handlers); 00437 fprintf(fp,"\tobsess_over_services=%d\n",obsess_over_services); 00438 fprintf(fp,"\tobsess_over_hosts=%d\n",obsess_over_hosts); 00439 fprintf(fp,"\tcheck_service_freshness=%d\n",check_service_freshness); 00440 fprintf(fp,"\tcheck_host_freshness=%d\n",check_host_freshness); 00441 fprintf(fp,"\tenable_flap_detection=%d\n",enable_flap_detection); 00442 fprintf(fp,"\tenable_failure_prediction=%d\n",enable_failure_prediction); 00443 fprintf(fp,"\tprocess_performance_data=%d\n",process_performance_data); 00444 fprintf(fp,"\tglobal_host_event_handler=%s\n",(global_host_event_handler==NULL)?"":global_host_event_handler); 00445 fprintf(fp,"\tglobal_service_event_handler=%s\n",(global_service_event_handler==NULL)?"":global_service_event_handler); 00446 fprintf(fp,"\tnext_comment_id=%lu\n",next_comment_id); 00447 fprintf(fp,"\tnext_downtime_id=%lu\n",next_downtime_id); 00448 fprintf(fp,"\tnext_event_id=%lu\n",next_event_id); 00449 fprintf(fp,"\tnext_problem_id=%lu\n",next_problem_id); 00450 fprintf(fp,"\tnext_notification_id=%lu\n",next_notification_id); 00451 fprintf(fp,"\ttotal_external_command_buffer_slots=%d\n",external_command_buffer_slots); 00452 fprintf(fp,"\tused_external_command_buffer_slots=%d\n",used_external_command_buffer_slots); 00453 fprintf(fp,"\thigh_external_command_buffer_slots=%d\n",high_external_command_buffer_slots); 00454 fprintf(fp,"\tactive_scheduled_host_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_SCHEDULED_HOST_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_SCHEDULED_HOST_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_SCHEDULED_HOST_CHECK_STATS].minute_stats[2]); 00455 fprintf(fp,"\tactive_ondemand_host_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_ONDEMAND_HOST_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_ONDEMAND_HOST_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_ONDEMAND_HOST_CHECK_STATS].minute_stats[2]); 00456 fprintf(fp,"\tpassive_host_check_stats=%d,%d,%d\n",check_statistics[PASSIVE_HOST_CHECK_STATS].minute_stats[0],check_statistics[PASSIVE_HOST_CHECK_STATS].minute_stats[1],check_statistics[PASSIVE_HOST_CHECK_STATS].minute_stats[2]); 00457 fprintf(fp,"\tactive_scheduled_service_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS].minute_stats[2]); 00458 fprintf(fp,"\tactive_ondemand_service_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS].minute_stats[2]); 00459 fprintf(fp,"\tpassive_service_check_stats=%d,%d,%d\n",check_statistics[PASSIVE_SERVICE_CHECK_STATS].minute_stats[0],check_statistics[PASSIVE_SERVICE_CHECK_STATS].minute_stats[1],check_statistics[PASSIVE_SERVICE_CHECK_STATS].minute_stats[2]); 00460 fprintf(fp,"\tcached_host_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_CACHED_HOST_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_CACHED_HOST_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_CACHED_HOST_CHECK_STATS].minute_stats[2]); 00461 fprintf(fp,"\tcached_service_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_CACHED_SERVICE_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_CACHED_SERVICE_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_CACHED_SERVICE_CHECK_STATS].minute_stats[2]); 00462 fprintf(fp,"\texternal_command_stats=%d,%d,%d\n",check_statistics[EXTERNAL_COMMAND_STATS].minute_stats[0],check_statistics[EXTERNAL_COMMAND_STATS].minute_stats[1],check_statistics[EXTERNAL_COMMAND_STATS].minute_stats[2]); 00463 00464 fprintf(fp,"\tparallel_host_check_stats=%d,%d,%d\n",check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[0],check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[1],check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[2]); 00465 fprintf(fp,"\tserial_host_check_stats=%d,%d,%d\n",check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[0],check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[1],check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[2]); 00466 00467 /* make sure gcc3 won't hit here */ 00468 #ifndef GCCTOOOLD 00469 fprintf(fp,"\tevent_profiling_enabled=%d\n",event_profiling_enabled); 00470 00471 if(event_profiling_enabled) 00472 profiler_output(fp); 00473 #endif 00474 00475 fprintf(fp,"\t}\n\n"); 00476 00477 00478 /* save host status data */ 00479 for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ 00480 00481 fprintf(fp,"hoststatus {\n"); 00482 fprintf(fp,"\thost_name=%s\n",temp_host->name); 00483 00484 fprintf(fp,"\tmodified_attributes=%lu\n",temp_host->modified_attributes); 00485 fprintf(fp,"\tcheck_command=%s\n",(temp_host->host_check_command==NULL)?"":temp_host->host_check_command); 00486 fprintf(fp,"\tcheck_period=%s\n",(temp_host->check_period==NULL)?"":temp_host->check_period); 00487 fprintf(fp,"\tnotification_period=%s\n",(temp_host->notification_period==NULL)?"":temp_host->notification_period); 00488 fprintf(fp,"\tcheck_interval=%f\n",temp_host->check_interval); 00489 fprintf(fp,"\tretry_interval=%f\n",temp_host->retry_interval); 00490 fprintf(fp,"\tevent_handler=%s\n",(temp_host->event_handler==NULL)?"":temp_host->event_handler); 00491 00492 fprintf(fp,"\thas_been_checked=%d\n",temp_host->has_been_checked); 00493 fprintf(fp,"\tshould_be_scheduled=%d\n",temp_host->should_be_scheduled); 00494 fprintf(fp,"\tcheck_execution_time=%.3f\n",temp_host->execution_time); 00495 fprintf(fp,"\tcheck_latency=%.3f\n",temp_host->latency); 00496 fprintf(fp,"\tcheck_type=%d\n",temp_host->check_type); 00497 fprintf(fp,"\tcurrent_state=%d\n",temp_host->current_state); 00498 fprintf(fp,"\tlast_hard_state=%d\n",temp_host->last_hard_state); 00499 fprintf(fp,"\tlast_event_id=%lu\n",temp_host->last_event_id); 00500 fprintf(fp,"\tcurrent_event_id=%lu\n",temp_host->current_event_id); 00501 fprintf(fp,"\tcurrent_problem_id=%lu\n",temp_host->current_problem_id); 00502 fprintf(fp,"\tlast_problem_id=%lu\n",temp_host->last_problem_id); 00503 fprintf(fp,"\tplugin_output=%s\n",(temp_host->plugin_output==NULL)?"":temp_host->plugin_output); 00504 fprintf(fp,"\tlong_plugin_output=%s\n",(temp_host->long_plugin_output==NULL)?"":temp_host->long_plugin_output); 00505 fprintf(fp,"\tperformance_data=%s\n",(temp_host->perf_data==NULL)?"":temp_host->perf_data); 00506 fprintf(fp,"\tlast_check=%lu\n",temp_host->last_check); 00507 fprintf(fp,"\tnext_check=%lu\n",temp_host->next_check); 00508 fprintf(fp,"\tcheck_options=%d\n",temp_host->check_options); 00509 fprintf(fp,"\tcurrent_attempt=%d\n",temp_host->current_attempt); 00510 fprintf(fp,"\tmax_attempts=%d\n",temp_host->max_attempts); 00511 fprintf(fp,"\tstate_type=%d\n",temp_host->state_type); 00512 fprintf(fp,"\tlast_state_change=%lu\n",temp_host->last_state_change); 00513 fprintf(fp,"\tlast_hard_state_change=%lu\n",temp_host->last_hard_state_change); 00514 fprintf(fp,"\tlast_time_up=%lu\n",temp_host->last_time_up); 00515 fprintf(fp,"\tlast_time_down=%lu\n",temp_host->last_time_down); 00516 fprintf(fp,"\tlast_time_unreachable=%lu\n",temp_host->last_time_unreachable); 00517 fprintf(fp,"\tlast_notification=%lu\n",temp_host->last_host_notification); 00518 fprintf(fp,"\tnext_notification=%lu\n",temp_host->next_host_notification); 00519 fprintf(fp,"\tno_more_notifications=%d\n",temp_host->no_more_notifications); 00520 fprintf(fp,"\tcurrent_notification_number=%d\n",temp_host->current_notification_number); 00521 #ifdef USE_ST_BASED_ESCAL_RANGES 00522 fprintf(fp,"\tcurrent_down_notification_number=%d\n",temp_host->current_down_notification_number); 00523 fprintf(fp,"\tcurrent_unreachable_notification_number=%d\n",temp_host->current_unreachable_notification_number); 00524 #endif 00525 fprintf(fp,"\tcurrent_notification_id=%lu\n",temp_host->current_notification_id); 00526 fprintf(fp,"\tnotifications_enabled=%d\n",temp_host->notifications_enabled); 00527 fprintf(fp,"\tproblem_has_been_acknowledged=%d\n",temp_host->problem_has_been_acknowledged); 00528 fprintf(fp,"\tacknowledgement_type=%d\n",temp_host->acknowledgement_type); 00529 fprintf(fp,"\tactive_checks_enabled=%d\n",temp_host->checks_enabled); 00530 fprintf(fp,"\tpassive_checks_enabled=%d\n",temp_host->accept_passive_host_checks); 00531 fprintf(fp,"\tevent_handler_enabled=%d\n",temp_host->event_handler_enabled); 00532 fprintf(fp,"\tflap_detection_enabled=%d\n",temp_host->flap_detection_enabled); 00533 fprintf(fp,"\tfailure_prediction_enabled=%d\n",temp_host->failure_prediction_enabled); 00534 fprintf(fp,"\tprocess_performance_data=%d\n",temp_host->process_performance_data); 00535 fprintf(fp,"\tobsess_over_host=%d\n",temp_host->obsess_over_host); 00536 fprintf(fp,"\tlast_update=%lu\n",current_time); 00537 fprintf(fp,"\tis_flapping=%d\n",temp_host->is_flapping); 00538 fprintf(fp,"\tpercent_state_change=%.2f\n",temp_host->percent_state_change); 00539 fprintf(fp,"\tscheduled_downtime_depth=%d\n",temp_host->scheduled_downtime_depth); 00540 /* 00541 fprintf(fp,"\tstate_history="); 00542 for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++) 00543 fprintf(fp,"%s%d",(x>0)?",":"",temp_host->state_history[(x+temp_host->state_history_index)%MAX_STATE_HISTORY_ENTRIES]); 00544 fprintf(fp,"\n"); 00545 */ 00546 /* custom variables */ 00547 for(temp_customvariablesmember=temp_host->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 00548 if(temp_customvariablesmember->variable_name) 00549 fprintf(fp,"\t_%s=%d;%s\n",temp_customvariablesmember->variable_name,temp_customvariablesmember->has_been_modified,(temp_customvariablesmember->variable_value==NULL)?"":temp_customvariablesmember->variable_value); 00550 } 00551 fprintf(fp,"\t}\n\n"); 00552 } 00553 00554 /* save service status data */ 00555 for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){ 00556 00557 fprintf(fp,"servicestatus {\n"); 00558 fprintf(fp,"\thost_name=%s\n",temp_service->host_name); 00559 00560 fprintf(fp,"\tservice_description=%s\n",temp_service->description); 00561 fprintf(fp,"\tmodified_attributes=%lu\n",temp_service->modified_attributes); 00562 fprintf(fp,"\tcheck_command=%s\n",(temp_service->service_check_command==NULL)?"":temp_service->service_check_command); 00563 fprintf(fp,"\tcheck_period=%s\n",(temp_service->check_period==NULL)?"":temp_service->check_period); 00564 fprintf(fp,"\tnotification_period=%s\n",(temp_service->notification_period==NULL)?"":temp_service->notification_period); 00565 fprintf(fp,"\tcheck_interval=%f\n",temp_service->check_interval); 00566 fprintf(fp,"\tretry_interval=%f\n",temp_service->retry_interval); 00567 fprintf(fp,"\tevent_handler=%s\n",(temp_service->event_handler==NULL)?"":temp_service->event_handler); 00568 00569 fprintf(fp,"\thas_been_checked=%d\n",temp_service->has_been_checked); 00570 fprintf(fp,"\tshould_be_scheduled=%d\n",temp_service->should_be_scheduled); 00571 fprintf(fp,"\tcheck_execution_time=%.3f\n",temp_service->execution_time); 00572 fprintf(fp,"\tcheck_latency=%.3f\n",temp_service->latency); 00573 fprintf(fp,"\tcheck_type=%d\n",temp_service->check_type); 00574 fprintf(fp,"\tcurrent_state=%d\n",temp_service->current_state); 00575 fprintf(fp,"\tlast_hard_state=%d\n",temp_service->last_hard_state); 00576 fprintf(fp,"\tlast_event_id=%lu\n",temp_service->last_event_id); 00577 fprintf(fp,"\tcurrent_event_id=%lu\n",temp_service->current_event_id); 00578 fprintf(fp,"\tcurrent_problem_id=%lu\n",temp_service->current_problem_id); 00579 fprintf(fp,"\tlast_problem_id=%lu\n",temp_service->last_problem_id); 00580 fprintf(fp,"\tcurrent_attempt=%d\n",temp_service->current_attempt); 00581 fprintf(fp,"\tmax_attempts=%d\n",temp_service->max_attempts); 00582 fprintf(fp,"\tstate_type=%d\n",temp_service->state_type); 00583 fprintf(fp,"\tlast_state_change=%lu\n",temp_service->last_state_change); 00584 fprintf(fp,"\tlast_hard_state_change=%lu\n",temp_service->last_hard_state_change); 00585 fprintf(fp,"\tlast_time_ok=%lu\n",temp_service->last_time_ok); 00586 fprintf(fp,"\tlast_time_warning=%lu\n",temp_service->last_time_warning); 00587 fprintf(fp,"\tlast_time_unknown=%lu\n",temp_service->last_time_unknown); 00588 fprintf(fp,"\tlast_time_critical=%lu\n",temp_service->last_time_critical); 00589 fprintf(fp,"\tplugin_output=%s\n",(temp_service->plugin_output==NULL)?"":temp_service->plugin_output); 00590 fprintf(fp,"\tlong_plugin_output=%s\n",(temp_service->long_plugin_output==NULL)?"":temp_service->long_plugin_output); 00591 fprintf(fp,"\tperformance_data=%s\n",(temp_service->perf_data==NULL)?"":temp_service->perf_data); 00592 fprintf(fp,"\tlast_check=%lu\n",temp_service->last_check); 00593 fprintf(fp,"\tnext_check=%lu\n",temp_service->next_check); 00594 fprintf(fp,"\tcheck_options=%d\n",temp_service->check_options); 00595 fprintf(fp,"\tcurrent_notification_number=%d\n",temp_service->current_notification_number); 00596 #ifdef USE_ST_BASED_ESCAL_RANGES 00597 fprintf(fp,"\tcurrent_warning_notification_number=%d\n",temp_service->current_warning_notification_number); 00598 fprintf(fp,"\tcurrent_critical_notification_number=%d\n",temp_service->current_critical_notification_number); 00599 fprintf(fp,"\tcurrent_unknown_notification_number=%d\n",temp_service->current_unknown_notification_number); 00600 #endif 00601 fprintf(fp,"\tcurrent_notification_id=%lu\n",temp_service->current_notification_id); 00602 fprintf(fp,"\tlast_notification=%lu\n",temp_service->last_notification); 00603 fprintf(fp,"\tnext_notification=%lu\n",temp_service->next_notification); 00604 fprintf(fp,"\tno_more_notifications=%d\n",temp_service->no_more_notifications); 00605 fprintf(fp,"\tnotifications_enabled=%d\n",temp_service->notifications_enabled); 00606 fprintf(fp,"\tactive_checks_enabled=%d\n",temp_service->checks_enabled); 00607 fprintf(fp,"\tpassive_checks_enabled=%d\n",temp_service->accept_passive_service_checks); 00608 fprintf(fp,"\tevent_handler_enabled=%d\n",temp_service->event_handler_enabled); 00609 fprintf(fp,"\tproblem_has_been_acknowledged=%d\n",temp_service->problem_has_been_acknowledged); 00610 fprintf(fp,"\tacknowledgement_type=%d\n",temp_service->acknowledgement_type); 00611 fprintf(fp,"\tflap_detection_enabled=%d\n",temp_service->flap_detection_enabled); 00612 fprintf(fp,"\tfailure_prediction_enabled=%d\n",temp_service->failure_prediction_enabled); 00613 fprintf(fp,"\tprocess_performance_data=%d\n",temp_service->process_performance_data); 00614 fprintf(fp,"\tobsess_over_service=%d\n",temp_service->obsess_over_service); 00615 fprintf(fp,"\tlast_update=%lu\n",current_time); 00616 fprintf(fp,"\tis_flapping=%d\n",temp_service->is_flapping); 00617 fprintf(fp,"\tpercent_state_change=%.2f\n",temp_service->percent_state_change); 00618 fprintf(fp,"\tscheduled_downtime_depth=%d\n",temp_service->scheduled_downtime_depth); 00619 /* 00620 fprintf(fp,"\tstate_history="); 00621 for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++) 00622 fprintf(fp,"%s%d",(x>0)?",":"",temp_service->state_history[(x+temp_service->state_history_index)%MAX_STATE_HISTORY_ENTRIES]); 00623 fprintf(fp,"\n"); 00624 */ 00625 /* custom variables */ 00626 for(temp_customvariablesmember=temp_service->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 00627 if(temp_customvariablesmember->variable_name) 00628 fprintf(fp,"\t_%s=%d;%s\n",temp_customvariablesmember->variable_name,temp_customvariablesmember->has_been_modified,(temp_customvariablesmember->variable_value==NULL)?"":temp_customvariablesmember->variable_value); 00629 } 00630 fprintf(fp,"\t}\n\n"); 00631 } 00632 00633 /* save contact status data */ 00634 for(temp_contact=contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){ 00635 00636 fprintf(fp,"contactstatus {\n"); 00637 fprintf(fp,"\tcontact_name=%s\n",temp_contact->name); 00638 00639 fprintf(fp,"\tmodified_attributes=%lu\n",temp_contact->modified_attributes); 00640 fprintf(fp,"\tmodified_host_attributes=%lu\n",temp_contact->modified_host_attributes); 00641 fprintf(fp,"\tmodified_service_attributes=%lu\n",temp_contact->modified_service_attributes); 00642 fprintf(fp,"\thost_notification_period=%s\n",(temp_contact->host_notification_period==NULL)?"":temp_contact->host_notification_period); 00643 fprintf(fp,"\tservice_notification_period=%s\n",(temp_contact->service_notification_period==NULL)?"":temp_contact->service_notification_period); 00644 00645 fprintf(fp,"\tlast_host_notification=%lu\n",temp_contact->last_host_notification); 00646 fprintf(fp,"\tlast_service_notification=%lu\n",temp_contact->last_service_notification); 00647 fprintf(fp,"\thost_notifications_enabled=%d\n",temp_contact->host_notifications_enabled); 00648 fprintf(fp,"\tservice_notifications_enabled=%d\n",temp_contact->service_notifications_enabled); 00649 /* custom variables */ 00650 for(temp_customvariablesmember=temp_contact->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 00651 if(temp_customvariablesmember->variable_name) 00652 fprintf(fp,"\t_%s=%d;%s\n",temp_customvariablesmember->variable_name,temp_customvariablesmember->has_been_modified,(temp_customvariablesmember->variable_value==NULL)?"":temp_customvariablesmember->variable_value); 00653 } 00654 fprintf(fp,"\t}\n\n"); 00655 } 00656 00657 /* save all comments */ 00658 for(temp_comment=comment_list;temp_comment!=NULL;temp_comment=temp_comment->next){ 00659 00660 if(temp_comment->comment_type==HOST_COMMENT) 00661 fprintf(fp,"hostcomment {\n"); 00662 else 00663 fprintf(fp,"servicecomment {\n"); 00664 fprintf(fp,"\thost_name=%s\n",temp_comment->host_name); 00665 if(temp_comment->comment_type==SERVICE_COMMENT) 00666 fprintf(fp,"\tservice_description=%s\n",temp_comment->service_description); 00667 fprintf(fp,"\tentry_type=%d\n",temp_comment->entry_type); 00668 fprintf(fp,"\tcomment_id=%lu\n",temp_comment->comment_id); 00669 fprintf(fp,"\tsource=%d\n",temp_comment->source); 00670 fprintf(fp,"\tpersistent=%d\n",temp_comment->persistent); 00671 fprintf(fp,"\tentry_time=%lu\n",temp_comment->entry_time); 00672 fprintf(fp,"\texpires=%d\n",temp_comment->expires); 00673 fprintf(fp,"\texpire_time=%lu\n",temp_comment->expire_time); 00674 fprintf(fp,"\tauthor=%s\n",temp_comment->author); 00675 fprintf(fp,"\tcomment_data=%s\n",temp_comment->comment_data); 00676 fprintf(fp,"\t}\n\n"); 00677 } 00678 00679 /* save all downtime */ 00680 for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){ 00681 00682 if(temp_downtime->type==HOST_DOWNTIME) 00683 fprintf(fp,"hostdowntime {\n"); 00684 else 00685 fprintf(fp,"servicedowntime {\n"); 00686 fprintf(fp,"\thost_name=%s\n",temp_downtime->host_name); 00687 if(temp_downtime->type==SERVICE_DOWNTIME) 00688 fprintf(fp,"\tservice_description=%s\n",temp_downtime->service_description); 00689 fprintf(fp,"\tdowntime_id=%lu\n",temp_downtime->downtime_id); 00690 fprintf(fp,"\tentry_time=%lu\n",temp_downtime->entry_time); 00691 fprintf(fp,"\tstart_time=%lu\n",temp_downtime->start_time); 00692 fprintf(fp,"\tend_time=%lu\n",temp_downtime->end_time); 00693 fprintf(fp,"\ttriggered_by=%lu\n",temp_downtime->triggered_by); 00694 fprintf(fp,"\tfixed=%d\n",temp_downtime->fixed); 00695 fprintf(fp,"\tduration=%lu\n",temp_downtime->duration); 00696 fprintf(fp,"\tis_in_effect=%d\n",temp_downtime->is_in_effect); 00697 fprintf(fp,"\tauthor=%s\n",temp_downtime->author); 00698 fprintf(fp,"\tcomment=%s\n",temp_downtime->comment); 00699 fprintf(fp,"\t}\n\n"); 00700 } 00701 00702 00703 /* reset file permissions */ 00704 fchmod(fd,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); 00705 00706 /* flush the file to disk */ 00707 fflush(fp); 00708 00709 /* close the temp file */ 00710 result=fclose(fp); 00711 00712 /* fsync the file so that it is completely written out before moving it */ 00713 fsync(fd); 00714 00715 /* save/close was successful */ 00716 if(result==0){ 00717 00718 result=OK; 00719 00720 /* move the temp file to the status log (overwrite the old status log) */ 00721 if(my_rename(temp_file,xsddefault_status_log)){ 00722 unlink(temp_file); 00723 logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Unable to update status data file '%s': %s",xsddefault_status_log,strerror(errno)); 00724 result=ERROR; 00725 } 00726 } 00727 00728 /* a problem occurred saving the file */ 00729 else{ 00730 00731 result=ERROR; 00732 00733 /* remove temp file and log an error */ 00734 unlink(temp_file); 00735 logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Unable to save status file: %s",strerror(errno)); 00736 } 00737 00738 /* free memory */ 00739 my_free(temp_file); 00740 00741 return result; 00742 } 00743 00744 #endif 00745 00746 00747 00748 #ifdef NSCGI 00749 00750 /******************************************************************/ 00751 /****************** DEFAULT DATA INPUT FUNCTIONS ******************/ 00752 /******************************************************************/ 00753 00754 /* read all program, host, and service status information */ 00755 int xsddefault_read_status_data(char *config_file,int options){ 00756 #ifdef NO_MMAP 00757 char input[MAX_PLUGIN_OUTPUT_LENGTH]=""; 00758 FILE *fp=NULL; 00759 #else 00760 char *input=NULL; 00761 mmapfile *thefile=NULL; 00762 #endif 00763 int data_type=XSDDEFAULT_NO_DATA; 00764 hoststatus *temp_hoststatus=NULL; 00765 servicestatus *temp_servicestatus=NULL; 00766 char *var=NULL; 00767 char *val=NULL; 00768 char *ptr=NULL; 00769 int result=0; 00770 /* comment and downtime vars */ 00771 unsigned long comment_id=0; 00772 int persistent=FALSE; 00773 int expires=FALSE; 00774 time_t expire_time=0L; 00775 int entry_type=USER_COMMENT; 00776 int source=COMMENTSOURCE_INTERNAL; 00777 time_t entry_time=0L; 00778 char *host_name=NULL; 00779 char *service_description=NULL; 00780 char *author=NULL; 00781 char *comment_data=NULL; 00782 unsigned long downtime_id=0; 00783 time_t start_time=0L; 00784 time_t end_time=0L; 00785 int fixed=FALSE; 00786 unsigned long triggered_by=0; 00787 unsigned long duration=0L; 00788 int x=0; 00789 int is_in_effect=FALSE; 00790 00791 00792 /* initialize some vars */ 00793 for(x=0;x<MAX_CHECK_STATS_TYPES;x++){ 00794 program_stats[x][0]=0; 00795 program_stats[x][1]=0; 00796 program_stats[x][2]=0; 00797 } 00798 00799 /* grab configuration data */ 00800 result=xsddefault_grab_config_info(config_file); 00801 if(result==ERROR) 00802 return ERROR; 00803 00804 /* open the status file for reading */ 00805 #ifdef NO_MMAP 00806 if((fp=fopen(xsddefault_status_log,"r"))==NULL) 00807 return ERROR; 00808 #else 00809 if((thefile=mmap_fopen(xsddefault_status_log))==NULL) 00810 return ERROR; 00811 #endif 00812 00813 /* Big speedup when reading status.dat in bulk */ 00814 defer_downtime_sorting=1; 00815 defer_comment_sorting=1; 00816 00817 /* read all lines in the status file */ 00818 while(1){ 00819 00820 #ifdef NO_MMAP 00821 strcpy(input,""); 00822 if(fgets(input,sizeof(input),fp)==NULL) 00823 break; 00824 #else 00825 /* free memory */ 00826 my_free(input); 00827 00828 /* read the next line */ 00829 if((input=mmap_fgets(thefile))==NULL) 00830 break; 00831 #endif 00832 00833 strip(input); 00834 00835 /* skip blank lines and comments */ 00836 if(input[0]=='#' || input[0]=='\x0') 00837 continue; 00838 00839 else if(!strcmp(input,"info {")) 00840 data_type=XSDDEFAULT_INFO_DATA; 00841 else if(!strcmp(input,"programstatus {")) 00842 data_type=XSDDEFAULT_PROGRAMSTATUS_DATA; 00843 else if(!strcmp(input,"hoststatus {")){ 00844 data_type=XSDDEFAULT_HOSTSTATUS_DATA; 00845 temp_hoststatus=(hoststatus *)malloc(sizeof(hoststatus)); 00846 if(temp_hoststatus){ 00847 temp_hoststatus->host_name=NULL; 00848 temp_hoststatus->plugin_output=NULL; 00849 temp_hoststatus->long_plugin_output=NULL; 00850 temp_hoststatus->perf_data=NULL; 00851 temp_hoststatus->check_options=0; 00852 } 00853 } 00854 else if(!strcmp(input,"servicestatus {")){ 00855 data_type=XSDDEFAULT_SERVICESTATUS_DATA; 00856 temp_servicestatus=(servicestatus *)malloc(sizeof(servicestatus)); 00857 if(temp_servicestatus){ 00858 temp_servicestatus->host_name=NULL; 00859 temp_servicestatus->description=NULL; 00860 temp_servicestatus->plugin_output=NULL; 00861 temp_servicestatus->long_plugin_output=NULL; 00862 temp_servicestatus->perf_data=NULL; 00863 temp_servicestatus->check_options=0; 00864 } 00865 } 00866 else if(!strcmp(input,"contactstatus {")){ 00867 data_type=XSDDEFAULT_CONTACTSTATUS_DATA; 00868 /* unimplemented */ 00869 } 00870 else if(!strcmp(input,"hostcomment {")) 00871 data_type=XSDDEFAULT_HOSTCOMMENT_DATA; 00872 else if(!strcmp(input,"servicecomment {")) 00873 data_type=XSDDEFAULT_SERVICECOMMENT_DATA; 00874 else if(!strcmp(input,"hostdowntime {")) 00875 data_type=XSDDEFAULT_HOSTDOWNTIME_DATA; 00876 else if(!strcmp(input,"servicedowntime {")) 00877 data_type=XSDDEFAULT_SERVICEDOWNTIME_DATA; 00878 00879 else if(!strcmp(input,"}")){ 00880 00881 switch(data_type){ 00882 00883 case XSDDEFAULT_INFO_DATA: 00884 break; 00885 00886 case XSDDEFAULT_PROGRAMSTATUS_DATA: 00887 break; 00888 00889 case XSDDEFAULT_HOSTSTATUS_DATA: 00890 add_host_status(temp_hoststatus); 00891 temp_hoststatus=NULL; 00892 break; 00893 00894 case XSDDEFAULT_SERVICESTATUS_DATA: 00895 add_service_status(temp_servicestatus); 00896 temp_servicestatus=NULL; 00897 break; 00898 00899 case XSDDEFAULT_CONTACTSTATUS_DATA: 00900 /* unimplemented */ 00901 break; 00902 00903 case XSDDEFAULT_HOSTCOMMENT_DATA: 00904 case XSDDEFAULT_SERVICECOMMENT_DATA: 00905 00906 /* add the comment */ 00907 add_comment((data_type==XSDDEFAULT_HOSTCOMMENT_DATA)?HOST_COMMENT:SERVICE_COMMENT,entry_type,host_name,service_description,entry_time,author,comment_data,comment_id,persistent,expires,expire_time,source); 00908 00909 /* free temp memory */ 00910 my_free(host_name); 00911 my_free(service_description); 00912 my_free(author); 00913 my_free(comment_data); 00914 00915 /* reset defaults */ 00916 entry_type=USER_COMMENT; 00917 comment_id=0; 00918 source=COMMENTSOURCE_INTERNAL; 00919 persistent=FALSE; 00920 entry_time=0L; 00921 expires=FALSE; 00922 expire_time=0L; 00923 00924 break; 00925 00926 case XSDDEFAULT_HOSTDOWNTIME_DATA: 00927 case XSDDEFAULT_SERVICEDOWNTIME_DATA: 00928 00929 /* add the downtime */ 00930 if(data_type==XSDDEFAULT_HOSTDOWNTIME_DATA) 00931 add_host_downtime(host_name,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,downtime_id,is_in_effect); 00932 else 00933 add_service_downtime(host_name,service_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,downtime_id,is_in_effect); 00934 00935 /* free temp memory */ 00936 my_free(host_name); 00937 my_free(service_description); 00938 my_free(author); 00939 my_free(comment_data); 00940 00941 /* reset defaults */ 00942 downtime_id=0; 00943 entry_time=0L; 00944 start_time=0L; 00945 end_time=0L; 00946 fixed=FALSE; 00947 triggered_by=0; 00948 duration=0L; 00949 is_in_effect=FALSE; 00950 00951 break; 00952 00953 default: 00954 break; 00955 } 00956 00957 data_type=XSDDEFAULT_NO_DATA; 00958 } 00959 00960 else if(data_type!=XSDDEFAULT_NO_DATA){ 00961 00962 var=strtok(input,"="); 00963 val=strtok(NULL,"\n"); 00964 if(val==NULL) 00965 continue; 00966 00967 switch(data_type){ 00968 00969 case XSDDEFAULT_INFO_DATA: 00970 break; 00971 00972 case XSDDEFAULT_PROGRAMSTATUS_DATA: 00973 /* NOTE: some vars are not read, as they are not used by the CGIs (modified attributes, event handler commands, etc.) */ 00974 if(!strcmp(var,"icinga_pid")) 00975 nagios_pid=atoi(val); 00976 else if(!strcmp(var,"daemon_mode")) 00977 daemon_mode=(atoi(val)>0)?TRUE:FALSE; 00978 else if(!strcmp(var,"program_start")) 00979 program_start=strtoul(val,NULL,10); 00980 else if(!strcmp(var,"last_command_check")) 00981 last_command_check=strtoul(val,NULL,10); 00982 else if(!strcmp(var,"last_log_rotation")) 00983 last_log_rotation=strtoul(val,NULL,10); 00984 else if(!strcmp(var,"enable_notifications")) 00985 enable_notifications=(atoi(val)>0)?TRUE:FALSE; 00986 else if(!strcmp(var,"active_service_checks_enabled")) 00987 execute_service_checks=(atoi(val)>0)?TRUE:FALSE; 00988 else if(!strcmp(var,"passive_service_checks_enabled")) 00989 accept_passive_service_checks=(atoi(val)>0)?TRUE:FALSE; 00990 else if(!strcmp(var,"active_host_checks_enabled")) 00991 execute_host_checks=(atoi(val)>0)?TRUE:FALSE; 00992 else if(!strcmp(var,"passive_host_checks_enabled")) 00993 accept_passive_host_checks=(atoi(val)>0)?TRUE:FALSE; 00994 else if(!strcmp(var,"enable_event_handlers")) 00995 enable_event_handlers=(atoi(val)>0)?TRUE:FALSE; 00996 else if(!strcmp(var,"obsess_over_services")) 00997 obsess_over_services=(atoi(val)>0)?TRUE:FALSE; 00998 else if(!strcmp(var,"obsess_over_hosts")) 00999 obsess_over_hosts=(atoi(val)>0)?TRUE:FALSE; 01000 else if(!strcmp(var,"check_service_freshness")) 01001 check_service_freshness=(atoi(val)>0)?TRUE:FALSE; 01002 else if(!strcmp(var,"check_host_freshness")) 01003 check_host_freshness=(atoi(val)>0)?TRUE:FALSE; 01004 else if(!strcmp(var,"enable_flap_detection")) 01005 enable_flap_detection=(atoi(val)>0)?TRUE:FALSE; 01006 else if(!strcmp(var,"enable_failure_prediction")) 01007 enable_failure_prediction=(atoi(val)>0)?TRUE:FALSE; 01008 else if(!strcmp(var,"process_performance_data")) 01009 process_performance_data=(atoi(val)>0)?TRUE:FALSE; 01010 else if(!strcmp(var,"event_profiling_enabled")){ 01011 /* make sure gcc3 won't hit here */ 01012 #ifndef GCCTOOOLD 01013 event_profiling_enabled=atoi(val); 01014 #endif 01015 } 01016 01017 else if(strstr(var,"PROFILE_")){ 01018 /* make sure gcc3 won't hit here */ 01019 #ifndef GCCTOOOLD 01020 if(strstr(var,"COUNTER")) 01021 profile_object_update_count(var+strlen("PROFILE_COUNTER_"),strtod(val,NULL)); 01022 01023 if(strstr(var,"ELAPSED")) 01024 profile_object_update_elapsed(var+strlen("PROFILE_ELAPSED_"),atoi(val)); 01025 #endif 01026 } 01027 01028 else if (!strcmp(var,"total_external_command_buffer_slots")) 01029 buffer_stats[0][0]=atoi(val); 01030 else if (!strcmp(var,"used_external_command_buffer_slots")) 01031 buffer_stats[0][1]=atoi(val); 01032 else if (!strcmp(var,"high_external_command_buffer_slots")) 01033 buffer_stats[0][2]=atoi(val); 01034 01035 01036 else if (strstr(var,"_stats")){ 01037 01038 x=-1; 01039 if(!strcmp(var,"active_scheduled_host_check_stats")) 01040 x=ACTIVE_SCHEDULED_HOST_CHECK_STATS; 01041 if(!strcmp(var,"active_ondemand_host_check_stats")) 01042 x=ACTIVE_ONDEMAND_HOST_CHECK_STATS; 01043 if(!strcmp(var,"passive_host_check_stats")) 01044 x=PASSIVE_HOST_CHECK_STATS; 01045 if(!strcmp(var,"active_scheduled_service_check_stats")) 01046 x=ACTIVE_SCHEDULED_SERVICE_CHECK_STATS; 01047 if(!strcmp(var,"active_ondemand_service_check_stats")) 01048 x=ACTIVE_ONDEMAND_SERVICE_CHECK_STATS; 01049 if(!strcmp(var,"passive_service_check_stats")) 01050 x=PASSIVE_SERVICE_CHECK_STATS; 01051 if(!strcmp(var,"cached_host_check_stats")) 01052 x=ACTIVE_CACHED_HOST_CHECK_STATS; 01053 if(!strcmp(var,"cached_service_check_stats")) 01054 x=ACTIVE_CACHED_SERVICE_CHECK_STATS; 01055 if(!strcmp(var,"external_command_stats")) 01056 x=EXTERNAL_COMMAND_STATS; 01057 if(!strcmp(var,"parallel_host_check_stats")) 01058 x=PARALLEL_HOST_CHECK_STATS; 01059 if(!strcmp(var,"serial_host_check_stats")) 01060 x=SERIAL_HOST_CHECK_STATS; 01061 01062 if(x>=0){ 01063 if((ptr=strtok(val,","))){ 01064 program_stats[x][0]=atoi(ptr); 01065 if((ptr=strtok(NULL,","))){ 01066 program_stats[x][1]=atoi(ptr); 01067 if((ptr=strtok(NULL,"\n"))) 01068 program_stats[x][2]=atoi(ptr); 01069 } 01070 } 01071 } 01072 } 01073 break; 01074 01075 case XSDDEFAULT_HOSTSTATUS_DATA: 01076 /* NOTE: some vars are not read, as they are not used by the CGIs (modified attributes, event handler commands, etc.) */ 01077 if(temp_hoststatus!=NULL){ 01078 if(!strcmp(var,"host_name")) 01079 temp_hoststatus->host_name=(char *)strdup(val); 01080 else if(!strcmp(var,"has_been_checked")) 01081 temp_hoststatus->has_been_checked=(atoi(val)>0)?TRUE:FALSE; 01082 else if(!strcmp(var,"should_be_scheduled")) 01083 temp_hoststatus->should_be_scheduled=(atoi(val)>0)?TRUE:FALSE; 01084 else if(!strcmp(var,"check_execution_time")) 01085 temp_hoststatus->execution_time=strtod(val,NULL); 01086 else if(!strcmp(var,"check_latency")) 01087 temp_hoststatus->latency=strtod(val,NULL); 01088 else if(!strcmp(var,"check_type")) 01089 temp_hoststatus->check_type=atoi(val); 01090 else if(!strcmp(var,"current_state")) 01091 temp_hoststatus->status=atoi(val); 01092 else if(!strcmp(var,"last_hard_state")) 01093 temp_hoststatus->last_hard_state=atoi(val); 01094 else if(!strcmp(var,"plugin_output")){ 01095 temp_hoststatus->plugin_output=(char *)strdup(val); 01096 unescape_newlines(temp_hoststatus->plugin_output); 01097 } 01098 else if(!strcmp(var,"long_plugin_output")){ 01099 temp_hoststatus->long_plugin_output=(char *)strdup(val); 01100 unescape_newlines(temp_hoststatus->long_plugin_output); 01101 } 01102 else if(!strcmp(var,"performance_data")) 01103 temp_hoststatus->perf_data=(char *)strdup(val); 01104 else if(!strcmp(var,"current_attempt")) 01105 temp_hoststatus->current_attempt=atoi(val); 01106 else if(!strcmp(var,"max_attempts")) 01107 temp_hoststatus->max_attempts=atoi(val); 01108 else if(!strcmp(var,"last_check")) 01109 temp_hoststatus->last_check=strtoul(val,NULL,10); 01110 else if(!strcmp(var,"next_check")) 01111 temp_hoststatus->next_check=strtoul(val,NULL,10); 01112 else if(!strcmp(var,"check_options")) 01113 temp_hoststatus->check_options=atoi(val); 01114 else if(!strcmp(var,"current_attempt")) 01115 temp_hoststatus->current_attempt=(atoi(val)>0)?TRUE:FALSE; 01116 else if(!strcmp(var,"state_type")) 01117 temp_hoststatus->state_type=atoi(val); 01118 else if(!strcmp(var,"last_state_change")) 01119 temp_hoststatus->last_state_change=strtoul(val,NULL,10); 01120 else if(!strcmp(var,"last_hard_state_change")) 01121 temp_hoststatus->last_hard_state_change=strtoul(val,NULL,10); 01122 else if(!strcmp(var,"last_time_up")) 01123 temp_hoststatus->last_time_up=strtoul(val,NULL,10); 01124 else if(!strcmp(var,"last_time_down")) 01125 temp_hoststatus->last_time_down=strtoul(val,NULL,10); 01126 else if(!strcmp(var,"last_time_unreachable")) 01127 temp_hoststatus->last_time_unreachable=strtoul(val,NULL,10); 01128 else if(!strcmp(var,"last_notification")) 01129 temp_hoststatus->last_notification=strtoul(val,NULL,10); 01130 else if(!strcmp(var,"next_notification")) 01131 temp_hoststatus->next_notification=strtoul(val,NULL,10); 01132 else if(!strcmp(var,"no_more_notifications")) 01133 temp_hoststatus->no_more_notifications=(atoi(val)>0)?TRUE:FALSE; 01134 else if(!strcmp(var,"current_notification_number")) 01135 temp_hoststatus->current_notification_number=atoi(val); 01136 #ifdef USE_ST_BASED_ESCAL_RANGES 01137 else if(!strcmp(var,"current_down_notification_number")) 01138 temp_hoststatus->current_down_notification_number=atoi(val); 01139 else if(!strcmp(var,"current_unreachable_notification_number")) 01140 temp_hoststatus->current_unreachable_notification_number=atoi(val); 01141 #endif 01142 else if(!strcmp(var,"notifications_enabled")) 01143 temp_hoststatus->notifications_enabled=(atoi(val)>0)?TRUE:FALSE; 01144 else if(!strcmp(var,"problem_has_been_acknowledged")) 01145 temp_hoststatus->problem_has_been_acknowledged=(atoi(val)>0)?TRUE:FALSE; 01146 else if(!strcmp(var,"acknowledgement_type")) 01147 temp_hoststatus->acknowledgement_type=atoi(val); 01148 else if(!strcmp(var,"active_checks_enabled")) 01149 temp_hoststatus->checks_enabled=(atoi(val)>0)?TRUE:FALSE; 01150 else if(!strcmp(var,"passive_checks_enabled")) 01151 temp_hoststatus->accept_passive_host_checks=(atoi(val)>0)?TRUE:FALSE; 01152 else if(!strcmp(var,"event_handler_enabled")) 01153 temp_hoststatus->event_handler_enabled=(atoi(val)>0)?TRUE:FALSE; 01154 else if(!strcmp(var,"flap_detection_enabled")) 01155 temp_hoststatus->flap_detection_enabled=(atoi(val)>0)?TRUE:FALSE; 01156 else if(!strcmp(var,"failure_prediction_enabled")) 01157 temp_hoststatus->failure_prediction_enabled=(atoi(val)>0)?TRUE:FALSE; 01158 else if(!strcmp(var,"process_performance_data")) 01159 temp_hoststatus->process_performance_data=(atoi(val)>0)?TRUE:FALSE; 01160 else if(!strcmp(var,"obsess_over_host")) 01161 temp_hoststatus->obsess_over_host=(atoi(val)>0)?TRUE:FALSE; 01162 else if(!strcmp(var,"last_update")) 01163 temp_hoststatus->last_update=strtoul(val,NULL,10); 01164 else if(!strcmp(var,"is_flapping")) 01165 temp_hoststatus->is_flapping=(atoi(val)>0)?TRUE:FALSE; 01166 else if(!strcmp(var,"percent_state_change")) 01167 temp_hoststatus->percent_state_change=strtod(val,NULL); 01168 else if(!strcmp(var,"scheduled_downtime_depth")) 01169 temp_hoststatus->scheduled_downtime_depth=atoi(val); 01170 /* 01171 else if(!strcmp(var,"state_history")){ 01172 temp_ptr=val; 01173 for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++) 01174 temp_hoststatus->state_history[x]=atoi(my_strsep(&temp_ptr,",")); 01175 temp_hoststatus->state_history_index=0; 01176 } 01177 */ 01178 } 01179 break; 01180 01181 case XSDDEFAULT_SERVICESTATUS_DATA: 01182 /* NOTE: some vars are not read, as they are not used by the CGIs (modified attributes, event handler commands, etc.) */ 01183 if(temp_servicestatus!=NULL){ 01184 if(!strcmp(var,"host_name")) 01185 temp_servicestatus->host_name=(char *)strdup(val); 01186 else if(!strcmp(var,"service_description")) 01187 temp_servicestatus->description=(char *)strdup(val); 01188 else if(!strcmp(var,"has_been_checked")) 01189 temp_servicestatus->has_been_checked=(atoi(val)>0)?TRUE:FALSE; 01190 else if(!strcmp(var,"should_be_scheduled")) 01191 temp_servicestatus->should_be_scheduled=(atoi(val)>0)?TRUE:FALSE; 01192 else if(!strcmp(var,"check_execution_time")) 01193 temp_servicestatus->execution_time=strtod(val,NULL); 01194 else if(!strcmp(var,"check_latency")) 01195 temp_servicestatus->latency=strtod(val,NULL); 01196 else if(!strcmp(var,"check_type")) 01197 temp_servicestatus->check_type=atoi(val); 01198 else if(!strcmp(var,"current_state")) 01199 temp_servicestatus->status=atoi(val); 01200 else if(!strcmp(var,"last_hard_state")) 01201 temp_servicestatus->last_hard_state=atoi(val); 01202 else if(!strcmp(var,"current_attempt")) 01203 temp_servicestatus->current_attempt=atoi(val); 01204 else if(!strcmp(var,"max_attempts")) 01205 temp_servicestatus->max_attempts=atoi(val); 01206 else if(!strcmp(var,"state_type")) 01207 temp_servicestatus->state_type=atoi(val); 01208 else if(!strcmp(var,"last_state_change")) 01209 temp_servicestatus->last_state_change=strtoul(val,NULL,10); 01210 else if(!strcmp(var,"last_hard_state_change")) 01211 temp_servicestatus->last_hard_state_change=strtoul(val,NULL,10); 01212 else if(!strcmp(var,"last_time_ok")) 01213 temp_servicestatus->last_time_ok=strtoul(val,NULL,10); 01214 else if(!strcmp(var,"last_time_warning")) 01215 temp_servicestatus->last_time_warning=strtoul(val,NULL,10); 01216 else if(!strcmp(var,"last_time_unknown")) 01217 temp_servicestatus->last_time_unknown=strtoul(val,NULL,10); 01218 else if(!strcmp(var,"last_time_critical")) 01219 temp_servicestatus->last_time_critical=strtoul(val,NULL,10); 01220 else if(!strcmp(var,"plugin_output")){ 01221 temp_servicestatus->plugin_output=(char *)strdup(val); 01222 unescape_newlines(temp_servicestatus->plugin_output); 01223 } 01224 else if(!strcmp(var,"long_plugin_output")){ 01225 temp_servicestatus->long_plugin_output=(char *)strdup(val); 01226 unescape_newlines(temp_servicestatus->long_plugin_output); 01227 } 01228 else if(!strcmp(var,"performance_data")) 01229 temp_servicestatus->perf_data=(char *)strdup(val); 01230 else if(!strcmp(var,"last_check")) 01231 temp_servicestatus->last_check=strtoul(val,NULL,10); 01232 else if(!strcmp(var,"next_check")) 01233 temp_servicestatus->next_check=strtoul(val,NULL,10); 01234 else if(!strcmp(var,"check_options")) 01235 temp_servicestatus->check_options=atoi(val); 01236 else if(!strcmp(var,"current_notification_number")) 01237 temp_servicestatus->current_notification_number=atoi(val); 01238 #ifdef USE_ST_BASED_ESCAL_RANGES 01239 else if(!strcmp(var,"current_warning_notification_number")) 01240 temp_servicestatus->current_warning_notification_number=atoi(val); 01241 else if(!strcmp(var,"current_critical_notification_number")) 01242 temp_servicestatus->current_critical_notification_number=atoi(val); 01243 else if(!strcmp(var,"current_unknown_notification_number")) 01244 temp_servicestatus->current_unknown_notification_number=atoi(val); 01245 #endif 01246 else if(!strcmp(var,"last_notification")) 01247 temp_servicestatus->last_notification=strtoul(val,NULL,10); 01248 else if(!strcmp(var,"next_notification")) 01249 temp_servicestatus->next_notification=strtoul(val,NULL,10); 01250 else if(!strcmp(var,"no_more_notifications")) 01251 temp_servicestatus->no_more_notifications=(atoi(val)>0)?TRUE:FALSE; 01252 else if(!strcmp(var,"notifications_enabled")) 01253 temp_servicestatus->notifications_enabled=(atoi(val)>0)?TRUE:FALSE; 01254 else if(!strcmp(var,"active_checks_enabled")) 01255 temp_servicestatus->checks_enabled=(atoi(val)>0)?TRUE:FALSE; 01256 else if(!strcmp(var,"passive_checks_enabled")) 01257 temp_servicestatus->accept_passive_service_checks=(atoi(val)>0)?TRUE:FALSE; 01258 else if(!strcmp(var,"event_handler_enabled")) 01259 temp_servicestatus->event_handler_enabled=(atoi(val)>0)?TRUE:FALSE; 01260 else if(!strcmp(var,"problem_has_been_acknowledged")) 01261 temp_servicestatus->problem_has_been_acknowledged=(atoi(val)>0)?TRUE:FALSE; 01262 else if(!strcmp(var,"acknowledgement_type")) 01263 temp_servicestatus->acknowledgement_type=atoi(val); 01264 else if(!strcmp(var,"flap_detection_enabled")) 01265 temp_servicestatus->flap_detection_enabled=(atoi(val)>0)?TRUE:FALSE; 01266 else if(!strcmp(var,"failure_prediction_enabled")) 01267 temp_servicestatus->failure_prediction_enabled=(atoi(val)>0)?TRUE:FALSE; 01268 else if(!strcmp(var,"process_performance_data")) 01269 temp_servicestatus->process_performance_data=(atoi(val)>0)?TRUE:FALSE; 01270 else if(!strcmp(var,"obsess_over_service")) 01271 temp_servicestatus->obsess_over_service=(atoi(val)>0)?TRUE:FALSE; 01272 else if(!strcmp(var,"last_update")) 01273 temp_servicestatus->last_update=strtoul(val,NULL,10); 01274 else if(!strcmp(var,"is_flapping")) 01275 temp_servicestatus->is_flapping=(atoi(val)>0)?TRUE:FALSE; 01276 else if(!strcmp(var,"percent_state_change")) 01277 temp_servicestatus->percent_state_change=strtod(val,NULL); 01278 else if(!strcmp(var,"scheduled_downtime_depth")) 01279 temp_servicestatus->scheduled_downtime_depth=atoi(val); 01280 /* 01281 else if(!strcmp(var,"state_history")){ 01282 temp_ptr=val; 01283 for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++) 01284 temp_servicestatus->state_history[x]=atoi(my_strsep(&temp_ptr,",")); 01285 temp_servicestatus->state_history_index=0; 01286 } 01287 */ 01288 } 01289 break; 01290 01291 case XSDDEFAULT_CONTACTSTATUS_DATA: 01292 /* unimplemented */ 01293 break; 01294 01295 case XSDDEFAULT_HOSTCOMMENT_DATA: 01296 case XSDDEFAULT_SERVICECOMMENT_DATA: 01297 if(!strcmp(var,"host_name")) 01298 host_name=(char *)strdup(val); 01299 else if(!strcmp(var,"service_description")) 01300 service_description=(char *)strdup(val); 01301 else if(!strcmp(var,"entry_type")) 01302 entry_type=atoi(val); 01303 else if(!strcmp(var,"comment_id")) 01304 comment_id=strtoul(val,NULL,10); 01305 else if(!strcmp(var,"source")) 01306 source=atoi(val); 01307 else if(!strcmp(var,"persistent")) 01308 persistent=(atoi(val)>0)?TRUE:FALSE; 01309 else if(!strcmp(var,"entry_time")) 01310 entry_time=strtoul(val,NULL,10); 01311 else if(!strcmp(var,"expires")) 01312 expires=(atoi(val)>0)?TRUE:FALSE; 01313 else if(!strcmp(var,"expire_time")) 01314 expire_time=strtoul(val,NULL,10); 01315 else if(!strcmp(var,"author")) 01316 author=(char *)strdup(val); 01317 else if(!strcmp(var,"comment_data")) 01318 comment_data=(char *)strdup(val); 01319 break; 01320 01321 case XSDDEFAULT_HOSTDOWNTIME_DATA: 01322 case XSDDEFAULT_SERVICEDOWNTIME_DATA: 01323 if(!strcmp(var,"host_name")) 01324 host_name=(char *)strdup(val); 01325 else if(!strcmp(var,"service_description")) 01326 service_description=(char *)strdup(val); 01327 else if(!strcmp(var,"downtime_id")) 01328 downtime_id=strtoul(val,NULL,10); 01329 else if(!strcmp(var,"entry_time")) 01330 entry_time=strtoul(val,NULL,10); 01331 else if(!strcmp(var,"start_time")) 01332 start_time=strtoul(val,NULL,10); 01333 else if(!strcmp(var,"end_time")) 01334 end_time=strtoul(val,NULL,10); 01335 else if(!strcmp(var,"fixed")) 01336 fixed=(atoi(val)>0)?TRUE:FALSE; 01337 else if(!strcmp(var,"triggered_by")) 01338 triggered_by=strtoul(val,NULL,10); 01339 else if(!strcmp(var,"duration")) 01340 duration=strtoul(val,NULL,10); 01341 else if(!strcmp(var,"is_in_effect")) 01342 is_in_effect=(atoi(val)>0)?TRUE:FALSE; 01343 else if(!strcmp(var,"author")) 01344 author=(char *)strdup(val); 01345 else if(!strcmp(var,"comment")) 01346 comment_data=(char *)strdup(val); 01347 break; 01348 01349 default: 01350 break; 01351 } 01352 01353 } 01354 } 01355 01356 /* free memory and close the file */ 01357 #ifdef NO_MMAP 01358 fclose(fp); 01359 #else 01360 my_free(input); 01361 mmap_fclose(thefile); 01362 #endif 01363 01364 /* free memory */ 01365 my_free(xsddefault_status_log); 01366 my_free(xsddefault_temp_file); 01367 01368 if(sort_downtime()!=OK) 01369 return ERROR; 01370 if(sort_comments()!=OK) 01371 return ERROR; 01372 01373 return OK; 01374 } 01375 01376 #endif 01377