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

Fix [#847]: Send a recovery notification if the object recovered while flapping #971

Merged
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
2 changes: 2 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Nagios Core 4 Change Log
4.5.6 - 2024-XX-XX
------------------
* Update tutorial links in Readme (Igor Udot)
* Send a recovery notification if the object recovered while flapping (#847) (Dylan Anderson)
* Fix for separate build directory & a couple small cleanups (Doug Nazar)

4.5.5 - 2024-09-17
------------------
Expand Down
6 changes: 4 additions & 2 deletions base/checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,8 @@ int handle_async_service_check_result(service *svc, check_result *cr)
}

/* the service recovered, so reset the current notification number and state flags (after the recovery notification has gone out) */
if(svc->current_state == STATE_OK && svc->state_type == HARD_STATE && hard_state_change == TRUE) {
/* We don't want to reset notifications if the service is currently flapping because we want recovery notifications */
if(svc->current_state == STATE_OK && svc->state_type == HARD_STATE && hard_state_change == TRUE && svc->is_flapping == FALSE) {
svc->current_notification_number = 0;
svc->notified_on = 0;
}
Expand Down Expand Up @@ -2494,7 +2495,8 @@ int handle_async_host_check_result(host *hst, check_result *cr)
}

/* the host recovered, so reset the current notification number and state flags (after the recovery notification has gone out) */
if(hst->current_state == HOST_UP && hst->state_type == HARD_STATE && hard_state_change == TRUE) {
/* We don't want to reset notifications if the host is currently flapping because we want recovery notifications */
if(hst->current_state == HOST_UP && hst->state_type == HARD_STATE && hard_state_change == TRUE && hst->is_flapping == FALSE) {
hst->current_notification_number = 0;
hst->notified_on = 0;
}
Expand Down
6 changes: 6 additions & 0 deletions base/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -5392,6 +5392,9 @@ void clear_host_flapping_state(host *hst) {
/* should we send a recovery notification? */
if (hst->current_state == HOST_UP && hst->check_flapping_recovery_notification == TRUE) {
host_notification(hst, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE);
/* Similar to what happens when a host recovers in handle_async_host_check_result */
hst->current_notification_number = 0;
hst->notified_on = 0;
}
}

Expand Down Expand Up @@ -5449,6 +5452,9 @@ void clear_service_flapping_state(service *svc) {
/* should we send a recovery notification? */
if (svc->current_state == STATE_OK && svc->check_flapping_recovery_notification == TRUE) {
service_notification(svc, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE);
/* Similar to what happens when a service recovers in handle_async_service_check_result */
svc->current_notification_number = 0;
svc->notified_on = 0;
}
}

Expand Down
30 changes: 24 additions & 6 deletions base/flapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ void set_service_flap(service *svc, double percent_change, double high_threshold
#endif

/* see if we should check to send a recovery notification out when flapping stops */
if(svc->current_state != STATE_OK && svc->current_notification_number > 0)
/* If the check result that causes the service to go into flapping status is STATUS_OK, we still want recovery notification */
if(svc->current_notification_number > 0)
svc->check_flapping_recovery_notification = TRUE;
else
svc->check_flapping_recovery_notification = FALSE;
Expand Down Expand Up @@ -373,8 +374,12 @@ void clear_service_flap(service *svc, double percent_change, double high_thresho
service_notification(svc, NOTIFICATION_FLAPPINGSTOP, NULL, NULL, NOTIFICATION_OPTION_NONE);

/* should we send a recovery notification? */
if(svc->check_flapping_recovery_notification == TRUE && svc->current_state == STATE_OK)
if(svc->check_flapping_recovery_notification == TRUE && svc->current_state == STATE_OK) {
service_notification(svc, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE);
/* Similar to what happens when a service recovers in handle_async_service_check_result */
svc->current_notification_number = 0;
svc->notified_on = 0;
}
}

/* clear the recovery notification flag */
Expand Down Expand Up @@ -414,7 +419,8 @@ void set_host_flap(host *hst, double percent_change, double high_threshold, doub
#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)
/* If the check result that causes the host to go into flapping status is HOST_UP, we still want recovery notification */
if(hst->current_notification_number > 0)
hst->check_flapping_recovery_notification = TRUE;
else
hst->check_flapping_recovery_notification = FALSE;
Expand Down Expand Up @@ -463,8 +469,12 @@ void clear_host_flap(host *hst, double percent_change, double high_threshold, do
host_notification(hst, NOTIFICATION_FLAPPINGSTOP, NULL, NULL, NOTIFICATION_OPTION_NONE);

/* should we send a recovery notification? */
if(hst->check_flapping_recovery_notification == TRUE && hst->current_state == HOST_UP)
if(hst->check_flapping_recovery_notification == TRUE && hst->current_state == HOST_UP) {
host_notification(hst, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE);
/* Similar to what happens when a host recovers in handle_async_host_check_result */
hst->current_notification_number = 0;
hst->notified_on = 0;
}
}

/* clear the recovery notification flag */
Expand Down Expand Up @@ -652,8 +662,12 @@ void handle_host_flap_detection_disabled(host *hst) {
host_notification(hst, NOTIFICATION_FLAPPINGDISABLED, NULL, NULL, NOTIFICATION_OPTION_NONE);

/* should we send a recovery notification? */
if(hst->check_flapping_recovery_notification == TRUE && hst->current_state == HOST_UP)
if(hst->check_flapping_recovery_notification == TRUE && hst->current_state == HOST_UP) {
host_notification(hst, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE);
/* Similar to what happens when a host recovers in handle_async_host_check_result */
hst->current_notification_number = 0;
hst->notified_on = 0;
}

/* clear the recovery notification flag */
hst->check_flapping_recovery_notification = FALSE;
Expand Down Expand Up @@ -766,8 +780,12 @@ void handle_service_flap_detection_disabled(service *svc) {
service_notification(svc, NOTIFICATION_FLAPPINGDISABLED, NULL, NULL, NOTIFICATION_OPTION_NONE);

/* should we send a recovery notification? */
if(svc->check_flapping_recovery_notification == TRUE && svc->current_state == STATE_OK)
if(svc->check_flapping_recovery_notification == TRUE && svc->current_state == STATE_OK) {
service_notification(svc, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE);
/* Similar to what happens when a service recovers in handle_async_service_check_result */
svc->current_notification_number = 0;
svc->notified_on = 0;
}

/* clear the recovery notification flag */
svc->check_flapping_recovery_notification = FALSE;
Expand Down