From 5547488cd5a2bf45c23a3d5276371ae6d2b61864 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 27 Nov 2020 17:03:34 +0100 Subject: [PATCH 1/3] Introduce Checkable#NotificationReasonSuppressed() refs #8509 --- lib/icinga/checkable-notification.cpp | 40 +++++++++++++++------------ lib/icinga/checkable.hpp | 1 + 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/icinga/checkable-notification.cpp b/lib/icinga/checkable-notification.cpp index 7d9fcb6b1..7bdfaa67c 100644 --- a/lib/icinga/checkable-notification.cpp +++ b/lib/icinga/checkable-notification.cpp @@ -173,24 +173,7 @@ static void FireSuppressedNotifications(Checkable* checkable) bool still_applies = checkable->NotificationReasonApplies(type); if (still_applies) { - bool still_suppressed; - - switch (type) { - case NotificationProblem: - /* Fall through. */ - case NotificationRecovery: - still_suppressed = !checkable->IsReachable(DependencyNotification) || checkable->IsInDowntime() || checkable->IsAcknowledged(); - break; - case NotificationFlappingStart: - /* Fall through. */ - case NotificationFlappingEnd: - still_suppressed = checkable->IsInDowntime(); - break; - default: - break; - } - - if (!still_suppressed && !checkable->IsLikelyToBeCheckedSoon() && !wasLastParentRecoveryRecent.Get()) { + if (!checkable->NotificationReasonSuppressed(type) && !checkable->IsLikelyToBeCheckedSoon() && !wasLastParentRecoveryRecent.Get()) { Checkable::OnNotificationsRequested(checkable, type, checkable->GetLastCheckResult(), "", "", nullptr); subtract |= type; @@ -258,6 +241,27 @@ bool Checkable::NotificationReasonApplies(NotificationType type) } } +/** + * Returns whether *this not allows sending a notification of type type right now. + * + * @param type The type of notification to send (or not to send). + * + * @return Whether not to send the notification. + */ +bool Checkable::NotificationReasonSuppressed(NotificationType type) +{ + switch (type) { + case NotificationProblem: + case NotificationRecovery: + return !IsReachable(DependencyNotification) || IsInDowntime() || IsAcknowledged(); + case NotificationFlappingStart: + case NotificationFlappingEnd: + return IsInDowntime(); + default: + return false; + } +} + /** * E.g. we're going to re-send a stashed problem notification as *this is still not ok. * But if the next check result recovers *this soon, we would send a recovery notification soon after the problem one. diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index c9799f07a..97518cfc2 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -175,6 +175,7 @@ public: void ValidateMaxCheckAttempts(const Lazy& lvalue, const ValidationUtils& value) final; bool NotificationReasonApplies(NotificationType type); + bool NotificationReasonSuppressed(NotificationType type); bool IsLikelyToBeCheckedSoon(); static void IncreasePendingChecks(); From f04387a9739375800aadf4d0bf571279760769b1 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 14 Dec 2020 13:28:53 +0100 Subject: [PATCH 2/3] FireSuppressedNotifications(const Notification::Ptr&): don't send notifications while suppressed by checkable ... e.g. if a notification enters its time period (not suppressed anymore), but its checkable has entered a downtime (suppressed). refs #8509 --- lib/notification/notificationcomponent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/notification/notificationcomponent.cpp b/lib/notification/notificationcomponent.cpp index b81092ff1..6e4e99168 100644 --- a/lib/notification/notificationcomponent.cpp +++ b/lib/notification/notificationcomponent.cpp @@ -91,7 +91,7 @@ void FireSuppressedNotifications(const Notification::Ptr& notification) if ((!tp || tp->IsInside(Utility::GetTime())) && !checkable->IsLikelyToBeCheckedSoon()) { for (auto type : {NotificationProblem, NotificationRecovery, NotificationFlappingStart, NotificationFlappingEnd}) { - if (!(suppressedTypes & type)) + if (!(suppressedTypes & type) || checkable->NotificationReasonSuppressed(type)) continue; auto notificationName (notification->GetName()); From 8d1e95827535eec89d11dad3198df6b82b86d23f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Aleksandrovi=C4=8D=20Klimov?= Date: Wed, 27 Jan 2021 15:43:37 +0100 Subject: [PATCH 3/3] Make code doc more readable Co-authored-by: Julian Brost --- lib/icinga/checkable-notification.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/icinga/checkable-notification.cpp b/lib/icinga/checkable-notification.cpp index 7bdfaa67c..cd0c497f4 100644 --- a/lib/icinga/checkable-notification.cpp +++ b/lib/icinga/checkable-notification.cpp @@ -242,11 +242,11 @@ bool Checkable::NotificationReasonApplies(NotificationType type) } /** - * Returns whether *this not allows sending a notification of type type right now. + * Checks if notifications of a given type should be suppressed for this Checkable at the moment. * - * @param type The type of notification to send (or not to send). + * @param type The notification type for which to query the suppression status. * - * @return Whether not to send the notification. + * @return true if no notification of this type should be sent. */ bool Checkable::NotificationReasonSuppressed(NotificationType type) {