From fe4a5e721c379ea33cbc23217bc4941217b26b21 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 18 Jul 2013 17:04:09 +0200 Subject: [PATCH] notifications: add notification number --- lib/icinga/notification.cpp | 26 ++++++++++++++++++++++++++ lib/icinga/notification.h | 6 ++++++ lib/icinga/service-check.cpp | 1 + lib/icinga/service-notification.cpp | 8 ++++++++ lib/icinga/service.h | 2 ++ 5 files changed, 43 insertions(+) diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index b65537c04..80d17cb05 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -44,6 +44,7 @@ Notification::Notification(const Dictionary::Ptr& serializedUpdate) RegisterAttribute("notification_period", Attribute_Config, &m_NotificationPeriod); RegisterAttribute("last_notification", Attribute_Replicated, &m_LastNotification); RegisterAttribute("next_notification", Attribute_Replicated, &m_NextNotification); + RegisterAttribute("notification_number", Attribute_Replicated, &m_NotificationNumber); RegisterAttribute("macros", Attribute_Config, &m_Macros); RegisterAttribute("users", Attribute_Config, &m_Users); RegisterAttribute("groups", Attribute_Config, &m_Groups); @@ -208,6 +209,26 @@ void Notification::SetNextNotification(double time) Touch("next_notification"); } +int Notification::GetNotificationNumber(void) const +{ + if (m_NotificationNumber.IsEmpty()) + return 0; + else + return m_NotificationNumber; +} + +void Notification::UpdateNotificationNumber(void) +{ + m_NotificationNumber = m_NotificationNumber + 1; + Touch("notification_number"); +} + +void Notification::ResetNotificationNumber(void) +{ + m_NotificationNumber = 0; + Touch("notification_number"); +} + String Notification::NotificationTypeToString(NotificationType type) { switch (type) { @@ -332,6 +353,11 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: try { GetNotificationCommand()->Execute(GetSelf(), user, cr, type); + { + ObjectLock olock(this); + UpdateNotificationNumber(); + } + RequestMessage rm; rm.SetMethod("icinga::NotificationSent"); diff --git a/lib/icinga/notification.h b/lib/icinga/notification.h index 0a10d9923..c85c8c1d4 100644 --- a/lib/icinga/notification.h +++ b/lib/icinga/notification.h @@ -83,6 +83,10 @@ public: double GetNextNotification(void) const; void SetNextNotification(double time); + int GetNotificationNumber(void) const; + void UpdateNotificationNumber(void); + void ResetNotificationNumber(void); + void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = ""); static String NotificationTypeToString(NotificationType type); @@ -98,6 +102,7 @@ private: Attribute m_NotificationPeriod; Attribute m_LastNotification; Attribute m_NextNotification; + Attribute m_NotificationNumber; Attribute m_Macros; Attribute m_ExportMacros; Attribute m_Users; @@ -108,6 +113,7 @@ private: Attribute m_HostName; Attribute m_Service; + void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = ""); }; diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp index 57e805bf0..c5ab8f22b 100644 --- a/lib/icinga/service-check.cpp +++ b/lib/icinga/service-check.cpp @@ -429,6 +429,7 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr) attempt = 1; recovery = true; + ResetNotificationNumbers(); } else { if (old_attempt >= GetMaxCheckAttempts()) { SetStateType(StateTypeHard); diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index be0581ed0..58b6b24a5 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -39,6 +39,14 @@ static Timer::Ptr l_NotificationsCacheTimer; boost::signals2::signal Service::OnNotificationSentChanged; +void Service::ResetNotificationNumbers(void) +{ + BOOST_FOREACH(const Notification::Ptr& notification, GetNotifications()) { + ObjectLock olock(notification); + notification->ResetNotificationNumber(); + } +} + void Service::NotificationSentRequestHandler(const RequestMessage& request) { NotificationMessage params; diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 9da59e9dd..3d7911a7d 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -283,6 +283,8 @@ public: void SetForceNextNotification(bool force); bool GetForceNextNotification(void) const; + void ResetNotificationNumbers(void); + static void InvalidateNotificationsCache(void); void UpdateSlaveNotifications(void); -- 2.40.0