From: <est...@us...> - 2013-02-09 23:55:55
|
Revision: 2600 http://nagios.svn.sourceforge.net/nagios/?rev=2600&view=rev Author: estanley375 Date: 2013-02-09 23:55:47 +0000 (Sat, 09 Feb 2013) Log Message: ----------- Fixed bug #418: Scheduled Downtime Notifications Resent On Nagios Restart/reload This was accomplished by adding a member to the downtime structure which records whether the start-of-downwtime notification has been sent. This is also recorded in the status.dat and retention.dat files, the latter so it can be read back in on Nagios restart. Modified Paths: -------------- nagioscore/branches/nagios-3-4-x/common/downtime.c nagioscore/branches/nagios-3-4-x/include/downtime.h nagioscore/branches/nagios-3-4-x/xdata/xdddefault.c nagioscore/branches/nagios-3-4-x/xdata/xdddefault.h nagioscore/branches/nagios-3-4-x/xdata/xrddefault.c nagioscore/branches/nagios-3-4-x/xdata/xsddefault.c Modified: nagioscore/branches/nagios-3-4-x/common/downtime.c =================================================================== --- nagioscore/branches/nagios-3-4-x/common/downtime.c 2013-02-06 16:12:21 UTC (rev 2599) +++ nagioscore/branches/nagios-3-4-x/common/downtime.c 2013-02-09 23:55:47 UTC (rev 2600) @@ -116,7 +116,7 @@ /* add a new downtime entry */ - add_new_downtime(type, host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &downtime_id, FALSE); + add_new_downtime(type, host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &downtime_id, FALSE, FALSE); /* register the scheduled downtime */ register_downtime(type, downtime_id); @@ -542,7 +542,10 @@ logit(NSLOG_INFO_MESSAGE, FALSE, "HOST DOWNTIME ALERT: %s;STARTED; Host has entered a period of scheduled downtime", hst->name); /* send a notification */ - host_notification(hst, NOTIFICATION_DOWNTIMESTART, temp_downtime->author, temp_downtime->comment, NOTIFICATION_OPTION_NONE); + if( FALSE == temp_downtime->start_notification_sent) { + host_notification(hst, NOTIFICATION_DOWNTIMESTART, temp_downtime->author, temp_downtime->comment, NOTIFICATION_OPTION_NONE); + temp_downtime->start_notification_sent = TRUE; + } } else if(temp_downtime->type == SERVICE_DOWNTIME && svc->scheduled_downtime_depth == 0) { @@ -553,7 +556,10 @@ logit(NSLOG_INFO_MESSAGE, FALSE, "SERVICE DOWNTIME ALERT: %s;%s;STARTED; Service has entered a period of scheduled downtime", svc->host_name, svc->description); /* send a notification */ - service_notification(svc, NOTIFICATION_DOWNTIMESTART, temp_downtime->author, temp_downtime->comment, NOTIFICATION_OPTION_NONE); + if( FALSE == temp_downtime->start_notification_sent) { + service_notification(svc, NOTIFICATION_DOWNTIMESTART, temp_downtime->author, temp_downtime->comment, NOTIFICATION_OPTION_NONE); + temp_downtime->start_notification_sent = TRUE; + } } /* increment the downtime depth variable */ @@ -746,20 +752,20 @@ /* save a host or service downtime */ -int add_new_downtime(int type, char *host_name, char *service_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id,int is_in_effect){ +int add_new_downtime(int type, char *host_name, char *service_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, int start_notification_sent){ int result = OK; if(type == HOST_DOWNTIME) - result = add_new_host_downtime(host_name, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect); + result = add_new_host_downtime(host_name, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, start_notification_sent); else - result = add_new_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect); + result = add_new_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, start_notification_sent); return result; } /* saves a host downtime entry */ -int add_new_host_downtime(char *host_name, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect){ +int add_new_host_downtime(char *host_name, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, int start_notification_sent){ int result = OK; unsigned long new_downtime_id = 0L; @@ -768,7 +774,7 @@ /**** IMPLEMENTATION-SPECIFIC CALLS ****/ #ifdef USE_XDDDEFAULT - result = xdddefault_add_new_host_downtime(host_name, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &new_downtime_id, is_in_effect); + result = xdddefault_add_new_host_downtime(host_name, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &new_downtime_id, is_in_effect, start_notification_sent); #endif /* save downtime id */ @@ -785,7 +791,7 @@ /* saves a service downtime entry */ -int add_new_service_downtime(char *host_name, char *service_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect){ +int add_new_service_downtime(char *host_name, char *service_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, int start_notification_sent){ int result = OK; unsigned long new_downtime_id = 0L; @@ -794,7 +800,7 @@ /**** IMPLEMENTATION-SPECIFIC CALLS ****/ #ifdef USE_XDDDEFAULT - result = xdddefault_add_new_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &new_downtime_id, is_in_effect); + result = xdddefault_add_new_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &new_downtime_id, is_in_effect, start_notification_sent); #endif /* save downtime id */ @@ -959,27 +965,27 @@ /******************************************************************/ /* adds a host downtime entry to the list in memory */ -int add_host_downtime(char *host_name, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t flex_downtime_start, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, int is_in_effect){ +int add_host_downtime(char *host_name, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t flex_downtime_start, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, int is_in_effect, int start_notification_sent){ int result = OK; - result = add_downtime(HOST_DOWNTIME, host_name, NULL, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect); + result = add_downtime(HOST_DOWNTIME, host_name, NULL, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, start_notification_sent); return result; } /* adds a service downtime entry to the list in memory */ -int add_service_downtime(char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t flex_downtime_start, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, int is_in_effect){ +int add_service_downtime(char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t flex_downtime_start, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, int is_in_effect, int start_notification_sent){ int result = OK; - result = add_downtime(SERVICE_DOWNTIME, host_name, svc_description, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect); + result = add_downtime(SERVICE_DOWNTIME, host_name, svc_description, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, start_notification_sent); return result; } /* adds a host or service downtime entry to the list in memory */ -int add_downtime(int downtime_type, char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t flex_downtime_start, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, int is_in_effect){ +int add_downtime(int downtime_type, char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t flex_downtime_start, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, int is_in_effect, int start_notification_sent){ scheduled_downtime *new_downtime = NULL; scheduled_downtime *last_downtime = NULL; scheduled_downtime *temp_downtime = NULL; @@ -1052,6 +1058,7 @@ new_downtime->duration = duration; new_downtime->downtime_id = downtime_id; new_downtime->is_in_effect=is_in_effect; + new_downtime->start_notification_sent=start_notification_sent; if(defer_downtime_sorting) { new_downtime->next = scheduled_downtime_list; Modified: nagioscore/branches/nagios-3-4-x/include/downtime.h =================================================================== --- nagioscore/branches/nagios-3-4-x/include/downtime.h 2013-02-06 16:12:21 UTC (rev 2599) +++ nagioscore/branches/nagios-3-4-x/include/downtime.h 2013-02-09 23:55:47 UTC (rev 2600) @@ -46,6 +46,7 @@ unsigned long duration; unsigned long downtime_id; int is_in_effect; + int start_notification_sent; char *author; char *comment; #ifdef NSCORE @@ -64,9 +65,9 @@ int initialize_downtime_data(char *); /* initializes scheduled downtime data */ int cleanup_downtime_data(char *); /* cleans up scheduled downtime data */ -int add_new_downtime(int, char *, char *, time_t, char *, char *, time_t, time_t, int, unsigned long, unsigned long, unsigned long *, int); -int add_new_host_downtime(char *, time_t, char *, char *, time_t, time_t, int, unsigned long, unsigned long, unsigned long *, int); -int add_new_service_downtime(char *, char *, time_t, char *, char *, time_t, time_t, int, unsigned long, unsigned long, unsigned long *, int); +int add_new_downtime(int, char *, char *, time_t, char *, char *, time_t, time_t, int, unsigned long, unsigned long, unsigned long *, int, int); +int add_new_host_downtime(char *, time_t, char *, char *, time_t, time_t, int, unsigned long, unsigned long, unsigned long *, int, int); +int add_new_service_downtime(char *, char *, time_t, char *, char *, time_t, time_t, int, unsigned long, unsigned long, unsigned long *, int, int); int delete_host_downtime(unsigned long); int delete_service_downtime(unsigned long); @@ -85,15 +86,15 @@ int check_for_expired_downtime(void); #endif -int add_host_downtime(char *, time_t, char *, char *, time_t, time_t, time_t, int, unsigned long, unsigned long, unsigned long, int); -int add_service_downtime(char *, char *, time_t, char *, char *, time_t, time_t, time_t, int, unsigned long, unsigned long, unsigned long, int); +int add_host_downtime(char *, time_t, char *, char *, time_t, time_t, time_t, int, unsigned long, unsigned long, unsigned long, int, int); +int add_service_downtime(char *, char *, time_t, char *, char *, time_t, time_t, time_t, int, unsigned long, unsigned long, unsigned long, int, int); /* If you are going to be adding a lot of downtime in sequence, set defer_downtime_sorting to 1 before you start and then call sort_downtime afterwards. Things will go MUCH faster. */ extern int defer_downtime_sorting; -int add_downtime(int, char *, char *, time_t, char *, char *, time_t, time_t, time_t, int, unsigned long, unsigned long, unsigned long, int); +int add_downtime(int, char *, char *, time_t, char *, char *, time_t, time_t, time_t, int, unsigned long, unsigned long, unsigned long, int, int); int sort_downtime(void); scheduled_downtime *find_downtime(int, unsigned long); Modified: nagioscore/branches/nagios-3-4-x/xdata/xdddefault.c =================================================================== --- nagioscore/branches/nagios-3-4-x/xdata/xdddefault.c 2013-02-06 16:12:21 UTC (rev 2599) +++ nagioscore/branches/nagios-3-4-x/xdata/xdddefault.c 2013-02-09 23:55:47 UTC (rev 2600) @@ -195,14 +195,14 @@ /******************************************************************/ /* adds a new scheduled host downtime entry */ -int xdddefault_add_new_host_downtime(char *host_name, time_t entry_time, char *author, char *comment, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect){ +int xdddefault_add_new_host_downtime(char *host_name, time_t entry_time, char *author, char *comment, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, int start_notification_sent){ /* find the next valid downtime id */ while(find_host_downtime(next_downtime_id) != NULL) next_downtime_id++; /* add downtime to list in memory */ - add_host_downtime(host_name, entry_time, author, comment, start_time, (time_t)0, end_time, fixed, triggered_by, duration, next_downtime_id, is_in_effect); + add_host_downtime(host_name, entry_time, author, comment, start_time, (time_t)0, end_time, fixed, triggered_by, duration, next_downtime_id, is_in_effect, start_notification_sent); /* update downtime file */ xdddefault_save_downtime_data(); @@ -220,14 +220,14 @@ /* adds a new scheduled service downtime entry */ -int xdddefault_add_new_service_downtime(char *host_name, char *service_description, time_t entry_time, char *author, char *comment, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect){ +int xdddefault_add_new_service_downtime(char *host_name, char *service_description, time_t entry_time, char *author, char *comment, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, int start_notification_sent){ /* find the next valid downtime id */ while(find_service_downtime(next_downtime_id) != NULL) next_downtime_id++; /* add downtime to list in memory */ - add_service_downtime(host_name, service_description, entry_time, author, comment, start_time, (time_t)0, end_time, fixed, triggered_by, duration, next_downtime_id, is_in_effect); + add_service_downtime(host_name, service_description, entry_time, author, comment, start_time, (time_t)0, end_time, fixed, triggered_by, duration, next_downtime_id, is_in_effect, start_notification_sent); /* update downtime file */ xdddefault_save_downtime_data(); Modified: nagioscore/branches/nagios-3-4-x/xdata/xdddefault.h =================================================================== --- nagioscore/branches/nagios-3-4-x/xdata/xdddefault.h 2013-02-06 16:12:21 UTC (rev 2599) +++ nagioscore/branches/nagios-3-4-x/xdata/xdddefault.h 2013-02-09 23:55:47 UTC (rev 2600) @@ -36,8 +36,8 @@ int xdddefault_cleanup_downtime_data(char *); int xdddefault_save_downtime_data(void); -int xdddefault_add_new_host_downtime(char *, time_t, char *, char *, time_t, time_t, int, unsigned long, unsigned long, unsigned long *, int); -int xdddefault_add_new_service_downtime(char *, char *, time_t, char *, char *, time_t, time_t, int, unsigned long, unsigned long, unsigned long *, int); +int xdddefault_add_new_host_downtime(char *, time_t, char *, char *, time_t, time_t, int, unsigned long, unsigned long, unsigned long *, int, int); +int xdddefault_add_new_service_downtime(char *, char *, time_t, char *, char *, time_t, time_t, int, unsigned long, unsigned long, unsigned long *, int, int); int xdddefault_delete_host_downtime(unsigned long); int xdddefault_delete_service_downtime(unsigned long); Modified: nagioscore/branches/nagios-3-4-x/xdata/xrddefault.c =================================================================== --- nagioscore/branches/nagios-3-4-x/xdata/xrddefault.c 2013-02-06 16:12:21 UTC (rev 2599) +++ nagioscore/branches/nagios-3-4-x/xdata/xrddefault.c 2013-02-09 23:55:47 UTC (rev 2600) @@ -561,6 +561,7 @@ fprintf(fp, "fixed=%d\n", temp_downtime->fixed); fprintf(fp, "duration=%lu\n", temp_downtime->duration); fprintf(fp, "is_in_effect=%d\n", temp_downtime->is_in_effect); + fprintf(fp, "start_notification_sent=%d\n", temp_downtime->start_notification_sent); fprintf(fp, "author=%s\n", temp_downtime->author); fprintf(fp, "comment=%s\n", temp_downtime->comment); fprintf(fp, "}\n"); @@ -661,6 +662,7 @@ double runtime[2]; int found_directive = FALSE; int is_in_effect = FALSE; + int start_notification_sent = FALSE; log_debug_info(DEBUGL_FUNCTIONS, 0, "xrddefault_read_state_information() start\n"); @@ -965,9 +967,9 @@ /* add the downtime */ if(data_type == XRDDEFAULT_HOSTDOWNTIME_DATA) - add_host_downtime(host_name, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect); + add_host_downtime(host_name, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, start_notification_sent); else - add_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect); + add_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, start_notification_sent); /* must register the downtime with Nagios so it can schedule it, add comments, etc. */ register_downtime((data_type == XRDDEFAULT_HOSTDOWNTIME_DATA) ? HOST_DOWNTIME : SERVICE_DOWNTIME, downtime_id); @@ -1846,6 +1848,8 @@ triggered_by = strtoul(val, NULL, 10); else if(!strcmp(var, "is_in_effect")) is_in_effect = (atoi(val) > 0) ? TRUE : FALSE; + else if(!strcmp(var, "start_notification_sent")) + start_notification_sent = (atoi(val) > 0) ? TRUE : FALSE; else if(!strcmp(var, "duration")) duration = strtoul(val, NULL, 10); else if(!strcmp(var, "author")) Modified: nagioscore/branches/nagios-3-4-x/xdata/xsddefault.c =================================================================== --- nagioscore/branches/nagios-3-4-x/xdata/xsddefault.c 2013-02-06 16:12:21 UTC (rev 2599) +++ nagioscore/branches/nagios-3-4-x/xdata/xsddefault.c 2013-02-09 23:55:47 UTC (rev 2600) @@ -671,6 +671,7 @@ fprintf(fp, "\tfixed=%d\n", temp_downtime->fixed); fprintf(fp, "\tduration=%lu\n", temp_downtime->duration); fprintf(fp, "\tis_in_effect=%d\n", temp_downtime->is_in_effect); + fprintf(fp, "\tstart_notification_sent=%d\n", temp_downtime->start_notification_sent); fprintf(fp, "\tauthor=%s\n", temp_downtime->author); fprintf(fp, "\tcomment=%s\n", temp_downtime->comment); fprintf(fp, "\t}\n\n"); @@ -765,6 +766,7 @@ unsigned long duration = 0L; int x = 0; int is_in_effect = FALSE; + int start_notification_sent = FALSE; /* initialize some vars */ @@ -891,9 +893,9 @@ /* add the downtime */ if(data_type == XSDDEFAULT_HOSTDOWNTIME_DATA) - add_host_downtime(host_name, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect); + add_host_downtime(host_name, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, start_notification_sent); else - add_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect); + add_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, flex_downtime_start, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, start_notification_sent); /* free temp memory */ my_free(host_name); @@ -910,6 +912,7 @@ triggered_by = 0; duration = 0L; is_in_effect = FALSE; + start_notification_sent = FALSE; break; @@ -1276,6 +1279,8 @@ duration = strtoul(val, NULL, 10); else if(!strcmp(var, "is_in_effect")) is_in_effect = (atoi(val) > 0) ? TRUE : FALSE; + else if(!strcmp(var, "start_notification_sent")) + start_notification_sent = (atoi(val) > 0) ? TRUE : FALSE; else if(!strcmp(var, "author")) author = (char *)strdup(val); else if(!strcmp(var, "comment")) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |