]> granicus.if.org Git - icinga2/commitdiff
notifications: add notification number
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 18 Jul 2013 15:04:09 +0000 (17:04 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 18 Jul 2013 15:04:09 +0000 (17:04 +0200)
lib/icinga/notification.cpp
lib/icinga/notification.h
lib/icinga/service-check.cpp
lib/icinga/service-notification.cpp
lib/icinga/service.h

index b65537c04f6ea0ec9bffb528099e64d20f027b8c..80d17cb05a0d45f0213501ebd2173774d5a7cf29 100644 (file)
@@ -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");
 
index 0a10d99235054290461034408d1ed164da0b5605..c85c8c1d4153989ad6fb40794b257c2092d3d132 100644 (file)
@@ -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<String> m_NotificationPeriod;
        Attribute<double> m_LastNotification;
        Attribute<double> m_NextNotification;
+       Attribute<int> m_NotificationNumber;
        Attribute<Dictionary::Ptr> m_Macros;
        Attribute<Array::Ptr> m_ExportMacros;
        Attribute<Array::Ptr> m_Users;
@@ -108,6 +113,7 @@ private:
        Attribute<String> m_HostName;
        Attribute<String> m_Service;
 
+
        void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = "");
 };
 
index 57e805bf09e7d0e16f66a7387fe4859305c7f71b..c5ab8f22b126a66da7686cf278f79b4414634687 100644 (file)
@@ -429,6 +429,7 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
 
                attempt = 1;
                recovery = true;
+               ResetNotificationNumbers();
        } else {
                if (old_attempt >= GetMaxCheckAttempts()) {
                        SetStateType(StateTypeHard);
index be0581ed07ee5a8b7b935f5e1753f48c9d0a6a2b..58b6b24a5e8f7f4fcc0aca7c3b90de4db3d33520 100644 (file)
@@ -39,6 +39,14 @@ static Timer::Ptr l_NotificationsCacheTimer;
 
 boost::signals2::signal<void (const Service::Ptr&, const String&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> 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;
index 9da59e9dde738dab344315235e5fd7498ff30928..3d7911a7d7eb185e920c39668b944ac3ac2b6141 100644 (file)
@@ -283,6 +283,8 @@ public:
        void SetForceNextNotification(bool force);
        bool GetForceNextNotification(void) const;
 
+       void ResetNotificationNumbers(void);
+
        static void InvalidateNotificationsCache(void);
 
        void UpdateSlaveNotifications(void);