From d909c0945c68db377ece0051e084a7f47f889082 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 15 Aug 2016 18:32:51 +0200 Subject: [PATCH] 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 0e5c9d179..b30ba73c8 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 0b518bd87..52f7dea13 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 a63e68284..2445c2d94 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 a33064ccf..5a8167b1c 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") -- 2.40.0