![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /***************************************************************************** 00002 * 00003 * FLAPPING.C - State flap detection and handling routines for Icinga 00004 * 00005 * Copyright (c) 2001-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 /*********** COMMON HEADER FILES ***********/ 00027 00028 #include "../include/config.h" 00029 #include "../include/common.h" 00030 #include "../include/objects.h" 00031 #include "../include/comments.h" 00032 #include "../include/statusdata.h" 00033 #include "../include/icinga.h" 00034 #include "../include/broker.h" 00035 00036 extern int interval_length; 00037 00038 extern int enable_flap_detection; 00039 00040 extern double low_service_flap_threshold; 00041 extern double high_service_flap_threshold; 00042 extern double low_host_flap_threshold; 00043 extern double high_host_flap_threshold; 00044 00045 extern host *host_list; 00046 extern service *service_list; 00047 00048 extern unsigned long modified_host_process_attributes; 00049 extern unsigned long modified_service_process_attributes; 00050 00051 int dummy; /* reduce compiler warnings */ 00052 00053 /******************************************************************/ 00054 /******************** FLAP DETECTION FUNCTIONS ********************/ 00055 /******************************************************************/ 00056 00057 00058 /* detects service flapping */ 00059 void check_for_service_flapping(service *svc, int update, int allow_flapstart_notification){ 00060 int update_history=TRUE; 00061 int is_flapping=FALSE; 00062 register int x=0; 00063 register int y=0; 00064 int last_state_history_value=STATE_OK; 00065 double curved_changes=0.0; 00066 double curved_percent_change=0.0; 00067 double low_threshold=0.0; 00068 double high_threshold=0.0; 00069 double low_curve_value=0.75; 00070 double high_curve_value=1.25; 00071 00072 /* large install tweaks skips all flap detection logic - including state change calculation */ 00073 00074 00075 log_debug_info(DEBUGL_FUNCTIONS,0,"check_for_service_flapping()\n"); 00076 00077 if(svc==NULL) 00078 return; 00079 00080 log_debug_info(DEBUGL_FLAPPING,1,"Checking service '%s' on host '%s' for flapping...\n",svc->description,svc->host_name); 00081 00082 /* if this is a soft service state and not a soft recovery, don't record this in the history */ 00083 /* only hard states and soft recoveries get recorded for flap detection */ 00084 if(svc->state_type==SOFT_STATE && svc->current_state!=STATE_OK) 00085 return; 00086 00087 /* what threshold values should we use (global or service-specific)? */ 00088 low_threshold=(svc->low_flap_threshold<=0.0)?low_service_flap_threshold:svc->low_flap_threshold; 00089 high_threshold=(svc->high_flap_threshold<=0.0)?high_service_flap_threshold:svc->high_flap_threshold; 00090 00091 update_history=update; 00092 00093 /* should we update state history for this state? */ 00094 if(update_history==TRUE){ 00095 00096 if(svc->current_state==STATE_OK && svc->flap_detection_on_ok==FALSE) 00097 update_history=FALSE; 00098 if(svc->current_state==STATE_WARNING && svc->flap_detection_on_warning==FALSE) 00099 update_history=FALSE; 00100 if(svc->current_state==STATE_UNKNOWN && svc->flap_detection_on_unknown==FALSE) 00101 update_history=FALSE; 00102 if(svc->current_state==STATE_CRITICAL && svc->flap_detection_on_critical==FALSE) 00103 update_history=FALSE; 00104 } 00105 00106 /* record current service state */ 00107 if(update_history==TRUE){ 00108 00109 /* record the current state in the state history */ 00110 svc->state_history[svc->state_history_index]=svc->current_state; 00111 00112 /* increment state history index to next available slot */ 00113 svc->state_history_index++; 00114 if(svc->state_history_index>=MAX_STATE_HISTORY_ENTRIES) 00115 svc->state_history_index=0; 00116 } 00117 00118 /* calculate overall and curved percent state changes */ 00119 for(x=0,y=svc->state_history_index;x<MAX_STATE_HISTORY_ENTRIES;x++){ 00120 00121 if(x==0){ 00122 last_state_history_value=svc->state_history[y]; 00123 y++; 00124 if(y>=MAX_STATE_HISTORY_ENTRIES) 00125 y=0; 00126 continue; 00127 } 00128 00129 if(last_state_history_value!=svc->state_history[y]) 00130 curved_changes+=(((double)(x-1)*(high_curve_value-low_curve_value))/((double)(MAX_STATE_HISTORY_ENTRIES-2)))+low_curve_value; 00131 00132 last_state_history_value=svc->state_history[y]; 00133 00134 y++; 00135 if(y>=MAX_STATE_HISTORY_ENTRIES) 00136 y=0; 00137 } 00138 00139 /* calculate overall percent change in state */ 00140 curved_percent_change=(double)(((double)curved_changes*100.0)/(double)(MAX_STATE_HISTORY_ENTRIES-1)); 00141 00142 svc->percent_state_change=curved_percent_change; 00143 00144 log_debug_info(DEBUGL_FLAPPING,2,"LFT=%.2f, HFT=%.2f, CPC=%.2f, PSC=%.2f%%\n",low_threshold,high_threshold,curved_percent_change,curved_percent_change); 00145 00146 00147 /* don't do anything if we don't have flap detection enabled on a program-wide basis */ 00148 if(enable_flap_detection==FALSE) 00149 return; 00150 00151 /* don't do anything if we don't have flap detection enabled for this service */ 00152 if(svc->flap_detection_enabled==FALSE) 00153 return; 00154 00155 /* are we flapping, undecided, or what?... */ 00156 00157 /* we're undecided, so don't change the current flap state */ 00158 if(curved_percent_change>low_threshold && curved_percent_change<high_threshold) 00159 return; 00160 00161 /* we're below the lower bound, so we're not flapping */ 00162 else if(curved_percent_change<=low_threshold) 00163 is_flapping=FALSE; 00164 00165 /* else we're above the upper bound, so we are flapping */ 00166 else if(curved_percent_change>=high_threshold) 00167 is_flapping=TRUE; 00168 00169 log_debug_info(DEBUGL_FLAPPING,1,"Service %s flapping (%.2f%% state change).\n",(is_flapping==TRUE)?"is":"is not",curved_percent_change); 00170 00171 /* did the service just start flapping? */ 00172 if(is_flapping==TRUE && svc->is_flapping==FALSE) 00173 set_service_flap(svc,curved_percent_change,high_threshold,low_threshold,allow_flapstart_notification); 00174 00175 /* did the service just stop flapping? */ 00176 else if(is_flapping==FALSE && svc->is_flapping==TRUE) 00177 clear_service_flap(svc,curved_percent_change,high_threshold,low_threshold); 00178 00179 return; 00180 } 00181 00182 00183 /* detects host flapping */ 00184 void check_for_host_flapping(host *hst, int update, int actual_check, int allow_flapstart_notification){ 00185 int update_history=TRUE; 00186 int is_flapping=FALSE; 00187 register int x=0; 00188 register int y=0; 00189 int last_state_history_value=HOST_UP; 00190 unsigned long wait_threshold=0L; 00191 double curved_changes=0.0; 00192 double curved_percent_change=0.0; 00193 time_t current_time=0L; 00194 double low_threshold=0.0; 00195 double high_threshold=0.0; 00196 double low_curve_value=0.75; 00197 double high_curve_value=1.25; 00198 00199 00200 log_debug_info(DEBUGL_FUNCTIONS,0,"check_for_host_flapping()\n"); 00201 00202 if(hst==NULL) 00203 return; 00204 00205 log_debug_info(DEBUGL_FLAPPING,1,"Checking host '%s' for flapping...\n",hst->name); 00206 00207 time(¤t_time); 00208 00209 /* period to wait for updating archived state info if we have no state change */ 00210 if(hst->total_services==0) 00211 wait_threshold=hst->notification_interval*interval_length; 00212 else 00213 wait_threshold=(hst->total_service_check_interval*interval_length)/hst->total_services; 00214 00215 update_history=update; 00216 00217 /* should we update state history for this state? */ 00218 if(update_history==TRUE){ 00219 00220 if(hst->current_state==HOST_UP && hst->flap_detection_on_up==FALSE) 00221 update_history=FALSE; 00222 if(hst->current_state==HOST_DOWN && hst->flap_detection_on_down==FALSE) 00223 update_history=FALSE; 00224 if(hst->current_state==HOST_UNREACHABLE && hst->flap_detection_on_unreachable==FALSE) 00225 update_history=FALSE; 00226 } 00227 00228 /* if we didn't have an actual check, only update if we've waited long enough */ 00229 if(update_history==TRUE && actual_check==FALSE && (current_time-hst->last_state_history_update)<wait_threshold){ 00230 00231 update_history=FALSE; 00232 00233 } 00234 00235 /* what thresholds should we use (global or host-specific)? */ 00236 low_threshold=(hst->low_flap_threshold<=0.0)?low_host_flap_threshold:hst->low_flap_threshold; 00237 high_threshold=(hst->high_flap_threshold<=0.0)?high_host_flap_threshold:hst->high_flap_threshold; 00238 00239 /* record current host state */ 00240 if(update_history==TRUE){ 00241 00242 /* update the last record time */ 00243 hst->last_state_history_update=current_time; 00244 00245 /* record the current state in the state history */ 00246 hst->state_history[hst->state_history_index]=hst->current_state; 00247 00248 /* increment state history index to next available slot */ 00249 hst->state_history_index++; 00250 if(hst->state_history_index>=MAX_STATE_HISTORY_ENTRIES) 00251 hst->state_history_index=0; 00252 } 00253 00254 /* calculate overall changes in state */ 00255 for(x=0,y=hst->state_history_index;x<MAX_STATE_HISTORY_ENTRIES;x++){ 00256 00257 if(x==0){ 00258 last_state_history_value=hst->state_history[y]; 00259 y++; 00260 if(y>=MAX_STATE_HISTORY_ENTRIES) 00261 y=0; 00262 continue; 00263 } 00264 00265 if(last_state_history_value!=hst->state_history[y]) 00266 curved_changes+=(((double)(x-1)*(high_curve_value-low_curve_value))/((double)(MAX_STATE_HISTORY_ENTRIES-2)))+low_curve_value; 00267 00268 last_state_history_value=hst->state_history[y]; 00269 00270 y++; 00271 if(y>=MAX_STATE_HISTORY_ENTRIES) 00272 y=0; 00273 } 00274 00275 /* calculate overall percent change in state */ 00276 curved_percent_change=(double)(((double)curved_changes*100.0)/(double)(MAX_STATE_HISTORY_ENTRIES-1)); 00277 00278 hst->percent_state_change=curved_percent_change; 00279 00280 log_debug_info(DEBUGL_FLAPPING,2,"LFT=%.2f, HFT=%.2f, CPC=%.2f, PSC=%.2f%%\n",low_threshold,high_threshold,curved_percent_change,curved_percent_change); 00281 00282 00283 /* don't do anything if we don't have flap detection enabled on a program-wide basis */ 00284 if(enable_flap_detection==FALSE) 00285 return; 00286 00287 /* don't do anything if we don't have flap detection enabled for this host */ 00288 if(hst->flap_detection_enabled==FALSE) 00289 return; 00290 00291 /* are we flapping, undecided, or what?... */ 00292 00293 /* we're undecided, so don't change the current flap state */ 00294 if(curved_percent_change>low_threshold && curved_percent_change<high_threshold) 00295 return; 00296 00297 /* we're below the lower bound, so we're not flapping */ 00298 else if(curved_percent_change<=low_threshold) 00299 is_flapping=FALSE; 00300 00301 /* else we're above the upper bound, so we are flapping */ 00302 else if(curved_percent_change>=high_threshold) 00303 is_flapping=TRUE; 00304 00305 log_debug_info(DEBUGL_FLAPPING,1,"Host %s flapping (%.2f%% state change).\n",(is_flapping==TRUE)?"is":"is not",curved_percent_change); 00306 00307 /* did the host just start flapping? */ 00308 if(is_flapping==TRUE && hst->is_flapping==FALSE) 00309 set_host_flap(hst,curved_percent_change,high_threshold,low_threshold,allow_flapstart_notification); 00310 00311 /* did the host just stop flapping? */ 00312 else if(is_flapping==FALSE && hst->is_flapping==TRUE) 00313 clear_host_flap(hst,curved_percent_change,high_threshold,low_threshold); 00314 00315 return; 00316 } 00317 00318 00319 /******************************************************************/ 00320 /********************* FLAP HANDLING FUNCTIONS ********************/ 00321 /******************************************************************/ 00322 00323 00324 /* handles a service that is flapping */ 00325 void set_service_flap(service *svc, double percent_change, double high_threshold, double low_threshold, int allow_flapstart_notification){ 00326 char *temp_buffer=NULL; 00327 00328 log_debug_info(DEBUGL_FUNCTIONS,0,"set_service_flap()\n"); 00329 00330 if(svc==NULL) 00331 return; 00332 00333 log_debug_info(DEBUGL_FLAPPING,1,"Service '%s' on host '%s' started flapping!\n",svc->description,svc->host_name); 00334 00335 /* log a notice - this one is parsed by the history CGI */ 00336 logit(NSLOG_RUNTIME_WARNING,FALSE,"SERVICE FLAPPING ALERT: %s;%s;STARTED; Service appears to have started flapping (%2.1f%% change >= %2.1f%% threshold)\n",svc->host_name,svc->description,percent_change,high_threshold); 00337 00338 /* add a non-persistent comment to the service */ 00339 dummy=asprintf(&temp_buffer,"Notifications for this service are being suppressed because it was detected as having been flapping between different states (%2.1f%% change >= %2.1f%% threshold). When the service state stabilizes and the flapping stops, notifications will be re-enabled.",percent_change,high_threshold); 00340 add_new_service_comment(FLAPPING_COMMENT,svc->host_name,svc->description,time(NULL),"(Icinga Process)",temp_buffer,0,COMMENTSOURCE_INTERNAL,FALSE,(time_t)0,&(svc->flapping_comment_id)); 00341 my_free(temp_buffer); 00342 00343 /* set the flapping indicator */ 00344 svc->is_flapping=TRUE; 00345 00346 #ifdef USE_EVENT_BROKER 00347 /* send data to event broker */ 00348 broker_flapping_data(NEBTYPE_FLAPPING_START,NEBFLAG_NONE,NEBATTR_NONE,SERVICE_FLAPPING,svc,percent_change,high_threshold,low_threshold,NULL); 00349 #endif 00350 00351 /* see if we should check to send a recovery notification out when flapping stops */ 00352 if(svc->current_state!=STATE_OK && svc->current_notification_number>0) 00353 svc->check_flapping_recovery_notification=TRUE; 00354 else 00355 svc->check_flapping_recovery_notification=FALSE; 00356 00357 /* send a notification */ 00358 if(allow_flapstart_notification==TRUE) 00359 service_notification(svc,NOTIFICATION_FLAPPINGSTART,NULL,NULL,NOTIFICATION_OPTION_NONE); 00360 00361 return; 00362 } 00363 00364 00365 /* handles a service that has stopped flapping */ 00366 void clear_service_flap(service *svc, double percent_change, double high_threshold, double low_threshold){ 00367 00368 log_debug_info(DEBUGL_FUNCTIONS,0,"clear_service_flap()\n"); 00369 00370 if(svc==NULL) 00371 return; 00372 00373 log_debug_info(DEBUGL_FLAPPING,1,"Service '%s' on host '%s' stopped flapping.\n",svc->description,svc->host_name); 00374 00375 /* log a notice - this one is parsed by the history CGI */ 00376 logit(NSLOG_INFO_MESSAGE,FALSE,"SERVICE FLAPPING ALERT: %s;%s;STOPPED; Service appears to have stopped flapping (%2.1f%% change < %2.1f%% threshold)\n",svc->host_name,svc->description,percent_change,low_threshold); 00377 00378 /* delete the comment we added earlier */ 00379 if(svc->flapping_comment_id!=0) 00380 delete_service_comment(svc->flapping_comment_id); 00381 svc->flapping_comment_id=0; 00382 00383 /* clear the flapping indicator */ 00384 svc->is_flapping=FALSE; 00385 00386 #ifdef USE_EVENT_BROKER 00387 /* send data to event broker */ 00388 broker_flapping_data(NEBTYPE_FLAPPING_STOP,NEBFLAG_NONE,NEBATTR_FLAPPING_STOP_NORMAL,SERVICE_FLAPPING,svc,percent_change,high_threshold,low_threshold,NULL); 00389 #endif 00390 00391 /* send a notification */ 00392 service_notification(svc,NOTIFICATION_FLAPPINGSTOP,NULL,NULL,NOTIFICATION_OPTION_NONE); 00393 00394 /* should we send a recovery notification? */ 00395 if(svc->check_flapping_recovery_notification==TRUE && svc->current_state==STATE_OK) 00396 service_notification(svc,NOTIFICATION_NORMAL,NULL,NULL,NOTIFICATION_OPTION_NONE); 00397 00398 /* clear the recovery notification flag */ 00399 svc->check_flapping_recovery_notification=FALSE; 00400 00401 return; 00402 } 00403 00404 00405 /* handles a host that is flapping */ 00406 void set_host_flap(host *hst, double percent_change, double high_threshold, double low_threshold, int allow_flapstart_notification){ 00407 char *temp_buffer=NULL; 00408 00409 log_debug_info(DEBUGL_FUNCTIONS,0,"set_host_flap()\n"); 00410 00411 if(hst==NULL) 00412 return; 00413 00414 log_debug_info(DEBUGL_FLAPPING,1,"Host '%s' started flapping!\n",hst->name); 00415 00416 /* log a notice - this one is parsed by the history CGI */ 00417 logit(NSLOG_RUNTIME_WARNING,FALSE,"HOST FLAPPING ALERT: %s;STARTED; Host appears to have started flapping (%2.1f%% change > %2.1f%% threshold)\n",hst->name,percent_change,high_threshold); 00418 00419 /* add a non-persistent comment to the host */ 00420 dummy=asprintf(&temp_buffer,"Notifications for this host are being suppressed because it was detected as having been flapping between different states (%2.1f%% change > %2.1f%% threshold). When the host state stabilizes and the flapping stops, notifications will be re-enabled.",percent_change,high_threshold); 00421 add_new_host_comment(FLAPPING_COMMENT,hst->name,time(NULL),"(Icinga Process)",temp_buffer,0,COMMENTSOURCE_INTERNAL,FALSE,(time_t)0,&(hst->flapping_comment_id)); 00422 my_free(temp_buffer); 00423 00424 /* set the flapping indicator */ 00425 hst->is_flapping=TRUE; 00426 00427 #ifdef USE_EVENT_BROKER 00428 /* send data to event broker */ 00429 broker_flapping_data(NEBTYPE_FLAPPING_START,NEBFLAG_NONE,NEBATTR_NONE,HOST_FLAPPING,hst,percent_change,high_threshold,low_threshold,NULL); 00430 #endif 00431 00432 /* see if we should check to send a recovery notification out when flapping stops */ 00433 if(hst->current_state!=HOST_UP && hst->current_notification_number>0) 00434 hst->check_flapping_recovery_notification=TRUE; 00435 else 00436 hst->check_flapping_recovery_notification=FALSE; 00437 00438 /* send a notification */ 00439 if(allow_flapstart_notification==TRUE) 00440 host_notification(hst,NOTIFICATION_FLAPPINGSTART,NULL,NULL,NOTIFICATION_OPTION_NONE); 00441 00442 return; 00443 } 00444 00445 00446 /* handles a host that has stopped flapping */ 00447 void clear_host_flap(host *hst, double percent_change, double high_threshold, double low_threshold){ 00448 00449 log_debug_info(DEBUGL_FUNCTIONS,0,"clear_host_flap()\n"); 00450 00451 if(hst==NULL) 00452 return; 00453 00454 log_debug_info(DEBUGL_FLAPPING,1,"Host '%s' stopped flapping.\n",hst->name); 00455 00456 /* log a notice - this one is parsed by the history CGI */ 00457 logit(NSLOG_INFO_MESSAGE,FALSE,"HOST FLAPPING ALERT: %s;STOPPED; Host appears to have stopped flapping (%2.1f%% change < %2.1f%% threshold)\n",hst->name,percent_change,low_threshold); 00458 00459 /* delete the comment we added earlier */ 00460 if(hst->flapping_comment_id!=0) 00461 delete_host_comment(hst->flapping_comment_id); 00462 hst->flapping_comment_id=0; 00463 00464 /* clear the flapping indicator */ 00465 hst->is_flapping=FALSE; 00466 00467 #ifdef USE_EVENT_BROKER 00468 /* send data to event broker */ 00469 broker_flapping_data(NEBTYPE_FLAPPING_STOP,NEBFLAG_NONE,NEBATTR_FLAPPING_STOP_NORMAL,HOST_FLAPPING,hst,percent_change,high_threshold,low_threshold,NULL); 00470 #endif 00471 00472 /* send a notification */ 00473 host_notification(hst,NOTIFICATION_FLAPPINGSTOP,NULL,NULL,NOTIFICATION_OPTION_NONE); 00474 00475 /* should we send a recovery notification? */ 00476 if(hst->check_flapping_recovery_notification==TRUE && hst->current_state==HOST_UP) 00477 host_notification(hst,NOTIFICATION_NORMAL,NULL,NULL,NOTIFICATION_OPTION_NONE); 00478 00479 /* clear the recovery notification flag */ 00480 hst->check_flapping_recovery_notification=FALSE; 00481 00482 return; 00483 } 00484 00485 00486 00487 /******************************************************************/ 00488 /***************** FLAP DETECTION STATUS FUNCTIONS ****************/ 00489 /******************************************************************/ 00490 00491 /* enables flap detection on a program wide basis */ 00492 void enable_flap_detection_routines(void){ 00493 host *temp_host=NULL; 00494 service *temp_service=NULL; 00495 unsigned long attr=MODATTR_FLAP_DETECTION_ENABLED; 00496 00497 log_debug_info(DEBUGL_FUNCTIONS,0,"enable_flap_detection_routines()\n"); 00498 00499 /* bail out if we're already set */ 00500 if(enable_flap_detection==TRUE) 00501 return; 00502 00503 /* set the attribute modified flag */ 00504 modified_host_process_attributes|=attr; 00505 modified_service_process_attributes|=attr; 00506 00507 /* set flap detection flag */ 00508 enable_flap_detection=TRUE; 00509 00510 #ifdef USE_EVENT_BROKER 00511 /* send data to event broker */ 00512 broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL); 00513 #endif 00514 00515 /* update program status */ 00516 update_program_status(FALSE); 00517 00518 /* check for flapping */ 00519 for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next) 00520 check_for_host_flapping(temp_host,FALSE,FALSE,TRUE); 00521 for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next) 00522 check_for_service_flapping(temp_service,FALSE,TRUE); 00523 00524 return; 00525 } 00526 00527 00528 00529 /* disables flap detection on a program wide basis */ 00530 void disable_flap_detection_routines(void){ 00531 host *temp_host=NULL; 00532 service *temp_service=NULL; 00533 unsigned long attr=MODATTR_FLAP_DETECTION_ENABLED; 00534 00535 log_debug_info(DEBUGL_FUNCTIONS,0,"disable_flap_detection_routines()\n"); 00536 00537 /* bail out if we're already set */ 00538 if(enable_flap_detection==FALSE) 00539 return; 00540 00541 /* set the attribute modified flag */ 00542 modified_host_process_attributes|=attr; 00543 modified_service_process_attributes|=attr; 00544 00545 /* set flap detection flag */ 00546 enable_flap_detection=FALSE; 00547 00548 #ifdef USE_EVENT_BROKER 00549 /* send data to event broker */ 00550 broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL); 00551 #endif 00552 00553 /* update program status */ 00554 update_program_status(FALSE); 00555 00556 /* handle the details... */ 00557 for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next) 00558 handle_host_flap_detection_disabled(temp_host); 00559 for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next) 00560 handle_service_flap_detection_disabled(temp_service); 00561 00562 return; 00563 } 00564 00565 00566 00567 /* enables flap detection for a specific host */ 00568 void enable_host_flap_detection(host *hst){ 00569 unsigned long attr=MODATTR_FLAP_DETECTION_ENABLED; 00570 00571 log_debug_info(DEBUGL_FUNCTIONS,0,"enable_host_flap_detection()\n"); 00572 00573 if(hst==NULL) 00574 return; 00575 00576 log_debug_info(DEBUGL_FLAPPING,1,"Enabling flap detection for host '%s'.\n",hst->name); 00577 00578 /* nothing to do... */ 00579 if(hst->flap_detection_enabled==TRUE) 00580 return; 00581 00582 /* set the attribute modified flag */ 00583 hst->modified_attributes|=attr; 00584 00585 /* set the flap detection enabled flag */ 00586 hst->flap_detection_enabled=TRUE; 00587 00588 #ifdef USE_EVENT_BROKER 00589 /* send data to event broker */ 00590 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL); 00591 #endif 00592 00593 /* check for flapping */ 00594 check_for_host_flapping(hst,FALSE,FALSE,TRUE); 00595 00596 /* update host status */ 00597 update_host_status(hst,FALSE); 00598 00599 return; 00600 } 00601 00602 00603 00604 /* disables flap detection for a specific host */ 00605 void disable_host_flap_detection(host *hst){ 00606 unsigned long attr=MODATTR_FLAP_DETECTION_ENABLED; 00607 00608 log_debug_info(DEBUGL_FUNCTIONS,0,"disable_host_flap_detection()\n"); 00609 00610 if(hst==NULL) 00611 return; 00612 00613 log_debug_info(DEBUGL_FLAPPING,1,"Disabling flap detection for host '%s'.\n",hst->name); 00614 00615 /* nothing to do... */ 00616 if(hst->flap_detection_enabled==FALSE) 00617 return; 00618 00619 /* set the attribute modified flag */ 00620 hst->modified_attributes|=attr; 00621 00622 /* set the flap detection enabled flag */ 00623 hst->flap_detection_enabled=FALSE; 00624 00625 #ifdef USE_EVENT_BROKER 00626 /* send data to event broker */ 00627 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL); 00628 #endif 00629 00630 /* handle the details... */ 00631 handle_host_flap_detection_disabled(hst); 00632 00633 return; 00634 } 00635 00636 00637 /* handles the details for a host when flap detection is disabled (globally or per-host) */ 00638 void handle_host_flap_detection_disabled(host *hst){ 00639 00640 log_debug_info(DEBUGL_FUNCTIONS,0,"handle_host_flap_detection_disabled()\n"); 00641 00642 if(hst==NULL) 00643 return; 00644 00645 /* if the host was flapping, remove the flapping indicator */ 00646 if(hst->is_flapping==TRUE){ 00647 00648 hst->is_flapping=FALSE; 00649 00650 /* delete the original comment we added earlier */ 00651 if(hst->flapping_comment_id!=0) 00652 delete_host_comment(hst->flapping_comment_id); 00653 hst->flapping_comment_id=0; 00654 00655 /* log a notice - this one is parsed by the history CGI */ 00656 logit(NSLOG_INFO_MESSAGE,FALSE,"HOST FLAPPING ALERT: %s;DISABLED; Flap detection has been disabled\n",hst->name); 00657 00658 #ifdef USE_EVENT_BROKER 00659 /* send data to event broker */ 00660 broker_flapping_data(NEBTYPE_FLAPPING_STOP,NEBFLAG_NONE,NEBATTR_FLAPPING_STOP_DISABLED,HOST_FLAPPING,hst,hst->percent_state_change,0.0,0.0,NULL); 00661 #endif 00662 00663 /* send a notification */ 00664 host_notification(hst,NOTIFICATION_FLAPPINGDISABLED,NULL,NULL,NOTIFICATION_OPTION_NONE); 00665 00666 /* should we send a recovery notification? */ 00667 if(hst->check_flapping_recovery_notification==TRUE && hst->current_state==HOST_UP) 00668 host_notification(hst,NOTIFICATION_NORMAL,NULL,NULL,NOTIFICATION_OPTION_NONE); 00669 00670 /* clear the recovery notification flag */ 00671 hst->check_flapping_recovery_notification=FALSE; 00672 } 00673 00674 /* update host status */ 00675 update_host_status(hst,FALSE); 00676 00677 return; 00678 } 00679 00680 00681 /* enables flap detection for a specific service */ 00682 void enable_service_flap_detection(service *svc){ 00683 unsigned long attr=MODATTR_FLAP_DETECTION_ENABLED; 00684 00685 log_debug_info(DEBUGL_FUNCTIONS,0,"enable_service_flap_detection()\n"); 00686 00687 if(svc==NULL) 00688 return; 00689 00690 log_debug_info(DEBUGL_FLAPPING,1,"Enabling flap detection for service '%s' on host '%s'.\n",svc->description,svc->host_name); 00691 00692 /* nothing to do... */ 00693 if(svc->flap_detection_enabled==TRUE) 00694 return; 00695 00696 /* set the attribute modified flag */ 00697 svc->modified_attributes|=attr; 00698 00699 /* set the flap detection enabled flag */ 00700 svc->flap_detection_enabled=TRUE; 00701 00702 #ifdef USE_EVENT_BROKER 00703 /* send data to event broker */ 00704 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL); 00705 #endif 00706 00707 /* check for flapping */ 00708 check_for_service_flapping(svc,FALSE,TRUE); 00709 00710 /* update service status */ 00711 update_service_status(svc,FALSE); 00712 00713 return; 00714 } 00715 00716 00717 00718 /* disables flap detection for a specific service */ 00719 void disable_service_flap_detection(service *svc){ 00720 unsigned long attr=MODATTR_FLAP_DETECTION_ENABLED; 00721 00722 log_debug_info(DEBUGL_FUNCTIONS,0,"disable_service_flap_detection()\n"); 00723 00724 if(svc==NULL) 00725 return; 00726 00727 log_debug_info(DEBUGL_FLAPPING,1,"Disabling flap detection for service '%s' on host '%s'.\n",svc->description,svc->host_name); 00728 00729 /* nothing to do... */ 00730 if(svc->flap_detection_enabled==FALSE) 00731 return; 00732 00733 /* set the attribute modified flag */ 00734 svc->modified_attributes|=attr; 00735 00736 /* set the flap detection enabled flag */ 00737 svc->flap_detection_enabled=FALSE; 00738 00739 #ifdef USE_EVENT_BROKER 00740 /* send data to event broker */ 00741 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL); 00742 #endif 00743 00744 /* handle the details... */ 00745 handle_service_flap_detection_disabled(svc); 00746 00747 return; 00748 } 00749 00750 00751 /* handles the details for a service when flap detection is disabled (globally or per-service) */ 00752 void handle_service_flap_detection_disabled(service *svc){ 00753 00754 log_debug_info(DEBUGL_FUNCTIONS,0,"handle_service_flap_detection_disabled()\n"); 00755 00756 if(svc==NULL) 00757 return; 00758 00759 /* if the service was flapping, remove the flapping indicator */ 00760 if(svc->is_flapping==TRUE){ 00761 00762 svc->is_flapping=FALSE; 00763 00764 /* delete the original comment we added earlier */ 00765 if(svc->flapping_comment_id!=0) 00766 delete_service_comment(svc->flapping_comment_id); 00767 svc->flapping_comment_id=0; 00768 00769 /* log a notice - this one is parsed by the history CGI */ 00770 logit(NSLOG_INFO_MESSAGE,FALSE,"SERVICE FLAPPING ALERT: %s;%s;DISABLED; Flap detection has been disabled\n",svc->host_name,svc->description); 00771 00772 #ifdef USE_EVENT_BROKER 00773 /* send data to event broker */ 00774 broker_flapping_data(NEBTYPE_FLAPPING_STOP,NEBFLAG_NONE,NEBATTR_FLAPPING_STOP_DISABLED,SERVICE_FLAPPING,svc,svc->percent_state_change,0.0,0.0,NULL); 00775 #endif 00776 00777 /* send a notification */ 00778 service_notification(svc,NOTIFICATION_FLAPPINGDISABLED,NULL,NULL,NOTIFICATION_OPTION_NONE); 00779 00780 /* should we send a recovery notification? */ 00781 if(svc->check_flapping_recovery_notification==TRUE && svc->current_state==STATE_OK) 00782 service_notification(svc,NOTIFICATION_NORMAL,NULL,NULL,NOTIFICATION_OPTION_NONE); 00783 00784 /* clear the recovery notification flag */ 00785 svc->check_flapping_recovery_notification=FALSE; 00786 } 00787 00788 /* update service status */ 00789 update_service_status(svc,FALSE); 00790 00791 return; 00792 } 00793 00794 00795 00796 00797