]> granicus.if.org Git - icinga2/commitdiff
Implement notification escalations.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 13 May 2013 11:44:57 +0000 (13:44 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 13 May 2013 11:44:57 +0000 (13:44 +0200)
lib/icinga/icinga-type.conf
lib/icinga/notification.cpp
lib/icinga/notification.h

index 7d119586fea776be0c5eba857925fd292b2216fc..16aa0fa8e335f9e37392e4d5a655a8e21f2f72d3 100644 (file)
@@ -97,7 +97,12 @@ type Host {
                                        },
                                        %attribute array "groups" {
                                                %attribute name(UserGroup) "*"
-                                       }
+                                       },
+
+                                       %attribute dictionary "times" {
+                                               %attribute number "begin",
+                                               %attribute number "end",
+                                       },
                                }
                        },
                }
@@ -122,7 +127,12 @@ type Host {
                        },
                        %attribute array "groups" {
                                %attribute name(UserGroup) "*"
-                       }
+                       },
+
+                       %attribute dictionary "times" {
+                               %attribute number "begin",
+                               %attribute number "end",
+                       },
                }
        },
 
@@ -240,7 +250,13 @@ type Service {
                        },
                        %attribute array "groups" {
                                %attribute name(UserGroup) "*"
-                       }
+                       },
+
+                       %attribute dictionary "times" {
+                               %attribute number "begin",
+                               %attribute number "end",
+                       },
+
                }
        }
 }
@@ -277,6 +293,11 @@ type Notification {
                %attribute name(UserGroup) "*"
        },
 
+       %attribute dictionary "times" {
+               %attribute number "begin",
+               %attribute number "end",
+       },
+
        %attribute array "notification_command" {
                %attribute string "*"
        },
index d11c86a3476dabd12b15d67479dc3fc50a1e159e..1698877a489c0bc0e8d943ba16db5d5586db1943 100644 (file)
@@ -43,6 +43,7 @@ Notification::Notification(const Dictionary::Ptr& serializedUpdate)
        RegisterAttribute("macros", Attribute_Config, &m_Macros);
        RegisterAttribute("users", Attribute_Config, &m_Users);
        RegisterAttribute("groups", Attribute_Config, &m_Groups);
+       RegisterAttribute("times", Attribute_Config, &m_Times);
        RegisterAttribute("host_name", Attribute_Config, &m_HostName);
        RegisterAttribute("service", Attribute_Config, &m_Service);
        RegisterAttribute("export_macros", Attribute_Config, &m_ExportMacros);
@@ -132,6 +133,11 @@ std::set<UserGroup::Ptr> Notification::GetGroups(void) const
        return result;
 }
 
+Dictionary::Ptr Notification::GetTimes(void) const
+{
+       return m_Times;
+}
+
 double Notification::GetNotificationInterval(void) const
 {
        if (m_NotificationInterval.IsEmpty())
@@ -202,17 +208,31 @@ String Notification::NotificationTypeToString(NotificationType type)
        }
 }
 
-void Notification::BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool ignore_timeperiod)
+void Notification::BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force)
 {
        ASSERT(!OwnsLock());
 
-       if (!ignore_timeperiod) {
+       if (!force) {
                TimePeriod::Ptr tp = GetNotificationPeriod();
 
                if (tp && !tp->IsInside(Utility::GetTime())) {
                        Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': not in timeperiod");
                        return;
                }
+
+               double now = Utility::GetTime();
+               Dictionary::Ptr times = GetTimes();
+               Service::Ptr service = GetService();
+
+               if (times && times->Contains("begin") && now < service->GetLastHardStateChange() + times->Get("begin")) {
+                       Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': before escalation range");
+                       return;
+               }
+
+               if (times && times->Contains("end") && now > service->GetLastHardStateChange() + times->Get("end")) {
+                       Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': after escalation range");
+                       return;
+               }
        }
 
        {
@@ -233,7 +253,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const Diction
 
        BOOST_FOREACH(const User::Ptr& user, allUsers) {
                Log(LogDebug, "icinga", "Sending notification for user " + user->GetName());
-               Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, ignore_timeperiod));
+               Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force));
        }
 }
 
index ee9c084c324879fc663c8eba8b7b3cb26fb8b370..4188c0f0e665d2e94b8425ac1d41e4d92de4dfe4 100644 (file)
@@ -71,6 +71,7 @@ public:
        Array::Ptr GetExportMacros(void) const;
        std::set<User::Ptr> GetUsers(void) const;
        std::set<UserGroup::Ptr> GetGroups(void) const;
+       Dictionary::Ptr GetTimes(void) const;
 
        double GetLastNotification(void) const;
        void SetLastNotification(double time);
@@ -78,7 +79,7 @@ public:
        double GetNextNotification(void) const;
        void SetNextNotification(double time);
 
-       void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool ignore_timeperiod);
+       void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force);
 
        static String NotificationTypeToString(NotificationType type);
 
@@ -97,10 +98,11 @@ private:
        Attribute<Array::Ptr> m_ExportMacros;
        Attribute<Array::Ptr> m_Users;
        Attribute<Array::Ptr> m_Groups;
+       Attribute<Dictionary::Ptr> m_Times;
        Attribute<String> m_HostName;
        Attribute<String> m_Service;
 
-       void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool ignore_timeperiod);
+       void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force);
 };
 
 }