/* handles a host that is flapping */ void set_host_flap(host *hst, double percent_change, double high_threshold, double low_threshold) { char *temp_buffer = NULL; if (hst == NULL) return; log_debug_info(DEBUGL_FLAPPING, 1, "Host '%s' started flapping!\n", hst->name); /* log a notice - this one is parsed by the history CGI */ nm_log(NSLOG_RUNTIME_WARNING, "HOST FLAPPING ALERT: %s;STARTED; Host appears to have started flapping (%2.1f%% change > %2.1f%% threshold)\n", hst->name, percent_change, high_threshold); /* add a non-persistent comment to the host */ nm_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); add_new_host_comment(FLAPPING_COMMENT, hst->name, time(NULL), "(Naemon Process)", temp_buffer, 0, COMMENTSOURCE_INTERNAL, FALSE, (time_t)0, &(hst->flapping_comment_id)); nm_free(temp_buffer); /* set the flapping indicator */ hst->is_flapping = TRUE; broker_flapping_data(NEBTYPE_FLAPPING_START, NEBFLAG_NONE, NEBATTR_NONE, HOST_FLAPPING, hst, percent_change, high_threshold, low_threshold); /* see if we should check to send a recovery notification out when flapping stops */ if (hst->current_state != STATE_UP && hst->current_notification_number > 0) hst->check_flapping_recovery_notification = TRUE; else hst->check_flapping_recovery_notification = FALSE; /* send a notification */ host_notification(hst, NOTIFICATION_FLAPPINGSTART, NULL, NULL, NOTIFICATION_OPTION_NONE); return; }
/* adds a new host or service comment */ int add_new_comment(int type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) { int result; unsigned long new_comment_id = 0L; if(type == HOST_COMMENT) result = add_new_host_comment(entry_type, host_name, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id); else result = add_new_service_comment(entry_type, host_name, svc_description, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id); /* add an event to expire comment data if necessary... */ if(expires == TRUE) schedule_new_event(EVENT_EXPIRE_COMMENT, FALSE, expire_time, FALSE, 0, NULL, TRUE, (void *)new_comment_id, NULL, 0); /* save comment id */ if(comment_id != NULL) *comment_id = new_comment_id; return result; }
/* handles a host that is flapping */ void set_host_flap(host *hst, double percent_change, double high_threshold, double low_threshold, int allow_flapstart_notification) { char *temp_buffer = NULL; log_debug_info(DEBUGL_FUNCTIONS, 0, "set_host_flap()\n"); if (hst == NULL) return; log_debug_info(DEBUGL_FLAPPING, 1, "主机 '%s' 已开始抖动!\n", hst->name); /* log a notice - this one is parsed by the history CGI */ logit(NSLOG_RUNTIME_WARNING, FALSE, "主机抖动警告: %s;开始; 主机似乎已经开始抖动 (%2.1f%% 变化 > %2.1f%% 阙值)\n", hst->name, percent_change, high_threshold); /* add a non-persistent comment to the host */ 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); 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)); my_free(temp_buffer); /* set the flapping indicator */ hst->is_flapping = TRUE; #ifdef USE_EVENT_BROKER /* send data to event broker */ broker_flapping_data(NEBTYPE_FLAPPING_START, NEBFLAG_NONE, NEBATTR_NONE, HOST_FLAPPING, hst, percent_change, high_threshold, low_threshold, NULL); #endif /* see if we should check to send a recovery notification out when flapping stops */ if (hst->current_state != HOST_UP && hst->current_notification_number > 0) hst->check_flapping_recovery_notification = TRUE; else hst->check_flapping_recovery_notification = FALSE; /* send a notification */ if (allow_flapstart_notification == TRUE) host_notification(hst, NOTIFICATION_FLAPPINGSTART, NULL, NULL, NOTIFICATION_OPTION_NONE); return; }