From d750bff193931e091101fb2a83e2b349dd564f14 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 8 Nov 2024 15:37:18 +0100 Subject: [PATCH] Notification: Fix incorrectly dropped recovery & ACK notifications Previously, recovery and ACK notifications were not delivered to users who weren't notified about the problem state while having a configured `Problem` type filter. However, since the type filter can also be configured on the `Notification` object level, this resulted to an incorrect behaviour. This PR changes the existing logic so that the recovery and ACK notifications gets dropped only if the `Problem` filter is configured on both the `User` and `Notification` object levels. --- lib/icinga/notification.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index bd3158ced..087c2a19d 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -428,22 +428,17 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe continue; } - /* on recovery, check if user was notified before */ - if (type == NotificationRecovery) { - if (!notifiedProblemUsers->Contains(userName) && (NotificationProblem & user->GetTypeFilter())) { + /* on acknowledgement/recovery, check if user was notified before */ + if (type == NotificationAcknowledgement || type == NotificationRecovery) { + // Do not notify the user about the ACK/recovery of a problem state that they have not been notified + // about, unless they are explicitly configured to receive ACK/recovery notifications but no problem + // ones, or this Notification instance isn't allowed to send problem notifications (doesn't contain + // the 'Problem' type filter). + if (!notifiedProblemUsers->Contains(userName) && NotificationProblem & user->GetTypeFilter() & GetTypeFilter()) { Log(LogNotice, "Notification") << "Notification object '" << notificationName << "': We did not notify user '" << userName - << "' (Problem types enabled) for a problem before. Not sending Recovery notification."; - continue; - } - } - - /* on acknowledgement, check if user was notified before */ - if (type == NotificationAcknowledgement) { - if (!notifiedProblemUsers->Contains(userName) && (NotificationProblem & user->GetTypeFilter())) { - Log(LogNotice, "Notification") - << "Notification object '" << notificationName << "': We did not notify user '" << userName - << "' (Problem types enabled) for a problem before. Not sending acknowledgement notification."; + << "' (Problem types enabled) for a problem before. Not sending " + << (type == NotificationRecovery ? "Recovery" : "acknowledgement") << " notification."; continue; } }