[icinga-checkins] icinga.org: icinga2/master: Implement downtime notifications.

git at icinga.org git at icinga.org
Mon Mar 18 12:55:47 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon Mar 18 12:55:41 2013 +0100

Implement downtime notifications.

---

 lib/icinga/pluginnotificationtask.cpp |   13 +++++++++++--
 lib/icinga/service-check.cpp          |   10 +++++++++-
 lib/icinga/service-downtime.cpp       |   15 ++++++++++++---
 lib/icinga/service.cpp                |    1 +
 lib/icinga/service.h                  |    1 +
 5 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/lib/icinga/pluginnotificationtask.cpp b/lib/icinga/pluginnotificationtask.cpp
index 4a565c6..217df95 100644
--- a/lib/icinga/pluginnotificationtask.cpp
+++ b/lib/icinga/pluginnotificationtask.cpp
@@ -50,7 +50,7 @@ void PluginNotificationTask::ScriptFunc(const ScriptTask::Ptr& task, const std::
 
 	Notification::Ptr notification = arguments[0];
 	Dictionary::Ptr macros = arguments[1];
-//	NotificationType type = static_cast<NotificationType>(static_cast<int>(arguments[2]));
+	NotificationType type = static_cast<NotificationType>(static_cast<int>(arguments[2]));
 
 	Value raw_command = notification->GetNotificationCommand();
 
@@ -60,7 +60,16 @@ void PluginNotificationTask::ScriptFunc(const ScriptTask::Ptr& task, const std::
 	if (service)
 		service_name = service->GetName();
 
-	Value command = MacroProcessor::ResolveMacros(raw_command, macros);
+	Dictionary::Ptr notificationMacros = boost::make_shared<Dictionary>();
+	notificationMacros->Set("NOTIFICATIONTYPE", Notification::NotificationTypeToString(type));
+
+	std::vector<Dictionary::Ptr> macroDicts;
+	macroDicts.push_back(notificationMacros);
+	macroDicts.push_back(macros);
+
+	Dictionary::Ptr allMacros = MacroProcessor::MergeMacroDicts(macroDicts);
+
+	Value command = MacroProcessor::ResolveMacros(raw_command, allMacros);
 
 	Process::Ptr process = boost::make_shared<Process>(Process::SplitCommand(command), macros);
 
diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp
index f0c918f..44d8542 100644
--- a/lib/icinga/service-check.cpp
+++ b/lib/icinga/service-check.cpp
@@ -473,7 +473,12 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
 
 	Service::UpdateStatistics(cr);
 
-	bool send_notification = hardChange && reachable && !IsInDowntime() && !IsAcknowledged();
+	bool in_downtime = IsInDowntime();
+	bool send_notification = hardChange && reachable && !in_downtime && !IsAcknowledged();
+
+	bool send_downtime_notification = m_LastInDowntime != in_downtime;
+	m_LastInDowntime = in_downtime;
+	Touch("last_in_downtime");
 
 	olock.Unlock();
 
@@ -502,6 +507,9 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
 
 	EndpointManager::GetInstance()->SendMulticastMessage(rm);
 
+	if (send_downtime_notification)
+		RequestNotifications(in_downtime ? NotificationDowntimeStart : NotificationDowntimeEnd, cr);
+
 	if (send_notification)
 		RequestNotifications(recovery ? NotificationRecovery : NotificationProblem, cr);
 }
diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp
index 01401b0..7d15eb1 100644
--- a/lib/icinga/service-downtime.cpp
+++ b/lib/icinga/service-downtime.cpp
@@ -141,10 +141,19 @@ void Service::TriggerDowntimes(void)
 	if (!downtimes)
 		return;
 
-	ObjectLock olock(downtimes);
+	std::vector<String> ids;
+
+	{
+		ObjectLock olock(downtimes);
+
+		String id;
+		BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), downtimes) {
+			ids.push_back(id);
+
+		}
+	}
 
-	String id;
-	BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), downtimes) {
+	BOOST_FOREACH(const String& id, ids) {
 		TriggerDowntime(id);
 	}
 }
diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp
index 24166b0..6314030 100644
--- a/lib/icinga/service.cpp
+++ b/lib/icinga/service.cpp
@@ -58,6 +58,7 @@ Service::Service(const Dictionary::Ptr& serializedObject)
 	RegisterAttribute("last_result", Attribute_Replicated, &m_LastResult);
 	RegisterAttribute("last_state_change", Attribute_Replicated, &m_LastStateChange);
 	RegisterAttribute("last_hard_state_change", Attribute_Replicated, &m_LastHardStateChange);
+	RegisterAttribute("last_in_downtime", Attribute_Replicated, &m_LastInDowntime);
 	RegisterAttribute("enable_active_checks", Attribute_Replicated, &m_EnableActiveChecks);
 	RegisterAttribute("enable_passive_checks", Attribute_Replicated, &m_EnablePassiveChecks);
 	RegisterAttribute("force_next_check", Attribute_Replicated, &m_ForceNextCheck);
diff --git a/lib/icinga/service.h b/lib/icinga/service.h
index 24b61bf..b6052c4 100644
--- a/lib/icinga/service.h
+++ b/lib/icinga/service.h
@@ -287,6 +287,7 @@ private:
 	Attribute<Dictionary::Ptr> m_LastResult;
 	Attribute<double> m_LastStateChange;
 	Attribute<double> m_LastHardStateChange;
+	Attribute<bool> m_LastInDowntime;
 	Attribute<bool> m_EnableActiveChecks;
 	Attribute<bool> m_EnablePassiveChecks;
 	Attribute<bool> m_ForceNextCheck;





More information about the icinga-checkins mailing list