From ec09f9cae936302d40d637a56c267e6c28ebb3ca 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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 81a48bada8..74174f32c6 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -428,9 +428,14 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe continue; } + // Verify if the 'Problem' filter is configured at both the User and Notification object levels. + bool foundProblemFilter = NotificationProblem & user->GetTypeFilter() & GetTypeFilter(); + /* on recovery, check if user was notified before */ if (type == NotificationRecovery) { - if (!notifiedProblemUsers->Contains(userName) && (NotificationProblem & user->GetTypeFilter())) { + // Do not send a recovery notification to the current user if he was not previously notified of the + // problem state, while containing the 'Problem' filter at both the user and notification object levels. + if (!notifiedProblemUsers->Contains(userName) && foundProblemFilter) { Log(LogNotice, "Notification") << "Notification object '" << notificationName << "': We did not notify user '" << userName << "' (Problem types enabled) for a problem before. Not sending Recovery notification."; @@ -440,7 +445,9 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe /* on acknowledgement, check if user was notified before */ if (type == NotificationAcknowledgement) { - if (!notifiedProblemUsers->Contains(userName) && (NotificationProblem & user->GetTypeFilter())) { + // Do not send an ACK notification to the current user if he wasn't previously notified of the problem + // state, while containing the 'Problem' filter at both the user and notification object levels. + if (!notifiedProblemUsers->Contains(userName) && foundProblemFilter) { Log(LogNotice, "Notification") << "Notification object '" << notificationName << "': We did not notify user '" << userName << "' (Problem types enabled) for a problem before. Not sending acknowledgement notification.";