![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /***************************************************************************** 00002 * 00003 * XRDDEFAULT.C - Default external state retention 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/objects.h" 00032 #include "../include/statusdata.h" 00033 #include "../include/macros.h" 00034 #include "../include/icinga.h" 00035 #include "../include/sretention.h" 00036 #include "../include/comments.h" 00037 #include "../include/downtime.h" 00038 00039 00040 /**** STATE INFORMATION SPECIFIC HEADER FILES ****/ 00041 00042 #include "xrddefault.h" 00043 00044 extern host *host_list; 00045 extern service *service_list; 00046 extern contact *contact_list; 00047 extern comment *comment_list; 00048 extern scheduled_downtime *scheduled_downtime_list; 00049 00050 extern char *global_host_event_handler; 00051 extern char *global_service_event_handler; 00052 00053 extern int enable_notifications; 00054 extern int execute_service_checks; 00055 extern int accept_passive_service_checks; 00056 extern int execute_host_checks; 00057 extern int accept_passive_host_checks; 00058 extern int enable_event_handlers; 00059 extern int obsess_over_services; 00060 extern int obsess_over_hosts; 00061 extern int enable_flap_detection; 00062 extern int enable_failure_prediction; 00063 extern int process_performance_data; 00064 extern int check_service_freshness; 00065 extern int check_host_freshness; 00066 00067 extern int test_scheduling; 00068 00069 extern int use_large_installation_tweaks; 00070 00071 extern int use_retained_program_state; 00072 extern int use_retained_scheduling_info; 00073 extern int retention_scheduling_horizon; 00074 00075 extern unsigned long next_comment_id; 00076 extern unsigned long next_downtime_id; 00077 extern unsigned long next_event_id; 00078 extern unsigned long next_problem_id; 00079 extern unsigned long next_notification_id; 00080 00081 extern unsigned long modified_host_process_attributes; 00082 extern unsigned long modified_service_process_attributes; 00083 00084 extern unsigned long retained_host_attribute_mask; 00085 extern unsigned long retained_service_attribute_mask; 00086 extern unsigned long retained_contact_host_attribute_mask; 00087 extern unsigned long retained_contact_service_attribute_mask; 00088 extern unsigned long retained_process_host_attribute_mask; 00089 extern unsigned long retained_process_service_attribute_mask; 00090 00091 00092 char *xrddefault_retention_file=NULL; 00093 char *xrddefault_sync_retention_file=NULL; 00094 char *xrddefault_temp_file=NULL; 00095 00096 00097 int xrddefault_read_retention_file_information(char*, int); 00098 00099 /******************************************************************/ 00100 /********************* CONFIG INITIALIZATION *********************/ 00101 /******************************************************************/ 00102 00103 int xrddefault_grab_config_info(char *main_config_file){ 00104 char *input=NULL; 00105 mmapfile *thefile=NULL; 00106 icinga_macros *mac; 00107 00108 mac = get_global_macros(); 00109 00110 /* open the main config file for reading */ 00111 if((thefile=mmap_fopen(main_config_file))==NULL){ 00112 00113 log_debug_info(DEBUGL_RETENTIONDATA,2,"Error: Cannot open main configuration file '%s' for reading!\n",main_config_file); 00114 00115 my_free(xrddefault_sync_retention_file); 00116 my_free(xrddefault_retention_file); 00117 my_free(xrddefault_temp_file); 00118 00119 return ERROR; 00120 } 00121 00122 /* read in all lines from the main config file */ 00123 while(1){ 00124 00125 /* free memory */ 00126 my_free(input); 00127 00128 /* read the next line */ 00129 if((input=mmap_fgets_multiline(thefile))==NULL) 00130 break; 00131 00132 strip(input); 00133 00134 /* skip blank lines and comments */ 00135 if(input[0]=='#' || input[0]=='\x0') 00136 continue; 00137 00138 xrddefault_grab_config_directives(input); 00139 } 00140 00141 /* free memory and close the file */ 00142 my_free(input); 00143 mmap_fclose(thefile); 00144 00145 /* initialize locations if necessary */ 00146 if(xrddefault_retention_file==NULL) 00147 xrddefault_retention_file=(char *)strdup(DEFAULT_RETENTION_FILE); 00148 if(xrddefault_temp_file==NULL) 00149 xrddefault_temp_file=(char *)strdup(DEFAULT_TEMP_FILE); 00150 00151 /* make sure we have everything */ 00152 if(xrddefault_retention_file==NULL) 00153 return ERROR; 00154 if(xrddefault_temp_file==NULL) 00155 return ERROR; 00156 00157 /* save the retention file macro */ 00158 my_free(mac->x[MACRO_RETENTIONDATAFILE]); 00159 if((mac->x[MACRO_RETENTIONDATAFILE]=(char *)strdup(xrddefault_retention_file))) 00160 strip(mac->x[MACRO_RETENTIONDATAFILE]); 00161 00162 return OK; 00163 } 00164 00165 00166 00167 /* process a single config directive */ 00168 int xrddefault_grab_config_directives(char *input){ 00169 char *temp_ptr=NULL; 00170 char *varname=NULL; 00171 char *varvalue=NULL; 00172 00173 /* get the variable name */ 00174 if((temp_ptr=my_strtok(input,"="))==NULL) 00175 return ERROR; 00176 if((varname=(char *)strdup(temp_ptr))==NULL) 00177 return ERROR; 00178 00179 /* get the variable value */ 00180 if((temp_ptr=my_strtok(NULL,"\n"))==NULL){ 00181 my_free(varname); 00182 return ERROR; 00183 } 00184 if((varvalue=(char *)strdup(temp_ptr))==NULL){ 00185 my_free(varname); 00186 return ERROR; 00187 } 00188 00189 /* retention file definition */ 00190 if(!strcmp(varname,"xrddefault_retention_file") || !strcmp(varname,"state_retention_file")) 00191 xrddefault_retention_file=(char *)strdup(varvalue); 00192 00193 else if(!strcmp(varname,"sync_retention_file")) 00194 xrddefault_sync_retention_file=(char *)strdup(varvalue); 00195 00196 /* temp file definition */ 00197 else if(!strcmp(varname,"temp_file")) 00198 xrddefault_temp_file=(char *)strdup(varvalue); 00199 00200 /* free memory */ 00201 my_free(varname); 00202 my_free(varvalue); 00203 00204 return OK; 00205 } 00206 00207 00208 00209 00210 /******************************************************************/ 00211 /********************* INIT/CLEANUP FUNCTIONS *********************/ 00212 /******************************************************************/ 00213 00214 00215 /* initialize retention data */ 00216 int xrddefault_initialize_retention_data(char *config_file){ 00217 int result; 00218 00219 /* grab configuration data */ 00220 result=xrddefault_grab_config_info(config_file); 00221 if(result==ERROR) 00222 return ERROR; 00223 00224 return OK; 00225 } 00226 00227 00228 /* cleanup retention data before terminating */ 00229 int xrddefault_cleanup_retention_data(char *config_file){ 00230 00231 /* free memory */ 00232 my_free(xrddefault_sync_retention_file); 00233 my_free(xrddefault_retention_file); 00234 my_free(xrddefault_temp_file); 00235 00236 return OK; 00237 } 00238 00239 00240 /******************************************************************/ 00241 /**************** DEFAULT STATE OUTPUT FUNCTION *******************/ 00242 /******************************************************************/ 00243 00244 int xrddefault_save_state_information(void){ 00245 char *temp_file=NULL; 00246 customvariablesmember *temp_customvariablesmember=NULL; 00247 time_t current_time=0L; 00248 int result=OK; 00249 FILE *fp=NULL; 00250 host *temp_host=NULL; 00251 service *temp_service=NULL; 00252 contact *temp_contact=NULL; 00253 comment *temp_comment=NULL; 00254 scheduled_downtime *temp_downtime=NULL; 00255 int x=0; 00256 int fd=0; 00257 int dummy; /* reduce compiler warnings */ 00258 unsigned long host_attribute_mask=0L; 00259 unsigned long service_attribute_mask=0L; 00260 unsigned long contact_attribute_mask=0L; 00261 unsigned long contact_host_attribute_mask=0L; 00262 unsigned long contact_service_attribute_mask=0L; 00263 unsigned long process_host_attribute_mask=0L; 00264 unsigned long process_service_attribute_mask=0L; 00265 00266 00267 log_debug_info(DEBUGL_FUNCTIONS,0,"xrddefault_save_state_information()\n"); 00268 00269 /* make sure we have everything */ 00270 if(xrddefault_retention_file==NULL || xrddefault_temp_file==NULL){ 00271 00272 logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: We don't have the required file names to store retention data!\n"); 00273 00274 return ERROR; 00275 } 00276 00277 /* open a safe temp file for output */ 00278 dummy=asprintf(&temp_file,"%sXXXXXX",xrddefault_temp_file); 00279 if(temp_file==NULL) 00280 return ERROR; 00281 if((fd=mkstemp(temp_file))==-1) 00282 return ERROR; 00283 00284 log_debug_info(DEBUGL_RETENTIONDATA,2,"Writing retention data to temp file '%s'\n",temp_file); 00285 00286 fp=(FILE *)fdopen(fd,"w"); 00287 if(fp==NULL){ 00288 00289 close(fd); 00290 unlink(temp_file); 00291 00292 logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Could not open temp state retention file '%s' for writing!\n",temp_file); 00293 00294 my_free(temp_file); 00295 00296 return ERROR; 00297 } 00298 00299 /* what attributes should be masked out? */ 00300 /* NOTE: host/service/contact-specific values may be added in the future, but for now we only have global masks */ 00301 process_host_attribute_mask=retained_process_host_attribute_mask; 00302 process_service_attribute_mask=retained_process_host_attribute_mask; 00303 host_attribute_mask=retained_host_attribute_mask; 00304 service_attribute_mask=retained_host_attribute_mask; 00305 contact_host_attribute_mask=retained_contact_host_attribute_mask; 00306 contact_service_attribute_mask=retained_contact_service_attribute_mask; 00307 00308 /* write version info to status file */ 00309 fprintf(fp,"########################################\n"); 00310 fprintf(fp,"# %s STATE RETENTION FILE\n", PROGRAM_NAME_UC); 00311 fprintf(fp,"#\n"); 00312 fprintf(fp,"# THIS FILE IS AUTOMATICALLY GENERATED\n"); 00313 fprintf(fp,"# BY %s. DO NOT MODIFY THIS FILE!\n", PROGRAM_NAME_UC); 00314 fprintf(fp,"########################################\n"); 00315 00316 time(¤t_time); 00317 00318 /* write file info */ 00319 fprintf(fp,"info {\n"); 00320 fprintf(fp,"created=%lu\n",current_time); 00321 fprintf(fp,"version=%s\n",PROGRAM_VERSION); 00322 fprintf(fp,"}\n"); 00323 00324 /* save program state information */ 00325 fprintf(fp,"program {\n"); 00326 fprintf(fp,"modified_host_attributes=%lu\n",(modified_host_process_attributes & ~process_host_attribute_mask)); 00327 fprintf(fp,"modified_service_attributes=%lu\n",(modified_service_process_attributes & ~process_service_attribute_mask)); 00328 fprintf(fp,"enable_notifications=%d\n",enable_notifications); 00329 fprintf(fp,"active_service_checks_enabled=%d\n",execute_service_checks); 00330 fprintf(fp,"passive_service_checks_enabled=%d\n",accept_passive_service_checks); 00331 fprintf(fp,"active_host_checks_enabled=%d\n",execute_host_checks); 00332 fprintf(fp,"passive_host_checks_enabled=%d\n",accept_passive_host_checks); 00333 fprintf(fp,"enable_event_handlers=%d\n",enable_event_handlers); 00334 fprintf(fp,"obsess_over_services=%d\n",obsess_over_services); 00335 fprintf(fp,"obsess_over_hosts=%d\n",obsess_over_hosts); 00336 fprintf(fp,"check_service_freshness=%d\n",check_service_freshness); 00337 fprintf(fp,"check_host_freshness=%d\n",check_host_freshness); 00338 fprintf(fp,"enable_flap_detection=%d\n",enable_flap_detection); 00339 fprintf(fp,"enable_failure_prediction=%d\n",enable_failure_prediction); 00340 fprintf(fp,"process_performance_data=%d\n",process_performance_data); 00341 fprintf(fp,"global_host_event_handler=%s\n",(global_host_event_handler==NULL)?"":global_host_event_handler); 00342 fprintf(fp,"global_service_event_handler=%s\n",(global_service_event_handler==NULL)?"":global_service_event_handler); 00343 fprintf(fp,"next_comment_id=%lu\n",next_comment_id); 00344 fprintf(fp,"next_downtime_id=%lu\n",next_downtime_id); 00345 fprintf(fp,"next_event_id=%lu\n",next_event_id); 00346 fprintf(fp,"next_problem_id=%lu\n",next_problem_id); 00347 fprintf(fp,"next_notification_id=%lu\n",next_notification_id); 00348 fprintf(fp,"}\n"); 00349 00350 /* save host state information */ 00351 for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ 00352 00353 fprintf(fp,"host {\n"); 00354 fprintf(fp,"host_name=%s\n",temp_host->name); 00355 fprintf(fp,"modified_attributes=%lu\n",(temp_host->modified_attributes & ~host_attribute_mask)); 00356 fprintf(fp,"check_command=%s\n",(temp_host->host_check_command==NULL)?"":temp_host->host_check_command); 00357 fprintf(fp,"check_period=%s\n",(temp_host->check_period==NULL)?"":temp_host->check_period); 00358 fprintf(fp,"notification_period=%s\n",(temp_host->notification_period==NULL)?"":temp_host->notification_period); 00359 fprintf(fp,"event_handler=%s\n",(temp_host->event_handler==NULL)?"":temp_host->event_handler); 00360 fprintf(fp,"has_been_checked=%d\n",temp_host->has_been_checked); 00361 fprintf(fp,"check_execution_time=%.3f\n",temp_host->execution_time); 00362 fprintf(fp,"check_latency=%.3f\n",temp_host->latency); 00363 fprintf(fp,"check_type=%d\n",temp_host->check_type); 00364 fprintf(fp,"current_state=%d\n",temp_host->current_state); 00365 fprintf(fp,"last_state=%d\n",temp_host->last_state); 00366 fprintf(fp,"last_hard_state=%d\n",temp_host->last_hard_state); 00367 fprintf(fp,"last_event_id=%lu\n",temp_host->last_event_id); 00368 fprintf(fp,"current_event_id=%lu\n",temp_host->current_event_id); 00369 fprintf(fp,"current_problem_id=%lu\n",temp_host->current_problem_id); 00370 fprintf(fp,"last_problem_id=%lu\n",temp_host->last_problem_id); 00371 fprintf(fp,"plugin_output=%s\n",(temp_host->plugin_output==NULL)?"":temp_host->plugin_output); 00372 fprintf(fp,"long_plugin_output=%s\n",(temp_host->long_plugin_output==NULL)?"":temp_host->long_plugin_output); 00373 fprintf(fp,"performance_data=%s\n",(temp_host->perf_data==NULL)?"":temp_host->perf_data); 00374 fprintf(fp,"last_check=%lu\n",temp_host->last_check); 00375 fprintf(fp,"next_check=%lu\n",temp_host->next_check); 00376 fprintf(fp,"check_options=%d\n",temp_host->check_options); 00377 fprintf(fp,"current_attempt=%d\n",temp_host->current_attempt); 00378 fprintf(fp,"max_attempts=%d\n",temp_host->max_attempts); 00379 fprintf(fp,"normal_check_interval=%f\n",temp_host->check_interval); 00380 fprintf(fp,"retry_check_interval=%f\n",temp_host->check_interval); 00381 fprintf(fp,"state_type=%d\n",temp_host->state_type); 00382 fprintf(fp,"last_state_change=%lu\n",temp_host->last_state_change); 00383 fprintf(fp,"last_hard_state_change=%lu\n",temp_host->last_hard_state_change); 00384 fprintf(fp,"last_time_up=%lu\n",temp_host->last_time_up); 00385 fprintf(fp,"last_time_down=%lu\n",temp_host->last_time_down); 00386 fprintf(fp,"last_time_unreachable=%lu\n",temp_host->last_time_unreachable); 00387 fprintf(fp,"notified_on_down=%d\n",temp_host->notified_on_down); 00388 fprintf(fp,"notified_on_unreachable=%d\n",temp_host->notified_on_unreachable); 00389 fprintf(fp,"last_notification=%lu\n",temp_host->last_host_notification); 00390 fprintf(fp,"current_notification_number=%d\n",temp_host->current_notification_number); 00391 #ifdef USE_ST_BASED_ESCAL_RANGES 00392 fprintf(fp,"current_down_notification_number=%d\n",temp_host->current_down_notification_number); 00393 fprintf(fp,"current_unreachable_notification_number=%d\n",temp_host->current_unreachable_notification_number); 00394 #endif 00395 fprintf(fp,"current_notification_id=%lu\n",temp_host->current_notification_id); 00396 fprintf(fp,"notifications_enabled=%d\n",temp_host->notifications_enabled); 00397 fprintf(fp,"problem_has_been_acknowledged=%d\n",temp_host->problem_has_been_acknowledged); 00398 fprintf(fp,"acknowledgement_type=%d\n",temp_host->acknowledgement_type); 00399 fprintf(fp,"active_checks_enabled=%d\n",temp_host->checks_enabled); 00400 fprintf(fp,"passive_checks_enabled=%d\n",temp_host->accept_passive_host_checks); 00401 fprintf(fp,"event_handler_enabled=%d\n",temp_host->event_handler_enabled); 00402 fprintf(fp,"flap_detection_enabled=%d\n",temp_host->flap_detection_enabled); 00403 fprintf(fp,"failure_prediction_enabled=%d\n",temp_host->failure_prediction_enabled); 00404 fprintf(fp,"process_performance_data=%d\n",temp_host->process_performance_data); 00405 fprintf(fp,"obsess_over_host=%d\n",temp_host->obsess_over_host); 00406 fprintf(fp,"is_flapping=%d\n",temp_host->is_flapping); 00407 fprintf(fp,"percent_state_change=%.2f\n",temp_host->percent_state_change); 00408 fprintf(fp,"check_flapping_recovery_notification=%d\n",temp_host->check_flapping_recovery_notification); 00409 00410 fprintf(fp,"state_history="); 00411 for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++) 00412 fprintf(fp,"%s%d",(x>0)?",":"",temp_host->state_history[(x+temp_host->state_history_index)%MAX_STATE_HISTORY_ENTRIES]); 00413 fprintf(fp,"\n"); 00414 00415 /* custom variables */ 00416 for(temp_customvariablesmember=temp_host->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 00417 if(temp_customvariablesmember->variable_name) 00418 fprintf(fp,"_%s=%d;%s\n",temp_customvariablesmember->variable_name,temp_customvariablesmember->has_been_modified,(temp_customvariablesmember->variable_value==NULL)?"":temp_customvariablesmember->variable_value); 00419 } 00420 00421 fprintf(fp,"}\n"); 00422 } 00423 00424 /* save service state information */ 00425 for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){ 00426 00427 fprintf(fp,"service {\n"); 00428 fprintf(fp,"host_name=%s\n",temp_service->host_name); 00429 fprintf(fp,"service_description=%s\n",temp_service->description); 00430 fprintf(fp,"modified_attributes=%lu\n",(temp_service->modified_attributes & ~service_attribute_mask)); 00431 fprintf(fp,"check_command=%s\n",(temp_service->service_check_command==NULL)?"":temp_service->service_check_command); 00432 fprintf(fp,"check_period=%s\n",(temp_service->check_period==NULL)?"":temp_service->check_period); 00433 fprintf(fp,"notification_period=%s\n",(temp_service->notification_period==NULL)?"":temp_service->notification_period); 00434 fprintf(fp,"event_handler=%s\n",(temp_service->event_handler==NULL)?"":temp_service->event_handler); 00435 fprintf(fp,"has_been_checked=%d\n",temp_service->has_been_checked); 00436 fprintf(fp,"check_execution_time=%.3f\n",temp_service->execution_time); 00437 fprintf(fp,"check_latency=%.3f\n",temp_service->latency); 00438 fprintf(fp,"check_type=%d\n",temp_service->check_type); 00439 fprintf(fp,"current_state=%d\n",temp_service->current_state); 00440 fprintf(fp,"last_state=%d\n",temp_service->last_state); 00441 fprintf(fp,"last_hard_state=%d\n",temp_service->last_hard_state); 00442 fprintf(fp,"last_event_id=%lu\n",temp_service->last_event_id); 00443 fprintf(fp,"current_event_id=%lu\n",temp_service->current_event_id); 00444 fprintf(fp,"current_problem_id=%lu\n",temp_service->current_problem_id); 00445 fprintf(fp,"last_problem_id=%lu\n",temp_service->last_problem_id); 00446 fprintf(fp,"current_attempt=%d\n",temp_service->current_attempt); 00447 fprintf(fp,"max_attempts=%d\n",temp_service->max_attempts); 00448 fprintf(fp,"normal_check_interval=%f\n",temp_service->check_interval); 00449 fprintf(fp,"retry_check_interval=%f\n",temp_service->retry_interval); 00450 fprintf(fp,"state_type=%d\n",temp_service->state_type); 00451 fprintf(fp,"last_state_change=%lu\n",temp_service->last_state_change); 00452 fprintf(fp,"last_hard_state_change=%lu\n",temp_service->last_hard_state_change); 00453 fprintf(fp,"last_time_ok=%lu\n",temp_service->last_time_ok); 00454 fprintf(fp,"last_time_warning=%lu\n",temp_service->last_time_warning); 00455 fprintf(fp,"last_time_unknown=%lu\n",temp_service->last_time_unknown); 00456 fprintf(fp,"last_time_critical=%lu\n",temp_service->last_time_critical); 00457 fprintf(fp,"plugin_output=%s\n",(temp_service->plugin_output==NULL)?"":temp_service->plugin_output); 00458 fprintf(fp,"long_plugin_output=%s\n",(temp_service->long_plugin_output==NULL)?"":temp_service->long_plugin_output); 00459 fprintf(fp,"performance_data=%s\n",(temp_service->perf_data==NULL)?"":temp_service->perf_data); 00460 fprintf(fp,"last_check=%lu\n",temp_service->last_check); 00461 fprintf(fp,"next_check=%lu\n",temp_service->next_check); 00462 fprintf(fp,"check_options=%d\n",temp_service->check_options); 00463 fprintf(fp,"notified_on_unknown=%d\n",temp_service->notified_on_unknown); 00464 fprintf(fp,"notified_on_warning=%d\n",temp_service->notified_on_warning); 00465 fprintf(fp,"notified_on_critical=%d\n",temp_service->notified_on_critical); 00466 fprintf(fp,"current_notification_number=%d\n",temp_service->current_notification_number); 00467 #ifdef USE_ST_BASED_ESCAL_RANGES 00468 fprintf(fp,"current_warning_notification_number=%d\n",temp_service->current_warning_notification_number); 00469 fprintf(fp,"current_critical_notification_number=%d\n",temp_service->current_critical_notification_number); 00470 fprintf(fp,"current_unknown_notification_number=%d\n",temp_service->current_unknown_notification_number); 00471 #endif 00472 fprintf(fp,"current_notification_id=%lu\n",temp_service->current_notification_id); 00473 fprintf(fp,"last_notification=%lu\n",temp_service->last_notification); 00474 fprintf(fp,"notifications_enabled=%d\n",temp_service->notifications_enabled); 00475 fprintf(fp,"active_checks_enabled=%d\n",temp_service->checks_enabled); 00476 fprintf(fp,"passive_checks_enabled=%d\n",temp_service->accept_passive_service_checks); 00477 fprintf(fp,"event_handler_enabled=%d\n",temp_service->event_handler_enabled); 00478 fprintf(fp,"problem_has_been_acknowledged=%d\n",temp_service->problem_has_been_acknowledged); 00479 fprintf(fp,"acknowledgement_type=%d\n",temp_service->acknowledgement_type); 00480 fprintf(fp,"flap_detection_enabled=%d\n",temp_service->flap_detection_enabled); 00481 fprintf(fp,"failure_prediction_enabled=%d\n",temp_service->failure_prediction_enabled); 00482 fprintf(fp,"process_performance_data=%d\n",temp_service->process_performance_data); 00483 fprintf(fp,"obsess_over_service=%d\n",temp_service->obsess_over_service); 00484 fprintf(fp,"is_flapping=%d\n",temp_service->is_flapping); 00485 fprintf(fp,"percent_state_change=%.2f\n",temp_service->percent_state_change); 00486 fprintf(fp,"check_flapping_recovery_notification=%d\n",temp_service->check_flapping_recovery_notification); 00487 00488 fprintf(fp,"state_history="); 00489 for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++) 00490 fprintf(fp,"%s%d",(x>0)?",":"",temp_service->state_history[(x+temp_service->state_history_index)%MAX_STATE_HISTORY_ENTRIES]); 00491 fprintf(fp,"\n"); 00492 00493 /* custom variables */ 00494 for(temp_customvariablesmember=temp_service->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 00495 if(temp_customvariablesmember->variable_name) 00496 fprintf(fp,"_%s=%d;%s\n",temp_customvariablesmember->variable_name,temp_customvariablesmember->has_been_modified,(temp_customvariablesmember->variable_value==NULL)?"":temp_customvariablesmember->variable_value); 00497 } 00498 00499 fprintf(fp,"}\n"); 00500 } 00501 00502 /* save contact state information */ 00503 for(temp_contact=contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){ 00504 00505 fprintf(fp,"contact {\n"); 00506 fprintf(fp,"contact_name=%s\n",temp_contact->name); 00507 fprintf(fp,"modified_attributes=%lu\n",(temp_contact->modified_attributes & ~contact_attribute_mask)); 00508 fprintf(fp,"modified_host_attributes=%lu\n",(temp_contact->modified_host_attributes & ~contact_host_attribute_mask)); 00509 fprintf(fp,"modified_service_attributes=%lu\n",(temp_contact->modified_service_attributes & ~contact_service_attribute_mask)); 00510 fprintf(fp,"host_notification_period=%s\n",(temp_contact->host_notification_period==NULL)?"":temp_contact->host_notification_period); 00511 fprintf(fp,"service_notification_period=%s\n",(temp_contact->service_notification_period==NULL)?"":temp_contact->service_notification_period); 00512 fprintf(fp,"last_host_notification=%lu\n",temp_contact->last_host_notification); 00513 fprintf(fp,"last_service_notification=%lu\n",temp_contact->last_service_notification); 00514 fprintf(fp,"host_notifications_enabled=%d\n",temp_contact->host_notifications_enabled); 00515 fprintf(fp,"service_notifications_enabled=%d\n",temp_contact->service_notifications_enabled); 00516 00517 /* custom variables */ 00518 for(temp_customvariablesmember=temp_contact->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 00519 if(temp_customvariablesmember->variable_name) 00520 fprintf(fp,"_%s=%d;%s\n",temp_customvariablesmember->variable_name,temp_customvariablesmember->has_been_modified,(temp_customvariablesmember->variable_value==NULL)?"":temp_customvariablesmember->variable_value); 00521 } 00522 00523 fprintf(fp,"}\n"); 00524 } 00525 00526 /* save all comments */ 00527 for(temp_comment=comment_list;temp_comment!=NULL;temp_comment=temp_comment->next){ 00528 00529 if(temp_comment->comment_type==HOST_COMMENT) 00530 fprintf(fp,"hostcomment {\n"); 00531 else 00532 fprintf(fp,"servicecomment {\n"); 00533 fprintf(fp,"host_name=%s\n",temp_comment->host_name); 00534 if(temp_comment->comment_type==SERVICE_COMMENT) 00535 fprintf(fp,"service_description=%s\n",temp_comment->service_description); 00536 fprintf(fp,"entry_type=%d\n",temp_comment->entry_type); 00537 fprintf(fp,"comment_id=%lu\n",temp_comment->comment_id); 00538 fprintf(fp,"source=%d\n",temp_comment->source); 00539 fprintf(fp,"persistent=%d\n",temp_comment->persistent); 00540 fprintf(fp,"entry_time=%lu\n",temp_comment->entry_time); 00541 fprintf(fp,"expires=%d\n",temp_comment->expires); 00542 fprintf(fp,"expire_time=%lu\n",temp_comment->expire_time); 00543 fprintf(fp,"author=%s\n",temp_comment->author); 00544 fprintf(fp,"comment_data=%s\n",temp_comment->comment_data); 00545 fprintf(fp,"}\n"); 00546 } 00547 00548 /* save all downtime */ 00549 for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){ 00550 00551 if(temp_downtime->type==HOST_DOWNTIME) 00552 fprintf(fp,"hostdowntime {\n"); 00553 else 00554 fprintf(fp,"servicedowntime {\n"); 00555 fprintf(fp,"host_name=%s\n",temp_downtime->host_name); 00556 if(temp_downtime->type==SERVICE_DOWNTIME) 00557 fprintf(fp,"service_description=%s\n",temp_downtime->service_description); 00558 fprintf(fp,"downtime_id=%lu\n",temp_downtime->downtime_id); 00559 fprintf(fp,"entry_time=%lu\n",temp_downtime->entry_time); 00560 fprintf(fp,"start_time=%lu\n",temp_downtime->start_time); 00561 fprintf(fp,"end_time=%lu\n",temp_downtime->end_time); 00562 fprintf(fp,"triggered_by=%lu\n",temp_downtime->triggered_by); 00563 fprintf(fp,"fixed=%d\n",temp_downtime->fixed); 00564 fprintf(fp,"duration=%lu\n",temp_downtime->duration); 00565 fprintf(fp,"is_in_effect=%d\n",temp_downtime->is_in_effect); 00566 fprintf(fp,"author=%s\n",temp_downtime->author); 00567 fprintf(fp,"comment=%s\n",temp_downtime->comment); 00568 fprintf(fp,"}\n"); 00569 } 00570 00571 fflush(fp); 00572 result=fclose(fp); 00573 fsync(fd); 00574 00575 /* save/close was successful */ 00576 if(result==0){ 00577 00578 result=OK; 00579 00580 /* move the temp file to the retention file (overwrite the old retention file) */ 00581 if(my_rename(temp_file,xrddefault_retention_file)){ 00582 unlink(temp_file); 00583 logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Unable to update retention file '%s': %s",xrddefault_retention_file,strerror(errno)); 00584 result=ERROR; 00585 } 00586 } 00587 00588 /* a problem occurred saving the file */ 00589 else{ 00590 00591 result=ERROR; 00592 00593 /* remove temp file and log an error */ 00594 unlink(temp_file); 00595 logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Unable to save retention file: %s",strerror(errno)); 00596 } 00597 00598 /* free memory */ 00599 my_free(temp_file); 00600 00601 return result; 00602 } 00603 00604 00605 00606 00607 /******************************************************************/ 00608 /***************** DEFAULT STATE INPUT FUNCTION *******************/ 00609 /******************************************************************/ 00610 00611 int xrddefault_read_state_information(void){ 00612 return xrddefault_read_retention_file_information(xrddefault_retention_file,TRUE); 00613 } 00614 00615 int xrddefault_sync_state_information(void){ 00616 int result=OK; 00617 if(xrddefault_sync_retention_file!=NULL) 00618 result=xrddefault_read_retention_file_information(xrddefault_sync_retention_file,FALSE); 00619 return result; 00620 } 00621 00622 int xrddefault_read_retention_file_information(char *retention_file, int overwrite_data){ 00623 char *input=NULL; 00624 char *inputbuf=NULL; 00625 char *temp_ptr=NULL; 00626 mmapfile *thefile; 00627 char *host_name=NULL; 00628 char *service_description=NULL; 00629 char *contact_name=NULL; 00630 char *author=NULL; 00631 char *comment_data=NULL; 00632 int data_type=XRDDEFAULT_NO_DATA; 00633 int x=0; 00634 host *temp_host=NULL; 00635 service *temp_service=NULL; 00636 contact *temp_contact=NULL; 00637 command *temp_command=NULL; 00638 timeperiod *temp_timeperiod=NULL; 00639 customvariablesmember *temp_customvariablesmember=NULL; 00640 char *customvarname=NULL; 00641 char *var=NULL; 00642 char *val=NULL; 00643 char *tempval=NULL; 00644 char *ch=NULL; 00645 unsigned long comment_id=0; 00646 int persistent=FALSE; 00647 int expires=FALSE; 00648 time_t expire_time=0L; 00649 int entry_type=USER_COMMENT; 00650 int source=COMMENTSOURCE_INTERNAL; 00651 time_t entry_time=0L; 00652 time_t creation_time; 00653 time_t current_time; 00654 int scheduling_info_is_ok=FALSE; 00655 unsigned long downtime_id=0; 00656 time_t start_time=0L; 00657 time_t end_time=0L; 00658 int fixed=FALSE; 00659 unsigned long triggered_by=0; 00660 unsigned long duration=0L; 00661 unsigned long host_attribute_mask=0L; 00662 unsigned long service_attribute_mask=0L; 00663 unsigned long contact_attribute_mask=0L; 00664 unsigned long contact_host_attribute_mask=0L; 00665 unsigned long contact_service_attribute_mask=0L; 00666 unsigned long process_host_attribute_mask=0L; 00667 unsigned long process_service_attribute_mask=0L; 00668 int remove_comment=FALSE; 00669 int ack=FALSE; 00670 int was_flapping=FALSE; 00671 int allow_flapstart_notification=TRUE; 00672 struct timeval tv[2]; 00673 double runtime[2]; 00674 int found_directive=FALSE; 00675 int retain_flag=TRUE; 00676 time_t last_check=0L; 00677 int add_object; 00678 int is_in_effect=FALSE; 00679 00680 log_debug_info(DEBUGL_FUNCTIONS,0,"xrddefault_read_state_information() start\n"); 00681 00682 /* make sure we have what we need */ 00683 if(retention_file==NULL){ 00684 00685 logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: We don't have a filename for retention data!\n"); 00686 00687 return ERROR; 00688 } 00689 00690 if(test_scheduling==TRUE) 00691 gettimeofday(&tv[0],NULL); 00692 00693 /* open the retention file for reading */ 00694 if((thefile=mmap_fopen(retention_file))==NULL) 00695 return ERROR; 00696 00697 /* what attributes should be masked out? */ 00698 /* NOTE: host/service/contact-specific values may be added in the future, but for now we only have global masks */ 00699 process_host_attribute_mask=retained_process_host_attribute_mask; 00700 process_service_attribute_mask=retained_process_host_attribute_mask; 00701 host_attribute_mask=retained_host_attribute_mask; 00702 service_attribute_mask=retained_host_attribute_mask; 00703 contact_host_attribute_mask=retained_contact_host_attribute_mask; 00704 contact_service_attribute_mask=retained_contact_service_attribute_mask; 00705 00706 /* big speedup when reading retention.dat in bulk, adapted from status.dat in xsddefault.c */ 00707 defer_downtime_sorting=1; 00708 defer_comment_sorting=1; 00709 00710 /* read all lines in the retention file */ 00711 while(1){ 00712 00713 /* free memory */ 00714 my_free(inputbuf); 00715 00716 /* read the next line */ 00717 if((inputbuf=mmap_fgets(thefile))==NULL) 00718 break; 00719 00720 input=inputbuf; 00721 00722 /* far better than strip()ing */ 00723 if(input[0]=='\t') 00724 input++; 00725 00726 strip(input); 00727 00728 if(!strcmp(input,"service {")) 00729 data_type=XRDDEFAULT_SERVICESTATUS_DATA; 00730 else if(!strcmp(input,"host {")) 00731 data_type=XRDDEFAULT_HOSTSTATUS_DATA; 00732 else if(!strcmp(input,"contact {")) 00733 data_type=XRDDEFAULT_CONTACTSTATUS_DATA; 00734 else if(!strcmp(input,"hostcomment {")) 00735 data_type=XRDDEFAULT_HOSTCOMMENT_DATA; 00736 else if(!strcmp(input,"servicecomment {")) 00737 data_type=XRDDEFAULT_SERVICECOMMENT_DATA; 00738 else if(!strcmp(input,"hostdowntime {")) 00739 data_type=XRDDEFAULT_HOSTDOWNTIME_DATA; 00740 else if(!strcmp(input,"servicedowntime {")) 00741 data_type=XRDDEFAULT_SERVICEDOWNTIME_DATA; 00742 else if(!strcmp(input,"info {")) 00743 data_type=XRDDEFAULT_INFO_DATA; 00744 else if(!strcmp(input,"program {")) 00745 data_type=XRDDEFAULT_PROGRAMSTATUS_DATA; 00746 00747 else if(!strcmp(input,"}")){ 00748 00749 switch(data_type){ 00750 00751 case XRDDEFAULT_INFO_DATA: 00752 break; 00753 00754 case XRDDEFAULT_PROGRAMSTATUS_DATA: 00755 00756 /* adjust modified attributes if necessary */ 00757 if(use_retained_program_state==FALSE){ 00758 modified_host_process_attributes=MODATTR_NONE; 00759 modified_service_process_attributes=MODATTR_NONE; 00760 } 00761 break; 00762 00763 case XRDDEFAULT_HOSTSTATUS_DATA: 00764 00765 if(temp_host!=NULL && retain_flag){ 00766 00767 /* adjust modified attributes if necessary */ 00768 if(temp_host->retain_nonstatus_information==FALSE) 00769 temp_host->modified_attributes=MODATTR_NONE; 00770 00771 /* adjust modified attributes if no custom variables have been changed */ 00772 if(temp_host->modified_attributes & MODATTR_CUSTOM_VARIABLE){ 00773 for(temp_customvariablesmember=temp_host->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 00774 if(temp_customvariablesmember->has_been_modified==TRUE) 00775 break; 00776 00777 } 00778 if(temp_customvariablesmember==NULL) 00779 temp_host->modified_attributes-=MODATTR_CUSTOM_VARIABLE; 00780 } 00781 00782 /* calculate next possible notification time */ 00783 if(temp_host->current_state!=HOST_UP && temp_host->last_host_notification!=(time_t)0) 00784 temp_host->next_host_notification=get_next_host_notification_time(temp_host,temp_host->last_host_notification); 00785 00786 /* ADDED 01/23/2009 adjust current check attempts if host in hard problem state (max attempts may have changed in config since restart) */ 00787 if(temp_host->current_state!=HOST_UP && temp_host->state_type==HARD_STATE) 00788 temp_host->current_attempt=temp_host->max_attempts; 00789 00790 00791 /* ADDED 02/20/08 assume same flapping state if large install tweaks enabled */ 00792 if(use_large_installation_tweaks==TRUE){ 00793 temp_host->is_flapping=was_flapping; 00794 } 00795 /* else use normal startup flap detection logic */ 00796 else{ 00797 /* host was flapping before program started */ 00798 /* 11/10/07 don't allow flapping notifications to go out */ 00799 if(was_flapping==TRUE) 00800 allow_flapstart_notification=FALSE; 00801 else 00802 /* flapstart notifications are okay */ 00803 allow_flapstart_notification=TRUE; 00804 00805 /* check for flapping */ 00806 check_for_host_flapping(temp_host,FALSE,FALSE,allow_flapstart_notification); 00807 00808 /* host was flapping before and isn't now, so clear recovery check variable if host isn't flapping now */ 00809 if(was_flapping==TRUE && temp_host->is_flapping==FALSE) 00810 temp_host->check_flapping_recovery_notification=FALSE; 00811 } 00812 00813 /* handle new vars added in 2.x */ 00814 if(temp_host->last_hard_state_change==(time_t)0) 00815 temp_host->last_hard_state_change=temp_host->last_state_change; 00816 00817 /* update host status */ 00818 update_host_status(temp_host,FALSE); 00819 } 00820 00821 /* reset vars */ 00822 was_flapping=FALSE; 00823 allow_flapstart_notification=TRUE; 00824 retain_flag=TRUE; 00825 00826 my_free(host_name); 00827 host_name=NULL; 00828 temp_host=NULL; 00829 break; 00830 00831 case XRDDEFAULT_SERVICESTATUS_DATA: 00832 00833 if(temp_service!=NULL && retain_flag){ 00834 00835 /* adjust modified attributes if necessary */ 00836 if(temp_service->retain_nonstatus_information==FALSE) 00837 temp_service->modified_attributes=MODATTR_NONE; 00838 00839 /* adjust modified attributes if no custom variables have been changed */ 00840 if(temp_service->modified_attributes & MODATTR_CUSTOM_VARIABLE){ 00841 for(temp_customvariablesmember=temp_service->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 00842 if(temp_customvariablesmember->has_been_modified==TRUE) 00843 break; 00844 00845 } 00846 if(temp_customvariablesmember==NULL) 00847 temp_service->modified_attributes-=MODATTR_CUSTOM_VARIABLE; 00848 } 00849 00850 /* calculate next possible notification time */ 00851 if(temp_service->current_state!=STATE_OK && temp_service->last_notification!=(time_t)0) 00852 temp_service->next_notification=get_next_service_notification_time(temp_service,temp_service->last_notification); 00853 00854 /* fix old vars */ 00855 if(temp_service->has_been_checked==FALSE && temp_service->state_type==SOFT_STATE) 00856 temp_service->state_type=HARD_STATE; 00857 00858 /* ADDED 01/23/2009 adjust current check attempt if service is in hard problem state (max attempts may have changed in config since restart) */ 00859 if(temp_service->current_state!=STATE_OK && temp_service->state_type==HARD_STATE) 00860 temp_service->current_attempt=temp_service->max_attempts; 00861 00862 00863 /* ADDED 02/20/08 assume same flapping state if large install tweaks enabled */ 00864 if(use_large_installation_tweaks==TRUE){ 00865 temp_service->is_flapping=was_flapping; 00866 } 00867 /* else use normal startup flap detection logic */ 00868 else{ 00869 /* service was flapping before program started */ 00870 /* 11/10/07 don't allow flapping notifications to go out */ 00871 if(was_flapping==TRUE) 00872 allow_flapstart_notification=FALSE; 00873 else 00874 /* flapstart notifications are okay */ 00875 allow_flapstart_notification=TRUE; 00876 00877 /* check for flapping */ 00878 check_for_service_flapping(temp_service,FALSE,allow_flapstart_notification); 00879 00880 /* service was flapping before and isn't now, so clear recovery check variable if service isn't flapping now */ 00881 if(was_flapping==TRUE && temp_service->is_flapping==FALSE) 00882 temp_service->check_flapping_recovery_notification=FALSE; 00883 } 00884 00885 /* handle new vars added in 2.x */ 00886 if(temp_service->last_hard_state_change==(time_t)0) 00887 temp_service->last_hard_state_change=temp_service->last_state_change; 00888 00889 /* update service status */ 00890 update_service_status(temp_service,FALSE); 00891 } 00892 00893 /* reset vars */ 00894 was_flapping=FALSE; 00895 allow_flapstart_notification=TRUE; 00896 retain_flag=TRUE; 00897 00898 my_free(host_name); 00899 my_free(service_description); 00900 temp_service=NULL; 00901 break; 00902 00903 case XRDDEFAULT_CONTACTSTATUS_DATA: 00904 00905 if(temp_contact!=NULL){ 00906 00907 /* adjust modified attributes if necessary */ 00908 if(temp_contact->retain_nonstatus_information==FALSE) 00909 temp_contact->modified_attributes=MODATTR_NONE; 00910 00911 /* adjust modified attributes if no custom variables have been changed */ 00912 if(temp_contact->modified_attributes & MODATTR_CUSTOM_VARIABLE){ 00913 for(temp_customvariablesmember=temp_contact->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 00914 if(temp_customvariablesmember->has_been_modified==TRUE) 00915 break; 00916 00917 } 00918 if(temp_customvariablesmember==NULL) 00919 temp_contact->modified_attributes-=MODATTR_CUSTOM_VARIABLE; 00920 } 00921 00922 /* update contact status */ 00923 update_contact_status(temp_contact,FALSE); 00924 } 00925 00926 my_free(contact_name); 00927 temp_contact=NULL; 00928 break; 00929 00930 case XRDDEFAULT_HOSTCOMMENT_DATA: 00931 case XRDDEFAULT_SERVICECOMMENT_DATA: 00932 00933 add_object=TRUE; 00934 00935 if(overwrite_data==FALSE) { 00936 00937 /* search for comment. If exists, then drop. If doesn't exist, then flow through but need to get a comment_id */ 00938 if(find_comment_by_similar_content((data_type==XRDDEFAULT_HOSTCOMMENT_DATA)?HOST_COMMENT:SERVICE_COMMENT,host_name,(data_type==XRDDEFAULT_HOSTCOMMENT_DATA?NULL:service_description),author,comment_data)!=NULL) { 00939 add_object=FALSE; 00940 } else { 00941 /* Get next available comment_id */ 00942 while(find_comment(next_comment_id,ANY_COMMENT)!=NULL) 00943 next_comment_id++; 00944 comment_id=next_comment_id; 00945 } 00946 } 00947 00948 if(add_object==TRUE) { 00949 /* add the comment */ 00950 add_comment((data_type==XRDDEFAULT_HOSTCOMMENT_DATA)?HOST_COMMENT:SERVICE_COMMENT,entry_type,host_name,service_description,entry_time,author,comment_data,comment_id,persistent,expires,expire_time,source); 00951 00952 /* delete the comment if necessary */ 00953 /* it seems a bit backwards to add and then immediately delete the comment, but its necessary to track comment deletions in the event broker */ 00954 remove_comment=FALSE; 00955 /* host no longer exists */ 00956 if((temp_host=find_host(host_name))==NULL) { 00957 remove_comment=TRUE; 00958 /* service no longer exists */ 00959 } else if(data_type==XRDDEFAULT_SERVICECOMMENT_DATA && (temp_service=find_service(host_name,service_description))==NULL) { 00960 remove_comment=TRUE; 00961 /* acknowledgement comments get deleted if they're not persistent and the original problem is no longer acknowledged */ 00962 } else if(entry_type==ACKNOWLEDGEMENT_COMMENT){ 00963 ack=FALSE; 00964 if(data_type==XRDDEFAULT_HOSTCOMMENT_DATA) { 00965 ack=temp_host->problem_has_been_acknowledged; 00966 } else { 00967 ack=temp_service->problem_has_been_acknowledged; 00968 } 00969 if(ack==FALSE && persistent==FALSE) 00970 remove_comment=TRUE; 00971 } 00972 00973 /* non-persistent comments don't last past restarts UNLESS they're acks (see above) */ 00974 else if(persistent==FALSE) { 00975 remove_comment=TRUE; 00976 } 00977 00978 if(remove_comment==TRUE) 00979 delete_comment((data_type==XRDDEFAULT_HOSTCOMMENT_DATA)?HOST_COMMENT:SERVICE_COMMENT,comment_id); 00980 00981 /* Reset any temporary pointers */ 00982 temp_host=NULL; 00983 temp_service=NULL; 00984 } 00985 00986 00987 /* free temp memory */ 00988 my_free(host_name); 00989 my_free(service_description); 00990 my_free(author); 00991 my_free(comment_data); 00992 00993 /* reset defaults */ 00994 entry_type=USER_COMMENT; 00995 comment_id=0; 00996 source=COMMENTSOURCE_INTERNAL; 00997 persistent=FALSE; 00998 entry_time=0L; 00999 expires=FALSE; 01000 expire_time=0L; 01001 01002 break; 01003 01004 case XRDDEFAULT_HOSTDOWNTIME_DATA: 01005 case XRDDEFAULT_SERVICEDOWNTIME_DATA: 01006 01007 add_object=TRUE; 01008 01009 if(overwrite_data==FALSE) { 01010 01011 /* search for downtime. If exists, then drop. If doesn't exist, then flow through but need to get a downtime id */ 01012 if(find_downtime_by_similar_content(ANY_DOWNTIME,host_name,(data_type==XRDDEFAULT_HOSTDOWNTIME_DATA?NULL:service_description),author,comment_data,start_time,end_time,fixed,duration)!=NULL) { 01013 add_object=FALSE; 01014 } else { 01015 /* Get next available downtime id */ 01016 while(find_downtime(ANY_DOWNTIME,next_downtime_id)!=NULL) 01017 next_downtime_id++; 01018 01019 downtime_id=next_downtime_id; 01020 } 01021 } 01022 01023 if (add_object==TRUE) { 01024 01025 /* add the downtime */ 01026 if(data_type==XRDDEFAULT_HOSTDOWNTIME_DATA) { 01027 add_host_downtime(host_name,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,downtime_id,is_in_effect); 01028 } else { 01029 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); 01030 } 01031 01032 /* must register the downtime with Icinga so it can schedule it, add comments, etc. */ 01033 register_downtime((data_type==XRDDEFAULT_HOSTDOWNTIME_DATA)?HOST_DOWNTIME:SERVICE_DOWNTIME,downtime_id); 01034 } 01035 01036 /* free temp memory */ 01037 my_free(host_name); 01038 my_free(service_description); 01039 my_free(author); 01040 my_free(comment_data); 01041 01042 /* reset defaults */ 01043 downtime_id=0; 01044 entry_time=0L; 01045 start_time=0L; 01046 end_time=0L; 01047 fixed=FALSE; 01048 triggered_by=0; 01049 is_in_effect=FALSE; 01050 duration=0L; 01051 01052 break; 01053 01054 default: 01055 break; 01056 } 01057 01058 data_type=XRDDEFAULT_NO_DATA; 01059 } 01060 01061 else if(data_type!=XRDDEFAULT_NO_DATA){ 01062 01063 /* slightly faster than strtok () */ 01064 var=input; 01065 if((val=strchr(input,'='))==NULL) 01066 continue; 01067 val[0]='\x0'; 01068 val++; 01069 01070 found_directive=TRUE; 01071 01072 switch(data_type){ 01073 01074 case XRDDEFAULT_INFO_DATA: 01075 if(!strcmp(var,"created")){ 01076 creation_time=strtoul(val,NULL,10); 01077 time(¤t_time); 01078 if(current_time-creation_time<retention_scheduling_horizon) 01079 scheduling_info_is_ok=TRUE; 01080 else 01081 scheduling_info_is_ok=FALSE; 01082 } 01083 else if(!strcmp(var,"version")){ 01084 } 01085 break; 01086 01087 case XRDDEFAULT_PROGRAMSTATUS_DATA: 01088 if(!strcmp(var,"modified_host_attributes")){ 01089 01090 modified_host_process_attributes=strtoul(val,NULL,10); 01091 01092 /* mask out attributes we don't want to retain */ 01093 modified_host_process_attributes&=~process_host_attribute_mask; 01094 } 01095 else if(!strcmp(var,"modified_service_attributes")){ 01096 01097 modified_service_process_attributes=strtoul(val,NULL,10); 01098 01099 /* mask out attributes we don't want to retain */ 01100 modified_service_process_attributes&=~process_service_attribute_mask; 01101 } 01102 if(use_retained_program_state==TRUE){ 01103 if(!strcmp(var,"enable_notifications")){ 01104 if(modified_host_process_attributes & MODATTR_NOTIFICATIONS_ENABLED) 01105 enable_notifications=(atoi(val)>0)?TRUE:FALSE; 01106 } 01107 else if(!strcmp(var,"active_service_checks_enabled")){ 01108 if(modified_service_process_attributes & MODATTR_ACTIVE_CHECKS_ENABLED) 01109 execute_service_checks=(atoi(val)>0)?TRUE:FALSE; 01110 } 01111 else if(!strcmp(var,"passive_service_checks_enabled")){ 01112 if(modified_service_process_attributes & MODATTR_PASSIVE_CHECKS_ENABLED) 01113 accept_passive_service_checks=(atoi(val)>0)?TRUE:FALSE; 01114 } 01115 else if(!strcmp(var,"active_host_checks_enabled")){ 01116 if(modified_host_process_attributes & MODATTR_ACTIVE_CHECKS_ENABLED) 01117 execute_host_checks=(atoi(val)>0)?TRUE:FALSE; 01118 } 01119 else if(!strcmp(var,"passive_host_checks_enabled")){ 01120 if(modified_host_process_attributes & MODATTR_PASSIVE_CHECKS_ENABLED) 01121 accept_passive_host_checks=(atoi(val)>0)?TRUE:FALSE; 01122 } 01123 else if(!strcmp(var,"enable_event_handlers")){ 01124 if(modified_host_process_attributes & MODATTR_EVENT_HANDLER_ENABLED) 01125 enable_event_handlers=(atoi(val)>0)?TRUE:FALSE; 01126 } 01127 else if(!strcmp(var,"obsess_over_services")){ 01128 if(modified_service_process_attributes & MODATTR_OBSESSIVE_HANDLER_ENABLED) 01129 obsess_over_services=(atoi(val)>0)?TRUE:FALSE; 01130 } 01131 else if(!strcmp(var,"obsess_over_hosts")){ 01132 if(modified_host_process_attributes & MODATTR_OBSESSIVE_HANDLER_ENABLED) 01133 obsess_over_hosts=(atoi(val)>0)?TRUE:FALSE; 01134 } 01135 else if(!strcmp(var,"check_service_freshness")){ 01136 if(modified_service_process_attributes & MODATTR_FRESHNESS_CHECKS_ENABLED) 01137 check_service_freshness=(atoi(val)>0)?TRUE:FALSE; 01138 } 01139 else if(!strcmp(var,"check_host_freshness")){ 01140 if(modified_host_process_attributes & MODATTR_FRESHNESS_CHECKS_ENABLED) 01141 check_host_freshness=(atoi(val)>0)?TRUE:FALSE; 01142 } 01143 else if(!strcmp(var,"enable_flap_detection")){ 01144 if(modified_host_process_attributes & MODATTR_FLAP_DETECTION_ENABLED) 01145 enable_flap_detection=(atoi(val)>0)?TRUE:FALSE; 01146 } 01147 else if(!strcmp(var,"enable_failure_prediction")){ 01148 if(modified_host_process_attributes & MODATTR_FAILURE_PREDICTION_ENABLED) 01149 enable_failure_prediction=(atoi(val)>0)?TRUE:FALSE; 01150 } 01151 else if(!strcmp(var,"process_performance_data")){ 01152 if(modified_host_process_attributes & MODATTR_PERFORMANCE_DATA_ENABLED) 01153 process_performance_data=(atoi(val)>0)?TRUE:FALSE; 01154 } 01155 else if(!strcmp(var,"global_host_event_handler")){ 01156 if(modified_host_process_attributes & MODATTR_EVENT_HANDLER_COMMAND){ 01157 01158 /* make sure the check command still exists... */ 01159 tempval=(char *)strdup(val); 01160 temp_ptr=my_strtok(tempval,"!"); 01161 temp_command=find_command(temp_ptr); 01162 temp_ptr=(char *)strdup(val); 01163 my_free(tempval); 01164 01165 if(temp_command!=NULL && temp_ptr!=NULL){ 01166 my_free(global_host_event_handler); 01167 global_host_event_handler=temp_ptr; 01168 } 01169 } 01170 } 01171 else if(!strcmp(var,"global_service_event_handler")){ 01172 if(modified_service_process_attributes & MODATTR_EVENT_HANDLER_COMMAND){ 01173 01174 /* make sure the check command still exists... */ 01175 tempval=(char *)strdup(val); 01176 temp_ptr=my_strtok(tempval,"!"); 01177 temp_command=find_command(temp_ptr); 01178 temp_ptr=(char *)strdup(val); 01179 my_free(tempval); 01180 01181 if(temp_command!=NULL && temp_ptr!=NULL){ 01182 my_free(global_service_event_handler); 01183 global_service_event_handler=temp_ptr; 01184 } 01185 } 01186 } 01187 else if(!strcmp(var,"next_comment_id")) 01188 next_comment_id=strtoul(val,NULL,10); 01189 else if(!strcmp(var,"next_downtime_id")) 01190 next_downtime_id=strtoul(val,NULL,10); 01191 else if(!strcmp(var,"next_event_id")) 01192 next_event_id=strtoul(val,NULL,10); 01193 else if(!strcmp(var,"next_problem_id")) 01194 next_problem_id=strtoul(val,NULL,10); 01195 else if(!strcmp(var,"next_notification_id")) 01196 next_notification_id=strtoul(val,NULL,10); 01197 } 01198 break; 01199 01200 case XRDDEFAULT_HOSTSTATUS_DATA: 01201 01202 if(temp_host==NULL){ 01203 if(!strcmp(var,"host_name")){ 01204 host_name=(char *)strdup(val); 01205 temp_host=find_host(host_name); 01206 } 01207 } 01208 else{ 01209 if(!strcmp(var,"modified_attributes")){ 01210 01211 temp_host->modified_attributes=strtoul(val,NULL,10); 01212 01213 /* mask out attributes we don't want to retain */ 01214 temp_host->modified_attributes&=~host_attribute_mask; 01215 01216 /* break out */ 01217 break; 01218 } 01219 if(retain_flag && temp_host->retain_status_information==TRUE){ 01220 if(!strcmp(var,"has_been_checked")) 01221 temp_host->has_been_checked=(atoi(val)>0)?TRUE:FALSE; 01222 else if(!strcmp(var,"check_execution_time")) 01223 temp_host->execution_time=strtod(val,NULL); 01224 else if(!strcmp(var,"check_latency")) 01225 temp_host->latency=strtod(val,NULL); 01226 else if(!strcmp(var,"check_type")) 01227 temp_host->check_type=atoi(val); 01228 else if(!strcmp(var,"current_state")) 01229 temp_host->current_state=atoi(val); 01230 else if(!strcmp(var,"last_state")) 01231 temp_host->last_state=atoi(val); 01232 else if(!strcmp(var,"last_hard_state")) 01233 temp_host->last_hard_state=atoi(val); 01234 else if(!strcmp(var,"plugin_output")){ 01235 my_free(temp_host->plugin_output); 01236 temp_host->plugin_output=(char *)strdup(val); 01237 } 01238 else if(!strcmp(var,"long_plugin_output")){ 01239 my_free(temp_host->long_plugin_output); 01240 temp_host->long_plugin_output=(char *)strdup(val); 01241 } 01242 else if(!strcmp(var,"performance_data")){ 01243 my_free(temp_host->perf_data); 01244 temp_host->perf_data=(char *)strdup(val); 01245 } 01246 else if(!strcmp(var,"last_check")) { 01247 last_check=strtoul(val,NULL,10); 01248 if (overwrite_data==FALSE && last_check<temp_host->last_check) 01249 retain_flag=FALSE; 01250 else 01251 temp_host->last_check=last_check; 01252 } 01253 else if(!strcmp(var,"next_check")){ 01254 if(use_retained_scheduling_info==TRUE && scheduling_info_is_ok==TRUE) 01255 temp_host->next_check=strtoul(val,NULL,10); 01256 } 01257 else if(!strcmp(var,"check_options")){ 01258 if(use_retained_scheduling_info==TRUE && scheduling_info_is_ok==TRUE) 01259 temp_host->check_options=atoi(val); 01260 } 01261 else if(!strcmp(var,"current_attempt")) 01262 temp_host->current_attempt=(atoi(val)>0)?TRUE:FALSE; 01263 else if(!strcmp(var,"current_event_id")) 01264 temp_host->current_event_id=strtoul(val,NULL,10); 01265 else if(!strcmp(var,"last_event_id")) 01266 temp_host->last_event_id=strtoul(val,NULL,10); 01267 else if(!strcmp(var,"current_problem_id")) 01268 temp_host->current_problem_id=strtoul(val,NULL,10); 01269 else if(!strcmp(var,"last_problem_id")) 01270 temp_host->last_problem_id=strtoul(val,NULL,10); 01271 else if(!strcmp(var,"state_type")) 01272 temp_host->state_type=atoi(val); 01273 else if(!strcmp(var,"last_state_change")) 01274 temp_host->last_state_change=strtoul(val,NULL,10); 01275 else if(!strcmp(var,"last_hard_state_change")) 01276 temp_host->last_hard_state_change=strtoul(val,NULL,10); 01277 else if(!strcmp(var,"last_time_up")) 01278 temp_host->last_time_up=strtoul(val,NULL,10); 01279 else if(!strcmp(var,"last_time_down")) 01280 temp_host->last_time_down=strtoul(val,NULL,10); 01281 else if(!strcmp(var,"last_time_unreachable")) 01282 temp_host->last_time_unreachable=strtoul(val,NULL,10); 01283 else if(!strcmp(var,"notified_on_down")) 01284 temp_host->notified_on_down=(atoi(val)>0)?TRUE:FALSE; 01285 else if(!strcmp(var,"notified_on_unreachable")) 01286 temp_host->notified_on_unreachable=(atoi(val)>0)?TRUE:FALSE; 01287 else if(!strcmp(var,"last_notification")) 01288 temp_host->last_host_notification=strtoul(val,NULL,10); 01289 else if(!strcmp(var,"current_notification_number")) 01290 temp_host->current_notification_number=atoi(val); 01291 #ifdef USE_ST_BASED_ESCAL_RANGES 01292 else if(!strcmp(var,"current_down_notification_number")) 01293 temp_host->current_down_notification_number=atoi(val); 01294 else if(!strcmp(var,"current_unreachable_notification_number")) 01295 temp_host->current_unreachable_notification_number=atoi(val); 01296 #endif 01297 else if(!strcmp(var,"current_notification_id")) 01298 temp_host->current_notification_id=strtoul(val,NULL,10); 01299 else if(!strcmp(var,"is_flapping")) 01300 was_flapping=atoi(val); 01301 else if(!strcmp(var,"percent_state_change")) 01302 temp_host->percent_state_change=strtod(val,NULL); 01303 else if(!strcmp(var,"check_flapping_recovery_notification")) 01304 temp_host->check_flapping_recovery_notification=atoi(val); 01305 else if(!strcmp(var,"state_history")){ 01306 temp_ptr=val; 01307 for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++){ 01308 if((ch=my_strsep(&temp_ptr,","))!=NULL) 01309 temp_host->state_history[x]=atoi(ch); 01310 else 01311 break; 01312 } 01313 temp_host->state_history_index=0; 01314 } 01315 else 01316 found_directive=FALSE; 01317 } 01318 if(retain_flag && temp_host->retain_nonstatus_information==TRUE){ 01319 /* null-op speeds up logic */ 01320 if(found_directive==TRUE); 01321 01322 else if(!strcmp(var,"problem_has_been_acknowledged")) 01323 temp_host->problem_has_been_acknowledged=(atoi(val)>0)?TRUE:FALSE; 01324 else if(!strcmp(var,"acknowledgement_type")) 01325 temp_host->acknowledgement_type=atoi(val); 01326 else if(!strcmp(var,"notifications_enabled")){ 01327 if(temp_host->modified_attributes & MODATTR_NOTIFICATIONS_ENABLED) 01328 temp_host->notifications_enabled=(atoi(val)>0)?TRUE:FALSE; 01329 } 01330 else if(!strcmp(var,"active_checks_enabled")){ 01331 if(temp_host->modified_attributes & MODATTR_ACTIVE_CHECKS_ENABLED) 01332 temp_host->checks_enabled=(atoi(val)>0)?TRUE:FALSE; 01333 } 01334 else if(!strcmp(var,"passive_checks_enabled")){ 01335 if(temp_host->modified_attributes & MODATTR_PASSIVE_CHECKS_ENABLED) 01336 temp_host->accept_passive_host_checks=(atoi(val)>0)?TRUE:FALSE; 01337 } 01338 else if(!strcmp(var,"event_handler_enabled")){ 01339 if(temp_host->modified_attributes & MODATTR_EVENT_HANDLER_ENABLED) 01340 temp_host->event_handler_enabled=(atoi(val)>0)?TRUE:FALSE; 01341 } 01342 else if(!strcmp(var,"flap_detection_enabled")){ 01343 if(temp_host->modified_attributes & MODATTR_FLAP_DETECTION_ENABLED) 01344 temp_host->flap_detection_enabled=(atoi(val)>0)?TRUE:FALSE; 01345 } 01346 else if(!strcmp(var,"failure_prediction_enabled")){ 01347 if(temp_host->modified_attributes & MODATTR_FAILURE_PREDICTION_ENABLED) 01348 temp_host->failure_prediction_enabled=(atoi(val)>0)?TRUE:FALSE; 01349 } 01350 else if(!strcmp(var,"process_performance_data")){ 01351 if(temp_host->modified_attributes & MODATTR_PERFORMANCE_DATA_ENABLED) 01352 temp_host->process_performance_data=(atoi(val)>0)?TRUE:FALSE; 01353 } 01354 else if(!strcmp(var,"obsess_over_host")){ 01355 if(temp_host->modified_attributes & MODATTR_OBSESSIVE_HANDLER_ENABLED) 01356 temp_host->obsess_over_host=(atoi(val)>0)?TRUE:FALSE; 01357 } 01358 else if(!strcmp(var,"check_command")){ 01359 if(temp_host->modified_attributes & MODATTR_CHECK_COMMAND){ 01360 01361 /* make sure the check command still exists... */ 01362 tempval=(char *)strdup(val); 01363 temp_ptr=my_strtok(tempval,"!"); 01364 temp_command=find_command(temp_ptr); 01365 temp_ptr=(char *)strdup(val); 01366 my_free(tempval); 01367 01368 if(temp_command!=NULL && temp_ptr!=NULL){ 01369 my_free(temp_host->host_check_command); 01370 temp_host->host_check_command=temp_ptr; 01371 } 01372 else 01373 temp_host->modified_attributes-=MODATTR_CHECK_COMMAND; 01374 } 01375 } 01376 else if(!strcmp(var,"check_period")){ 01377 if(temp_host->modified_attributes & MODATTR_CHECK_TIMEPERIOD){ 01378 01379 /* make sure the timeperiod still exists... */ 01380 temp_timeperiod=find_timeperiod(val); 01381 temp_ptr=(char *)strdup(val); 01382 01383 if(temp_timeperiod!=NULL && temp_ptr!=NULL){ 01384 my_free(temp_host->check_period); 01385 temp_host->check_period=temp_ptr; 01386 } 01387 else 01388 temp_host->modified_attributes-=MODATTR_CHECK_TIMEPERIOD; 01389 } 01390 } 01391 else if(!strcmp(var,"notification_period")){ 01392 if(temp_host->modified_attributes & MODATTR_NOTIFICATION_TIMEPERIOD){ 01393 01394 /* make sure the timeperiod still exists... */ 01395 temp_timeperiod=find_timeperiod(val); 01396 temp_ptr=(char *)strdup(val); 01397 01398 if(temp_timeperiod!=NULL && temp_ptr!=NULL){ 01399 my_free(temp_host->notification_period); 01400 temp_host->notification_period=temp_ptr; 01401 } 01402 else 01403 temp_host->modified_attributes-=MODATTR_NOTIFICATION_TIMEPERIOD; 01404 } 01405 } 01406 else if(!strcmp(var,"event_handler")){ 01407 if(temp_host->modified_attributes & MODATTR_EVENT_HANDLER_COMMAND){ 01408 01409 /* make sure the check command still exists... */ 01410 tempval=(char *)strdup(val); 01411 temp_ptr=my_strtok(tempval,"!"); 01412 temp_command=find_command(temp_ptr); 01413 temp_ptr=(char *)strdup(val); 01414 my_free(tempval); 01415 01416 if(temp_command!=NULL && temp_ptr!=NULL){ 01417 my_free(temp_host->event_handler); 01418 temp_host->event_handler=temp_ptr; 01419 } 01420 else 01421 temp_host->modified_attributes-=MODATTR_EVENT_HANDLER_COMMAND; 01422 } 01423 } 01424 else if(!strcmp(var,"normal_check_interval")){ 01425 if(temp_host->modified_attributes & MODATTR_NORMAL_CHECK_INTERVAL && strtod(val,NULL)>=0) 01426 temp_host->check_interval=strtod(val,NULL); 01427 } 01428 else if(!strcmp(var,"retry_check_interval")){ 01429 if(temp_host->modified_attributes & MODATTR_RETRY_CHECK_INTERVAL && strtod(val,NULL)>=0) 01430 temp_host->retry_interval=strtod(val,NULL); 01431 } 01432 else if(!strcmp(var,"max_attempts")){ 01433 if(temp_host->modified_attributes & MODATTR_MAX_CHECK_ATTEMPTS && atoi(val)>=1){ 01434 01435 temp_host->max_attempts=atoi(val); 01436 01437 /* adjust current attempt number if in a hard state */ 01438 if(temp_host->state_type==HARD_STATE && temp_host->current_state!=HOST_UP && temp_host->current_attempt>1) 01439 temp_host->current_attempt=temp_host->max_attempts; 01440 } 01441 } 01442 01443 /* custom variables */ 01444 else if(var[0]=='_'){ 01445 01446 if(temp_host->modified_attributes & MODATTR_CUSTOM_VARIABLE){ 01447 01448 /* get the variable name */ 01449 if((customvarname=(char *)strdup(var+1))){ 01450 01451 for(temp_customvariablesmember=temp_host->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 01452 if(!strcmp(customvarname,temp_customvariablesmember->variable_name)){ 01453 if((x=atoi(val))>0 && strlen(val)>3){ 01454 my_free(temp_customvariablesmember->variable_value); 01455 temp_customvariablesmember->variable_value=(char *)strdup(val+2); 01456 temp_customvariablesmember->has_been_modified=(x>0)?TRUE:FALSE; 01457 } 01458 break; 01459 } 01460 } 01461 01462 /* free memory */ 01463 my_free(customvarname); 01464 } 01465 } 01466 01467 } 01468 } 01469 01470 } 01471 01472 break; 01473 01474 case XRDDEFAULT_SERVICESTATUS_DATA: 01475 01476 if(temp_service==NULL){ 01477 if(!strcmp(var,"host_name")){ 01478 host_name=(char *)strdup(val); 01479 01480 /*temp_service=find_service(host_name,service_description);*/ 01481 01482 /* break out */ 01483 break; 01484 } 01485 else if(!strcmp(var,"service_description")){ 01486 service_description=(char *)strdup(val); 01487 temp_service=find_service(host_name,service_description); 01488 01489 /* break out */ 01490 break; 01491 } 01492 } 01493 else{ 01494 if(!strcmp(var,"modified_attributes")){ 01495 01496 temp_service->modified_attributes=strtoul(val,NULL,10); 01497 01498 /* mask out attributes we don't want to retain */ 01499 temp_service->modified_attributes&=~service_attribute_mask; 01500 } 01501 if(retain_flag && temp_service->retain_status_information==TRUE){ 01502 if(!strcmp(var,"has_been_checked")) 01503 temp_service->has_been_checked=(atoi(val)>0)?TRUE:FALSE; 01504 else if(!strcmp(var,"check_execution_time")) 01505 temp_service->execution_time=strtod(val,NULL); 01506 else if(!strcmp(var,"check_latency")) 01507 temp_service->latency=strtod(val,NULL); 01508 else if(!strcmp(var,"check_type")) 01509 temp_service->check_type=atoi(val); 01510 else if(!strcmp(var,"current_state")) 01511 temp_service->current_state=atoi(val); 01512 else if(!strcmp(var,"last_state")) 01513 temp_service->last_state=atoi(val); 01514 else if(!strcmp(var,"last_hard_state")) 01515 temp_service->last_hard_state=atoi(val); 01516 else if(!strcmp(var,"current_attempt")) 01517 temp_service->current_attempt=atoi(val); 01518 else if(!strcmp(var,"current_event_id")) 01519 temp_service->current_event_id=strtoul(val,NULL,10); 01520 else if(!strcmp(var,"last_event_id")) 01521 temp_service->last_event_id=strtoul(val,NULL,10); 01522 else if(!strcmp(var,"current_problem_id")) 01523 temp_service->current_problem_id=strtoul(val,NULL,10); 01524 else if(!strcmp(var,"last_problem_id")) 01525 temp_service->last_problem_id=strtoul(val,NULL,10); 01526 else if(!strcmp(var,"state_type")) 01527 temp_service->state_type=atoi(val); 01528 else if(!strcmp(var,"last_state_change")) 01529 temp_service->last_state_change=strtoul(val,NULL,10); 01530 else if(!strcmp(var,"last_hard_state_change")) 01531 temp_service->last_hard_state_change=strtoul(val,NULL,10); 01532 else if(!strcmp(var,"last_time_ok")) 01533 temp_service->last_time_ok=strtoul(val,NULL,10); 01534 else if(!strcmp(var,"last_time_warning")) 01535 temp_service->last_time_warning=strtoul(val,NULL,10); 01536 else if(!strcmp(var,"last_time_unknown")) 01537 temp_service->last_time_unknown=strtoul(val,NULL,10); 01538 else if(!strcmp(var,"last_time_critical")) 01539 temp_service->last_time_critical=strtoul(val,NULL,10); 01540 else if(!strcmp(var,"plugin_output")){ 01541 my_free(temp_service->plugin_output); 01542 temp_service->plugin_output=(char *)strdup(val); 01543 } 01544 else if(!strcmp(var,"long_plugin_output")){ 01545 my_free(temp_service->long_plugin_output); 01546 temp_service->long_plugin_output=(char *)strdup(val); 01547 } 01548 else if(!strcmp(var,"performance_data")){ 01549 my_free(temp_service->perf_data); 01550 temp_service->perf_data=(char *)strdup(val); 01551 } 01552 else if(!strcmp(var,"last_check")){ 01553 last_check=strtoul(val,NULL,10); 01554 if (overwrite_data==FALSE && last_check<temp_service->last_check) 01555 retain_flag=FALSE; 01556 else 01557 temp_service->last_check=last_check; 01558 } 01559 01560 else if(!strcmp(var,"next_check")){ 01561 if(use_retained_scheduling_info==TRUE && scheduling_info_is_ok==TRUE) 01562 temp_service->next_check=strtoul(val,NULL,10); 01563 } 01564 else if(!strcmp(var,"check_options")){ 01565 if(use_retained_scheduling_info==TRUE && scheduling_info_is_ok==TRUE) 01566 temp_service->check_options=atoi(val); 01567 } 01568 else if(!strcmp(var,"notified_on_unknown")) 01569 temp_service->notified_on_unknown=(atoi(val)>0)?TRUE:FALSE; 01570 else if(!strcmp(var,"notified_on_warning")) 01571 temp_service->notified_on_warning=(atoi(val)>0)?TRUE:FALSE; 01572 else if(!strcmp(var,"notified_on_critical")) 01573 temp_service->notified_on_critical=(atoi(val)>0)?TRUE:FALSE; 01574 else if(!strcmp(var,"current_notification_number")) 01575 temp_service->current_notification_number=atoi(val); 01576 #ifdef USE_ST_BASED_ESCAL_RANGES 01577 else if(!strcmp(var,"current_warning_notification_number")) 01578 temp_service->current_warning_notification_number=atoi(val); 01579 else if(!strcmp(var,"current_critical_notification_number")) 01580 temp_service->current_critical_notification_number=atoi(val); 01581 else if(!strcmp(var,"current_unknown_notification_number")) 01582 temp_service->current_unknown_notification_number=atoi(val); 01583 #endif 01584 else if(!strcmp(var,"current_notification_id")) 01585 temp_service->current_notification_id=strtoul(val,NULL,10); 01586 else if(!strcmp(var,"last_notification")) 01587 temp_service->last_notification=strtoul(val,NULL,10); 01588 else if(!strcmp(var,"is_flapping")) 01589 was_flapping=atoi(val); 01590 else if(!strcmp(var,"percent_state_change")) 01591 temp_service->percent_state_change=strtod(val,NULL); 01592 else if(!strcmp(var,"check_flapping_recovery_notification")) 01593 temp_service->check_flapping_recovery_notification=atoi(val); 01594 else if(!strcmp(var,"state_history")){ 01595 temp_ptr=val; 01596 for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++){ 01597 if((ch=my_strsep(&temp_ptr,","))!=NULL) 01598 temp_service->state_history[x]=atoi(ch); 01599 else 01600 break; 01601 } 01602 temp_service->state_history_index=0; 01603 } 01604 else 01605 found_directive=FALSE; 01606 } 01607 if(retain_flag && temp_service->retain_nonstatus_information==TRUE){ 01608 /* null-op speeds up logic */ 01609 if(found_directive==TRUE); 01610 01611 else if(!strcmp(var,"problem_has_been_acknowledged")) 01612 temp_service->problem_has_been_acknowledged=(atoi(val)>0)?TRUE:FALSE; 01613 else if(!strcmp(var,"acknowledgement_type")) 01614 temp_service->acknowledgement_type=atoi(val); 01615 else if(!strcmp(var,"notifications_enabled")){ 01616 if(temp_service->modified_attributes & MODATTR_NOTIFICATIONS_ENABLED) 01617 temp_service->notifications_enabled=(atoi(val)>0)?TRUE:FALSE; 01618 } 01619 else if(!strcmp(var,"active_checks_enabled")){ 01620 if(temp_service->modified_attributes & MODATTR_ACTIVE_CHECKS_ENABLED) 01621 temp_service->checks_enabled=(atoi(val)>0)?TRUE:FALSE; 01622 } 01623 else if(!strcmp(var,"passive_checks_enabled")){ 01624 if(temp_service->modified_attributes & MODATTR_PASSIVE_CHECKS_ENABLED) 01625 temp_service->accept_passive_service_checks=(atoi(val)>0)?TRUE:FALSE; 01626 } 01627 else if(!strcmp(var,"event_handler_enabled")){ 01628 if(temp_service->modified_attributes & MODATTR_EVENT_HANDLER_ENABLED) 01629 temp_service->event_handler_enabled=(atoi(val)>0)?TRUE:FALSE; 01630 } 01631 else if(!strcmp(var,"flap_detection_enabled")){ 01632 if(temp_service->modified_attributes & MODATTR_FLAP_DETECTION_ENABLED) 01633 temp_service->flap_detection_enabled=(atoi(val)>0)?TRUE:FALSE; 01634 } 01635 else if(!strcmp(var,"failure_prediction_enabled")){ 01636 if(temp_service->modified_attributes & MODATTR_FAILURE_PREDICTION_ENABLED) 01637 temp_service->failure_prediction_enabled=(atoi(val)>0)?TRUE:FALSE; 01638 } 01639 else if(!strcmp(var,"process_performance_data")){ 01640 if(temp_service->modified_attributes & MODATTR_PERFORMANCE_DATA_ENABLED) 01641 temp_service->process_performance_data=(atoi(val)>0)?TRUE:FALSE; 01642 } 01643 else if(!strcmp(var,"obsess_over_service")){ 01644 if(temp_service->modified_attributes & MODATTR_OBSESSIVE_HANDLER_ENABLED) 01645 temp_service->obsess_over_service=(atoi(val)>0)?TRUE:FALSE; 01646 } 01647 else if(!strcmp(var,"check_command")){ 01648 if(temp_service->modified_attributes & MODATTR_CHECK_COMMAND){ 01649 01650 /* make sure the check command still exists... */ 01651 tempval=(char *)strdup(val); 01652 temp_ptr=my_strtok(tempval,"!"); 01653 temp_command=find_command(temp_ptr); 01654 temp_ptr=(char *)strdup(val); 01655 my_free(tempval); 01656 01657 if(temp_command!=NULL && temp_ptr!=NULL){ 01658 my_free(temp_service->service_check_command); 01659 temp_service->service_check_command=temp_ptr; 01660 } 01661 else 01662 temp_service->modified_attributes-=MODATTR_CHECK_COMMAND; 01663 } 01664 } 01665 else if(!strcmp(var,"check_period")){ 01666 if(temp_service->modified_attributes & MODATTR_CHECK_TIMEPERIOD){ 01667 01668 /* make sure the timeperiod still exists... */ 01669 temp_timeperiod=find_timeperiod(val); 01670 temp_ptr=(char *)strdup(val); 01671 01672 if(temp_timeperiod!=NULL && temp_ptr!=NULL){ 01673 my_free(temp_service->check_period); 01674 temp_service->check_period=temp_ptr; 01675 } 01676 else 01677 temp_service->modified_attributes-=MODATTR_CHECK_TIMEPERIOD; 01678 } 01679 } 01680 else if(!strcmp(var,"notification_period")){ 01681 if(temp_service->modified_attributes & MODATTR_NOTIFICATION_TIMEPERIOD){ 01682 01683 /* make sure the timeperiod still exists... */ 01684 temp_timeperiod=find_timeperiod(val); 01685 temp_ptr=(char *)strdup(val); 01686 01687 if(temp_timeperiod!=NULL && temp_ptr!=NULL){ 01688 my_free(temp_service->notification_period); 01689 temp_service->notification_period=temp_ptr; 01690 } 01691 else 01692 temp_service->modified_attributes-=MODATTR_NOTIFICATION_TIMEPERIOD; 01693 } 01694 } 01695 else if(!strcmp(var,"event_handler")){ 01696 if(temp_service->modified_attributes & MODATTR_EVENT_HANDLER_COMMAND){ 01697 01698 /* make sure the check command still exists... */ 01699 tempval=(char *)strdup(val); 01700 temp_ptr=my_strtok(tempval,"!"); 01701 temp_command=find_command(temp_ptr); 01702 temp_ptr=(char *)strdup(val); 01703 my_free(tempval); 01704 01705 if(temp_command!=NULL && temp_ptr!=NULL){ 01706 my_free(temp_service->event_handler); 01707 temp_service->event_handler=temp_ptr; 01708 } 01709 else 01710 temp_service->modified_attributes-=MODATTR_EVENT_HANDLER_COMMAND; 01711 } 01712 } 01713 else if(!strcmp(var,"normal_check_interval")){ 01714 if(temp_service->modified_attributes & MODATTR_NORMAL_CHECK_INTERVAL && strtod(val,NULL)>=0) 01715 temp_service->check_interval=strtod(val,NULL); 01716 } 01717 else if(!strcmp(var,"retry_check_interval")){ 01718 if(temp_service->modified_attributes & MODATTR_RETRY_CHECK_INTERVAL && strtod(val,NULL)>=0) 01719 temp_service->retry_interval=strtod(val,NULL); 01720 } 01721 else if(!strcmp(var,"max_attempts")){ 01722 if(temp_service->modified_attributes & MODATTR_MAX_CHECK_ATTEMPTS && atoi(val)>=1){ 01723 01724 temp_service->max_attempts=atoi(val); 01725 01726 /* adjust current attempt number if in a hard state */ 01727 if(temp_service->state_type==HARD_STATE && temp_service->current_state!=STATE_OK && temp_service->current_attempt>1) 01728 temp_service->current_attempt=temp_service->max_attempts; 01729 } 01730 } 01731 01732 /* custom variables */ 01733 else if(var[0]=='_'){ 01734 01735 if(temp_service->modified_attributes & MODATTR_CUSTOM_VARIABLE){ 01736 01737 /* get the variable name */ 01738 if((customvarname=(char *)strdup(var+1))){ 01739 01740 for(temp_customvariablesmember=temp_service->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 01741 if(!strcmp(customvarname,temp_customvariablesmember->variable_name)){ 01742 if((x=atoi(val))>0 && strlen(val)>3){ 01743 my_free(temp_customvariablesmember->variable_value); 01744 temp_customvariablesmember->variable_value=(char *)strdup(val+2); 01745 temp_customvariablesmember->has_been_modified=(x>0)?TRUE:FALSE; 01746 } 01747 break; 01748 } 01749 } 01750 01751 /* free memory */ 01752 my_free(customvarname); 01753 } 01754 } 01755 01756 } 01757 } 01758 } 01759 01760 break; 01761 01762 case XRDDEFAULT_CONTACTSTATUS_DATA: 01763 if(temp_contact==NULL){ 01764 if(!strcmp(var,"contact_name")){ 01765 contact_name=(char *)strdup(val); 01766 temp_contact=find_contact(contact_name); 01767 } 01768 } 01769 else{ 01770 if(!strcmp(var,"modified_attributes")){ 01771 01772 temp_contact->modified_attributes=strtoul(val,NULL,10); 01773 01774 /* mask out attributes we don't want to retain */ 01775 temp_contact->modified_attributes&=~contact_attribute_mask; 01776 } 01777 else if(!strcmp(var,"modified_host_attributes")){ 01778 01779 temp_contact->modified_host_attributes=strtoul(val,NULL,10); 01780 01781 /* mask out attributes we don't want to retain */ 01782 temp_contact->modified_host_attributes&=~contact_host_attribute_mask; 01783 } 01784 else if(!strcmp(var,"modified_service_attributes")){ 01785 temp_contact->modified_service_attributes=strtoul(val,NULL,10); 01786 01787 /* mask out attributes we don't want to retain */ 01788 temp_contact->modified_service_attributes&=~contact_service_attribute_mask; 01789 } 01790 else if(temp_contact->retain_status_information==TRUE){ 01791 if(!strcmp(var,"last_host_notification")) 01792 temp_contact->last_host_notification=strtoul(val,NULL,10); 01793 else if(!strcmp(var,"last_service_notification")) 01794 temp_contact->last_service_notification=strtoul(val,NULL,10); 01795 else 01796 found_directive=FALSE; 01797 } 01798 if(temp_contact->retain_nonstatus_information==TRUE){ 01799 /* null-op speeds up logic */ 01800 if(found_directive==TRUE); 01801 01802 else if(!strcmp(var,"host_notification_period")){ 01803 if(temp_contact->modified_host_attributes & MODATTR_NOTIFICATION_TIMEPERIOD){ 01804 01805 /* make sure the timeperiod still exists... */ 01806 temp_timeperiod=find_timeperiod(val); 01807 temp_ptr=(char *)strdup(val); 01808 01809 if(temp_timeperiod!=NULL && temp_ptr!=NULL){ 01810 my_free(temp_contact->host_notification_period); 01811 temp_contact->host_notification_period=temp_ptr; 01812 } 01813 else 01814 temp_contact->modified_host_attributes-=MODATTR_NOTIFICATION_TIMEPERIOD; 01815 } 01816 } 01817 else if(!strcmp(var,"service_notification_period")){ 01818 if(temp_contact->modified_service_attributes & MODATTR_NOTIFICATION_TIMEPERIOD){ 01819 01820 /* make sure the timeperiod still exists... */ 01821 temp_timeperiod=find_timeperiod(val); 01822 temp_ptr=(char *)strdup(val); 01823 01824 if(temp_timeperiod!=NULL && temp_ptr!=NULL){ 01825 my_free(temp_contact->service_notification_period); 01826 temp_contact->service_notification_period=temp_ptr; 01827 } 01828 else 01829 temp_contact->modified_service_attributes-=MODATTR_NOTIFICATION_TIMEPERIOD; 01830 } 01831 } 01832 else if(!strcmp(var,"host_notifications_enabled")){ 01833 if(temp_contact->modified_host_attributes & MODATTR_NOTIFICATIONS_ENABLED) 01834 temp_contact->host_notifications_enabled=(atoi(val)>0)?TRUE:FALSE; 01835 } 01836 else if(!strcmp(var,"service_notifications_enabled")){ 01837 if(temp_contact->modified_service_attributes & MODATTR_NOTIFICATIONS_ENABLED) 01838 temp_contact->service_notifications_enabled=(atoi(val)>0)?TRUE:FALSE; 01839 } 01840 /* custom variables */ 01841 else if(var[0]=='_'){ 01842 01843 if(temp_contact->modified_attributes & MODATTR_CUSTOM_VARIABLE){ 01844 01845 /* get the variable name */ 01846 if((customvarname=(char *)strdup(var+1))){ 01847 01848 for(temp_customvariablesmember=temp_contact->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){ 01849 if(!strcmp(customvarname,temp_customvariablesmember->variable_name)){ 01850 if((x=atoi(val))>0 && strlen(val)>3){ 01851 my_free(temp_customvariablesmember->variable_value); 01852 temp_customvariablesmember->variable_value=(char *)strdup(val+2); 01853 temp_customvariablesmember->has_been_modified=(x>0)?TRUE:FALSE; 01854 } 01855 break; 01856 } 01857 } 01858 01859 /* free memory */ 01860 my_free(customvarname); 01861 } 01862 } 01863 } 01864 } 01865 } 01866 break; 01867 01868 case XRDDEFAULT_HOSTCOMMENT_DATA: 01869 case XRDDEFAULT_SERVICECOMMENT_DATA: 01870 if(!strcmp(var,"host_name")) 01871 host_name=(char *)strdup(val); 01872 else if(!strcmp(var,"service_description")) 01873 service_description=(char *)strdup(val); 01874 else if(!strcmp(var,"entry_type")) 01875 entry_type=atoi(val); 01876 else if(!strcmp(var,"comment_id")) 01877 comment_id=strtoul(val,NULL,10); 01878 else if(!strcmp(var,"source")) 01879 source=atoi(val); 01880 else if(!strcmp(var,"persistent")) 01881 persistent=(atoi(val)>0)?TRUE:FALSE; 01882 else if(!strcmp(var,"entry_time")) 01883 entry_time=strtoul(val,NULL,10); 01884 else if(!strcmp(var,"expires")) 01885 expires=(atoi(val)>0)?TRUE:FALSE; 01886 else if(!strcmp(var,"expire_time")) 01887 expire_time=strtoul(val,NULL,10); 01888 else if(!strcmp(var,"author")) 01889 author=(char *)strdup(val); 01890 else if(!strcmp(var,"comment_data")) 01891 comment_data=(char *)strdup(val); 01892 break; 01893 01894 case XRDDEFAULT_HOSTDOWNTIME_DATA: 01895 case XRDDEFAULT_SERVICEDOWNTIME_DATA: 01896 if(!strcmp(var,"host_name")) 01897 host_name=(char *)strdup(val); 01898 else if(!strcmp(var,"service_description")) 01899 service_description=(char *)strdup(val); 01900 else if(!strcmp(var,"downtime_id")) 01901 downtime_id=strtoul(val,NULL,10); 01902 else if(!strcmp(var,"entry_time")) 01903 entry_time=strtoul(val,NULL,10); 01904 else if(!strcmp(var,"start_time")) 01905 start_time=strtoul(val,NULL,10); 01906 else if(!strcmp(var,"end_time")) 01907 end_time=strtoul(val,NULL,10); 01908 else if(!strcmp(var,"fixed")) 01909 fixed=(atoi(val)>0)?TRUE:FALSE; 01910 else if(!strcmp(var,"triggered_by")) 01911 triggered_by=strtoul(val,NULL,10); 01912 else if(!strcmp(var,"is_in_effect")) 01913 is_in_effect=(atoi(val)>0)?TRUE:FALSE; 01914 else if(!strcmp(var,"duration")) 01915 duration=strtoul(val,NULL,10); 01916 else if(!strcmp(var,"author")) 01917 author=(char *)strdup(val); 01918 else if(!strcmp(var,"comment")) 01919 comment_data=(char *)strdup(val); 01920 break; 01921 01922 default: 01923 break; 01924 } 01925 } 01926 } 01927 01928 /* free memory and close the file */ 01929 my_free(inputbuf); 01930 mmap_fclose(thefile); 01931 01932 if(sort_downtime()!=OK) 01933 return ERROR; 01934 if(sort_comments()!=OK) 01935 return ERROR; 01936 01937 /* If this is a sync file, remove the file */ 01938 if(overwrite_data==FALSE) 01939 unlink(retention_file); 01940 01941 if(test_scheduling==TRUE) 01942 gettimeofday(&tv[1],NULL); 01943 01944 if(test_scheduling==TRUE){ 01945 runtime[0]=(double)((double)(tv[1].tv_sec-tv[0].tv_sec)+(double)((tv[1].tv_usec-tv[0].tv_usec)/1000.0)/1000.0); 01946 01947 runtime[1]=(double)((double)(tv[1].tv_sec-tv[0].tv_sec)+(double)((tv[1].tv_usec-tv[0].tv_usec)/1000.0)/1000.0); 01948 01949 printf("RETENTION DATA TIMES\n"); 01950 printf("----------------------------------\n"); 01951 printf("Read and Process: %.6lf sec\n",runtime[0]); 01952 printf(" ============\n"); 01953 printf("TOTAL: %.6lf sec\n",runtime[1]); 01954 printf("\n\n"); 01955 } 01956 01957 log_debug_info(DEBUGL_FUNCTIONS,0,"xrddefault_read_state_information() end\n"); 01958 01959 return OK; 01960 }