Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'stalking_notify' logic for both Host and Service based objects #981

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions base/checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,9 @@ int handle_async_service_check_result(service *svc, check_result *cr)
svc->current_problem_id = 0L;
}

/* initialize notification type for sending service notifications */
int notification_type = NOTIFICATION_NORMAL;

/* volatile service gets everything in non-ok hard state */
if ((svc->current_state != STATE_OK)
&& (svc->state_type == HARD_STATE)
Expand All @@ -1590,10 +1593,23 @@ int handle_async_service_check_result(service *svc, check_result *cr)
handle_event = TRUE;
}

/* if we're stalking this state type AND the plugin output changed since last check, log it now.. */
if (should_stalk(svc) && compare_strings(old_plugin_output, svc->plugin_output)) {
log_debug_info(DEBUGL_CHECKS, 2, "Logging due to state stalking, old: [%s], new: [%s]\n", old_plugin_output, svc->plugin_output);
log_event = TRUE;

if (svc->stalking_notify == TRUE && svc->state_type == HARD_STATE) {
send_notification = TRUE;
notification_type = NOTIFICATION_STALKING;
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Notifying due to state stalking, old: [%s], new: [%s]\n", old_plugin_output, svc->plugin_output);
}
}


if (send_notification == TRUE) {

/* send notification */
if (service_notification(svc, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE) == OK) {
if (service_notification(svc, notification_type, NULL, NULL, NOTIFICATION_OPTION_NONE) == OK) {

/* log state due to notification event when stalking_options N is set */
if (should_stalk_notifications(svc)) {
Expand All @@ -1612,13 +1628,6 @@ int handle_async_service_check_result(service *svc, check_result *cr)
obsessive_compulsive_service_check_processor(svc);
}

/* if we're stalking this state type AND the plugin output changed since last check, log it now.. */
if (should_stalk(svc) && compare_strings(old_plugin_output, svc->plugin_output)) {

log_debug_info(DEBUGL_CHECKS, 2, "Logging due to state stalking, old: [%s], new: [%s]\n", old_plugin_output, svc->plugin_output);
log_event = TRUE;
}

if (log_event == TRUE) {
log_service_event(svc);
}
Expand Down Expand Up @@ -2481,10 +2490,23 @@ int handle_async_host_check_result(host *hst, check_result *cr)
hst->current_attempt = 1;
}

/* initialize notification type for sending host notifications */
int notification_type = NOTIFICATION_NORMAL;

/* if we're stalking this state type AND the plugin output changed since last check, log it now.. */
if (should_stalk(hst) && compare_strings(old_plugin_output, hst->plugin_output)) {
log_event = TRUE;

if (hst->stalking_notify == TRUE && hst->state_type == HARD_STATE) {
send_notification = TRUE;
notification_type = NOTIFICATION_STALKING;
}
}

if (send_notification == TRUE) {

/* send notifications */
if (host_notification(hst, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE) == OK) {
if (host_notification(hst, notification_type, NULL, NULL, NOTIFICATION_OPTION_NONE) == OK) {

/* log state due to notification event when stalking_options N is set */
if (should_stalk_notifications(hst)) {
Expand All @@ -2503,11 +2525,6 @@ int handle_async_host_check_result(host *hst, check_result *cr)
obsessive_compulsive_host_check_processor(hst);
}

/* if we're stalking this state type AND the plugin output changed since last check, log it now.. */
if (should_stalk(hst) && compare_strings(old_plugin_output, hst->plugin_output)) {
log_event = TRUE;
}

/* if log_host_retries is set to true, we have to log soft states too */
if (hst->state_type == SOFT_STATE && log_host_retries == TRUE) {
log_event = TRUE;
Expand Down
33 changes: 24 additions & 9 deletions base/notifications.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat
log_debug_info(DEBUGL_NOTIFICATIONS, 0, "Notification viability test passed.\n");

/* should the notification number be increased? */
if(type == NOTIFICATION_NORMAL || (options & NOTIFICATION_OPTION_INCREMENT)) {
if((type == NOTIFICATION_NORMAL || type == NOTIFICATION_STALKING) || (options & NOTIFICATION_OPTION_INCREMENT)) {
svc->current_notification_number++;
increment_notification_number = TRUE;
}
Expand Down Expand Up @@ -276,7 +276,7 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat
clear_servicegroup_macros_r(&mac);
clear_datetime_macros_r(&mac);

if(type == NOTIFICATION_NORMAL) {
if(type == NOTIFICATION_NORMAL || type == NOTIFICATION_STALKING) {

/* adjust last/next notification time and notification flags if we notified someone */
if(contacts_notified > 0) {
Expand Down Expand Up @@ -392,6 +392,14 @@ int check_service_notification_viability(service *svc, int type, int options) {
temp_period = svc->host_ptr->notification_period_ptr;
}

/* if service should stalk and has stalking notify enabled, bypass next notification schedule */
int stalk_notify = FALSE;
if(type == NOTIFICATION_STALKING) {
svc->next_notification = (time_t)0;
type = NOTIFICATION_NORMAL;
stalk_notify = TRUE;
}

/* see if the service can have notifications sent out at this time */
if(check_time_against_period(current_time, temp_period) == ERROR) {

Expand Down Expand Up @@ -591,8 +599,8 @@ int check_service_notification_viability(service *svc, int type, int options) {
return ERROR;
}

/* don't notify contacts about this service problem again if the notification interval is set to 0 */
if(svc->no_more_notifications == TRUE) {
/* don't notify contacts about this service problem again if not stalking and the notification interval is set to 0 */
if(stalk_notify == FALSE && svc->no_more_notifications == TRUE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't re-notify contacts about this service problem.\n");
return ERROR;
}
Expand Down Expand Up @@ -1072,7 +1080,7 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int
log_debug_info(DEBUGL_NOTIFICATIONS, 0, "Notification viability test passed.\n");

/* should the notification number be increased? */
if(type == NOTIFICATION_NORMAL || (options & NOTIFICATION_OPTION_INCREMENT)) {
if((type == NOTIFICATION_NORMAL || type == NOTIFICATION_STALKING) || (options & NOTIFICATION_OPTION_INCREMENT)) {
hst->current_notification_number++;
increment_notification_number = TRUE;
}
Expand Down Expand Up @@ -1233,7 +1241,7 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int
clear_hostgroup_macros_r(&mac);
clear_datetime_macros_r(&mac);

if(type == NOTIFICATION_NORMAL) {
if(type == NOTIFICATION_NORMAL || type == NOTIFICATION_STALKING) {

/* adjust last/next notification time and notification flags if we notified someone */
if(contacts_notified > 0) {
Expand Down Expand Up @@ -1291,7 +1299,6 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int
}



/* checks viability of sending a host notification */
int check_host_notification_viability(host *hst, int type, int options) {
time_t current_time;
Expand All @@ -1314,12 +1321,20 @@ int check_host_notification_viability(host *hst, int type, int options) {
return ERROR;
}

/* if host should stalk and has stalking notify enabled, bypass next notification schedule */
int stalk_notify = FALSE;
if(type == NOTIFICATION_STALKING) {
hst->next_notification = (time_t)0;
type = NOTIFICATION_NORMAL;
stalk_notify = TRUE;
}

/* see if the host can have notifications sent out at this time */
if(check_time_against_period(current_time, hst->notification_period_ptr) == ERROR) {

log_debug_info(DEBUGL_NOTIFICATIONS, 1, "This host shouldn't have notifications sent out at this time.\n");

/* if this is a normal notification, calculate the next acceptable notification time, once the next valid time range arrives... */
/* if this is either a normal or a stalking notification, calculate the next acceptable notification time, once the next valid time range arrives... */
if(type == NOTIFICATION_NORMAL) {

get_next_valid_time(current_time, &timeperiod_start, hst->notification_period_ptr);
Expand Down Expand Up @@ -1498,7 +1513,7 @@ int check_host_notification_viability(host *hst, int type, int options) {
}

/* check if we shouldn't renotify contacts about the host problem */
if(hst->no_more_notifications == TRUE) {
if(stalk_notify == FALSE && hst->no_more_notifications == TRUE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't re-notify contacts about this host problem.\n");
return ERROR;
}
Expand Down
10 changes: 10 additions & 0 deletions cgi/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ void display_hosts(void) {
printf("<TH CLASS='data'>Event Handler Period</TH>");
printf("<TH CLASS='data'>Enable Event Handler</TH>");
printf("<TH CLASS='data'>Stalking Options</TH>\n");
printf("<TH CLASS='data'>Stalking Notify</TH>\n");
printf("<TH CLASS='data'>Enable Flap Detection</TH>");
printf("<TH CLASS='data'>Low Flap Threshold</TH>");
printf("<TH CLASS='data'>High Flap Threshold</TH>");
Expand Down Expand Up @@ -651,6 +652,10 @@ void display_hosts(void) {
printf("None");
printf("</TD>\n");

printf("<TD CLASS='%s'>", bg_class);
printf("%s\n", (temp_host->stalking_notify == TRUE) ? "Yes" : "No");
printf("</TD>\n");

printf("<TD CLASS='%s'>", bg_class);
printf("%s\n", (temp_host->flap_detection_enabled == TRUE) ? "Yes" : "No");
printf("</TD>\n");
Expand Down Expand Up @@ -1213,6 +1218,7 @@ void display_services(void) {
printf("<TH CLASS='data'>Event Handler Period</TH>");
printf("<TH CLASS='data'>Enable Event Handler</TH>");
printf("<TH CLASS='data'>Stalking Options</TH>\n");
printf("<TH CLASS='data'>Stalking Notify</TH>\n");
printf("<TH CLASS='data'>Enable Flap Detection</TH>");
printf("<TH CLASS='data'>Low Flap Threshold</TH>");
printf("<TH CLASS='data'>High Flap Threshold</TH>");
Expand Down Expand Up @@ -1397,6 +1403,10 @@ void display_services(void) {
printf("None");
printf("</TD>\n");

printf("<TD CLASS='%s'>", bg_class);
printf("%s\n", (temp_service->stalking_notify == TRUE) ? "Yes" : "No");
printf("</TD>\n");

printf("<TD CLASS='%s'>", bg_class);
printf("%s\n", (temp_service->flap_detection_enabled == TRUE) ? "Yes" : "No");
printf("</TD>\n");
Expand Down
4 changes: 4 additions & 0 deletions cgi/objectjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -2871,6 +2871,8 @@ void json_object_host_details(json_object *json_details, unsigned format_options
#endif
json_bitmask(json_details, format_options, "stalking_options",
temp_host->stalking_options, svm_option_types);
json_object_append_boolean(json_details, "stalking_notify",
temp_host->stalking_notify);
#if 0
}
#endif
Expand Down Expand Up @@ -3720,6 +3722,8 @@ void json_object_service_details(json_object *json_details,
#endif
json_bitmask(json_details, format_options, "stalking_options",
temp_service->stalking_options, svm_option_types);
json_object_append_boolean(json_details, "stalking_notify",
temp_service->stalking_notify);
#if 0
}
#endif
Expand Down
8 changes: 6 additions & 2 deletions common/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ timerange *add_timerange_to_daterange(daterange *drange, unsigned long start_tim


/* add a new host definition */
host *add_host(char *name, char *display_name, char *alias, char *address, char *check_period, int initial_state, double check_interval, double retry_interval, int max_attempts, int notification_options, double notification_interval, double first_notification_delay, char *notification_period, int notifications_enabled, char *check_command, int checks_enabled, int accept_passive_checks, char *event_handler, int event_handler_enabled, char *event_handler_period, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_options, int stalking_options, int process_perfdata, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, char *vrml_image, char *statusmap_image, int x_2d, int y_2d, int have_2d_coords, double x_3d, double y_3d, double z_3d, int have_3d_coords, int should_be_drawn, int retain_status_information, int retain_nonstatus_information, int obsess, unsigned int hourly_value) {
host *add_host(char *name, char *display_name, char *alias, char *address, char *check_period, int initial_state, double check_interval, double retry_interval, int max_attempts, int notification_options, double notification_interval, double first_notification_delay, char *notification_period, int notifications_enabled, char *check_command, int checks_enabled, int accept_passive_checks, char *event_handler, int event_handler_enabled, char *event_handler_period, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_options, int stalking_options, int stalking_notify, int process_perfdata, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, char *vrml_image, char *statusmap_image, int x_2d, int y_2d, int have_2d_coords, double x_3d, double y_3d, double z_3d, int have_3d_coords, int should_be_drawn, int retain_status_information, int retain_nonstatus_information, int obsess, unsigned int hourly_value) {
host *new_host = NULL;
timeperiod *check_tp = NULL, *notify_tp = NULL, *event_handler_tp = NULL;
int result = OK;
Expand Down Expand Up @@ -684,6 +684,7 @@ host *add_host(char *name, char *display_name, char *alias, char *address, char
new_host->high_flap_threshold = high_flap_threshold;
new_host->flap_detection_options = flap_detection_options;
new_host->stalking_options = stalking_options;
new_host->stalking_notify = (stalking_notify > 0) ? TRUE : FALSE;
new_host->process_performance_data = (process_perfdata > 0) ? TRUE : FALSE;
new_host->check_freshness = (check_freshness > 0) ? TRUE : FALSE;
new_host->freshness_threshold = freshness_threshold;
Expand Down Expand Up @@ -1432,7 +1433,7 @@ contactsmember *add_contact_to_contactgroup(contactgroup *grp, char *contact_nam


/* add a new service to the list in memory */
service *add_service(char *host_name, char *description, char *display_name, char *check_period, int initial_state, int max_attempts, int parallelize, int accept_passive_checks, double check_interval, double retry_interval, double notification_interval, double first_notification_delay, char *notification_period, int notification_options, int notifications_enabled, int is_volatile, char *event_handler, int event_handler_enabled, char *event_handler_period, char *check_command, int checks_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_options, int stalking_options, int process_perfdata, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, int retain_status_information, int retain_nonstatus_information, int obsess, unsigned int hourly_value) {
service *add_service(char *host_name, char *description, char *display_name, char *check_period, int initial_state, int max_attempts, int parallelize, int accept_passive_checks, double check_interval, double retry_interval, double notification_interval, double first_notification_delay, char *notification_period, int notification_options, int notifications_enabled, int is_volatile, char *event_handler, int event_handler_enabled, char *event_handler_period, char *check_command, int checks_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_options, int stalking_options, int stalking_notify, int process_perfdata, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, int retain_status_information, int retain_nonstatus_information, int obsess, unsigned int hourly_value) {
host *h;
timeperiod *cp = NULL, *np = NULL, *ep = NULL;
service *new_service = NULL;
Expand Down Expand Up @@ -1539,6 +1540,7 @@ service *add_service(char *host_name, char *description, char *display_name, cha
new_service->high_flap_threshold = high_flap_threshold;
new_service->flap_detection_options = flap_detection_options;
new_service->stalking_options = stalking_options;
new_service->stalking_notify = (stalking_notify > 0) ? TRUE : FALSE;
new_service->process_performance_data = (process_perfdata > 0) ? TRUE : FALSE;
new_service->check_freshness = (check_freshness > 0) ? TRUE : FALSE;
new_service->freshness_threshold = freshness_threshold;
Expand Down Expand Up @@ -3302,6 +3304,7 @@ void fcache_host(FILE *fp, host *temp_host)
fprintf(fp, "\tnotification_interval\t%f\n", temp_host->notification_interval);
fprintf(fp, "\tfirst_notification_delay\t%f\n", temp_host->first_notification_delay);
fprintf(fp, "\tstalking_options\t%s\n", opts2str(temp_host->stalking_options, host_flag_map, 'u'));
fprintf(fp, "\tstalking_notify\t%d\n", temp_host->stalking_notify);
fprintf(fp, "\tprocess_perf_data\t%d\n", temp_host->process_performance_data);
if(temp_host->icon_image)
fprintf(fp, "\ticon_image\t%s \n", temp_host->icon_image);
Expand Down Expand Up @@ -3390,6 +3393,7 @@ void fcache_service(FILE *fp, service *temp_service)
fprintf(fp, "\tnotification_interval\t%f\n", temp_service->notification_interval);
fprintf(fp, "\tfirst_notification_delay\t%f\n", temp_service->first_notification_delay);
fprintf(fp, "\tstalking_options\t%s\n", opts2str(temp_service->stalking_options, service_flag_map, 'o'));
fprintf(fp, "\tstalking_notify\t%d\n", temp_service->stalking_notify);
fprintf(fp, "\tprocess_perf_data\t%d\n", temp_service->process_performance_data);
if(temp_service->icon_image)
fprintf(fp, "\ticon_image\t%s \n", temp_service->icon_image);
Expand Down
2 changes: 1 addition & 1 deletion include/nagios.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ extern struct load_control loadctl;
#define NOTIFICATION_DOWNTIMEEND 6
#define NOTIFICATION_DOWNTIMECANCELLED 7
#define NOTIFICATION_CUSTOM 8

#define NOTIFICATION_STALKING 9


/**************** EVENT HANDLER TYPES *****************/
Expand Down
Loading