From 35ce166bd214ca552d27cf4d8f4d9d8eea2859ae Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 15 Nov 2016 15:12:26 +0100 Subject: [PATCH] Fix that recovery notifications are sent if notified for !Problem type before fixes #13205 --- lib/icinga/clusterevents.cpp | 6 +++--- lib/icinga/notification.cpp | 12 ++++++------ lib/icinga/notification.ti | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/icinga/clusterevents.cpp b/lib/icinga/clusterevents.cpp index 1f0952356..deaceb60c 100644 --- a/lib/icinga/clusterevents.cpp +++ b/lib/icinga/clusterevents.cpp @@ -1097,12 +1097,12 @@ Value ClusterEvents::NotificationSentToAllUsersAPIHandler(const MessageOrigin::P notification->SetLastProblemNotification(params->Get("last_problem_notification")); notification->SetNoMoreNotifications(params->Get("no_more_notifications")); - Array::Ptr notifiedUsers = new Array(); + Array::Ptr notifiedProblemUsers = new Array(); for (const User::Ptr& user : users) { - notifiedUsers->Add(user->GetName()); + notifiedProblemUsers->Add(user->GetName()); } - notification->SetNotifiedUsers(notifiedUsers); + notification->SetNotifiedProblemUsers(notifiedProblemUsers); Checkable::OnNotificationSentToAllUsers(notification, checkable, users, type, cr, author, text, origin); diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 305be8fef..7701de4d1 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -386,7 +386,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe } std::set allNotifiedUsers; - Array::Ptr notifiedUsers = GetNotifiedUsers(); + Array::Ptr notifiedProblemUsers = GetNotifiedProblemUsers(); for (const User::Ptr& user : allUsers) { String userName = user->GetName(); @@ -405,9 +405,9 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe /* on recovery, check if user was notified before */ if (type == NotificationRecovery) { - if (!notifiedUsers->Contains(userName)) { + if (!notifiedProblemUsers->Contains(userName)) { Log(LogNotice, "Notification") - << "We did not notify user '" << userName << "' before. Not sending recovery notification."; + << "We did not notify user '" << userName << "' for a problem before. Not sending recovery notification."; continue; } } @@ -422,13 +422,13 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe allNotifiedUsers.insert(user); /* store all notified users for later recovery checks */ - if (!notifiedUsers->Contains(userName)) - notifiedUsers->Add(userName); + if (type == NotificationProblem && !notifiedProblemUsers->Contains(userName)) + notifiedProblemUsers->Add(userName); } /* if this was a recovery notification, reset all notified users */ if (type == NotificationRecovery) - notifiedUsers->Clear(); + notifiedProblemUsers->Clear(); /* used in db_ido for notification history */ Service::OnNotificationSentToAllUsers(this, checkable, allNotifiedUsers, type, cr, author, text, MessageOrigin::Ptr()); diff --git a/lib/icinga/notification.ti b/lib/icinga/notification.ti index 2445c2d94..12922d6bf 100644 --- a/lib/icinga/notification.ti +++ b/lib/icinga/notification.ti @@ -86,7 +86,7 @@ class Notification : CustomVarObject < NotificationNameComposer }}} }; - [state, no_user_modify] Array::Ptr notified_users { + [state, no_user_modify] Array::Ptr notified_problem_users { default {{{ return new Array(); }}} }; -- 2.40.0