Skip to content

Commit

Permalink
Fix: Unreachable status should be notifiable
Browse files Browse the repository at this point in the history
  • Loading branch information
tsadpbb committed Nov 22, 2024
1 parent 1867ffe commit 263c706
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Nagios Core 4 Change Log
########################

4.5.9 - 2024-XX-XX
------------------
* Fix unreachable notifications (Dylan Anderson)

4.5.8 - 2024-11-19
------------------
* Improve new exfoliation theme and add back in PID information (Dylan Anderson)
Expand Down
45 changes: 17 additions & 28 deletions base/notifications.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,23 @@ int check_service_notification_viability(service *svc, int type, int options) {
}
}

/* If all of the host parents are down, don't notify */
if (temp_host->parent_hosts != NULL) {
int bad_parents = 0, total_parents = 0;
hostsmember *temp_hostsmember = NULL;

for(temp_hostsmember = temp_host->parent_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
if (temp_hostsmember->host_ptr->current_state != HOST_UP)
bad_parents += !!temp_hostsmember->host_ptr->current_state;
total_parents++;
}
if(bad_parents == total_parents) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "This service has a host with no good parents, so notification will be blocked.\n");
return ERROR;
}
}


/* if the service has no notification period, inherit one from the host */
temp_period = svc->notification_period_ptr;
if(temp_period == NULL) {
Expand Down Expand Up @@ -614,20 +631,6 @@ int check_service_notification_viability(service *svc, int type, int options) {
return ERROR;
}

/* If any of the parents are down, don't notify */
if (temp_host->parent_hosts != NULL) {
hostsmember *temp_hostsmember = NULL;
host *parent_host = NULL;

for(temp_hostsmember = temp_host->parent_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
parent_host = temp_hostsmember->host_ptr;
if (parent_host->current_state != HOST_UP) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "At least one parent (%s) is down, so we won't notify about this service.\n", parent_host->name);
return ERROR;
}
}
}

/* don't notify if we haven't waited long enough since the last time (and the service is not marked as being volatile) */
if((current_time < svc->next_notification) && svc->is_volatile == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We haven't waited long enough to re-notify contacts about this service.\n");
Expand Down Expand Up @@ -1538,20 +1541,6 @@ int check_host_notification_viability(host *hst, int type, int options) {
return ERROR;
}

/* If any of the parents are down, don't notify */
if (hst->parent_hosts != NULL) {
hostsmember *temp_hostsmember = NULL;
host *parent_host = NULL;

for(temp_hostsmember = hst->parent_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
parent_host = temp_hostsmember->host_ptr;
if (parent_host->current_state != HOST_UP) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "At least one parent (%s) is down, so we won't notify about this host.\n", parent_host->name);
return ERROR;
}
}
}

return OK;
}

Expand Down

0 comments on commit 263c706

Please sign in to comment.