[icinga-checkins] icinga.org: icinga2/master: Implement notification escalations.

git at icinga.org git at icinga.org
Mon May 13 13:45:07 CEST 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon May 13 13:44:57 2013 +0200

Implement notification escalations.

---

 lib/icinga/icinga-type.conf |   27 ++++++++++++++++++++++++---
 lib/icinga/notification.cpp |   26 +++++++++++++++++++++++---
 lib/icinga/notification.h   |    6 ++++--
 3 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/lib/icinga/icinga-type.conf b/lib/icinga/icinga-type.conf
index 7d11958..16aa0fa 100644
--- a/lib/icinga/icinga-type.conf
+++ b/lib/icinga/icinga-type.conf
@@ -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 "*"
 	},
diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp
index d11c86a..1698877 100644
--- a/lib/icinga/notification.cpp
+++ b/lib/icinga/notification.cpp
@@ -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));
 	}
 }
 
diff --git a/lib/icinga/notification.h b/lib/icinga/notification.h
index ee9c084..4188c0f 100644
--- a/lib/icinga/notification.h
+++ b/lib/icinga/notification.h
@@ -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);
 };
 
 }





More information about the icinga-checkins mailing list