[icinga-checkins] icinga.org: icinga2/master: Fix that recovery notifications are sent if notified for !Problem type before

git at icinga.org git at icinga.org
Thu Nov 17 10:37:30 CET 2016


Module: icinga2
Branch: master
Commit: 35ce166bd214ca552d27cf4d8f4d9d8eea2859ae
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=35ce166bd214ca552d27cf4d8f4d9d8eea2859ae

Author: Michael Friedrich <michael.friedrich at icinga.com>
Date:   Tue Nov 15 15:12:26 2016 +0100

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 1f09523..deaceb6 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 305be8f..7701de4 100644
--- a/lib/icinga/notification.cpp
+++ b/lib/icinga/notification.cpp
@@ -386,7 +386,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
 	}
 
 	std::set<User::Ptr> 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 2445c2d..12922d6 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(); }}}
 	};
 



More information about the icinga-checkins mailing list