[icinga-checkins] icinga.org: icinga2/master: Add an explicit flag for disabling reminder notifications

git at icinga.org git at icinga.org
Mon Aug 15 18:33:55 CEST 2016


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Mon Aug 15 18:32:51 2016 +0200

Add an explicit flag for disabling reminder notifications

refs #12402

---

 lib/icinga/clusterevents.cpp               |    2 ++
 lib/icinga/notification.cpp                |    5 +++++
 lib/icinga/notification.ti                 |    4 ++++
 lib/notification/notificationcomponent.cpp |    7 +++++--
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/icinga/clusterevents.cpp b/lib/icinga/clusterevents.cpp
index 0e5c9d1..b30ba73 100644
--- a/lib/icinga/clusterevents.cpp
+++ b/lib/icinga/clusterevents.cpp
@@ -968,6 +968,7 @@ void ClusterEvents::NotificationSentToAllUsersHandler(const Notification::Ptr& n
 	params->Set("next_notification", notification->GetNextNotification());
 	params->Set("notification_number", notification->GetNotificationNumber());
 	params->Set("last_problem_notification", notification->GetLastProblemNotification());
+	params->Set("no_more_notifications", notification->GetNoMoreNotifications());
 
 	Dictionary::Ptr message = new Dictionary();
 	message->Set("jsonrpc", "2.0");
@@ -1051,6 +1052,7 @@ Value ClusterEvents::NotificationSentAllUsersAPIHandler(const MessageOrigin::Ptr
 	notification->SetNextNotification(params->Get("next_notification"));
 	notification->SetNotificationNumber(params->Get("notification_number"));
 	notification->SetLastProblemNotification(params->Get("last_problem_notification"));
+	notification->SetNoMoreNotifications(params->Get("no_more_notifications"));
 	notification->SetNotifiedUsers(Array::FromSet(users));
 
 	Checkable::OnNotificationSentToAllUsers(notification, checkable, users, type, cr, author, text, origin);
diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp
index 0b518bd..52f7dea 100644
--- a/lib/icinga/notification.cpp
+++ b/lib/icinga/notification.cpp
@@ -364,6 +364,11 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
 		double now = Utility::GetTime();
 		SetLastNotification(now);
 
+		if (type == NotificationProblem && GetInterval() <= 0)
+			SetNoMoreNotifications(true);
+		else
+			SetNoMoreNotifications(false);
+
 		if (type == NotificationProblem && GetInterval() > 0)
 			SetNextNotification(now + GetInterval());
 
diff --git a/lib/icinga/notification.ti b/lib/icinga/notification.ti
index a63e682..2445c2d 100644
--- a/lib/icinga/notification.ti
+++ b/lib/icinga/notification.ti
@@ -90,6 +90,10 @@ class Notification : CustomVarObject < NotificationNameComposer
 		default {{{ return new Array(); }}}
 	};
 
+	[state, no_user_modify] bool no_more_notifications {
+		default {{{ return false; }}}
+	};
+
 	[state] Timestamp last_notification;
 	[state] Timestamp next_notification;
 	[state] int notification_number;
diff --git a/lib/notification/notificationcomponent.cpp b/lib/notification/notificationcomponent.cpp
index a33064c..5a8167b 100644
--- a/lib/notification/notificationcomponent.cpp
+++ b/lib/notification/notificationcomponent.cpp
@@ -83,8 +83,11 @@ void NotificationComponent::NotificationTimerHandler(void)
 		if (!IcingaApplication::GetInstance()->GetEnableNotifications() || !checkable->GetEnableNotifications())
 			continue;
 
-		if (notification->GetInterval() <= 0 && notification->GetLastProblemNotification() > checkable->GetLastHardStateChange())
+		if (notification->GetInterval() <= 0 && notification->GetNoMoreNotifications()) {
+			Log(LogDebug, "NotificationComponent")
+			    << "Skipping reminder notification '" << notification->GetName() << "'. Interval is 0 and no more notifications are required.";
 			continue;
+		}
 
 		if (notification->GetNextNotification() > now)
 			continue;
@@ -115,7 +118,7 @@ void NotificationComponent::NotificationTimerHandler(void)
 
 		try {
 			Log(LogNotice, "NotificationComponent")
-			    << "Attempting to send reminder notification for object '" << checkable->GetName() << "'";
+			    << "Attempting to send reminder notification '" << notification->GetName() << "'";
 			notification->BeginExecuteNotification(NotificationProblem, checkable->GetLastCheckResult(), false, true);
 		} catch (const std::exception& ex) {
 			Log(LogWarning, "NotificationComponent")



More information about the icinga-checkins mailing list