From: Gunnar Beutner Date: Mon, 18 Mar 2013 11:55:41 +0000 (+0100) Subject: Implement downtime notifications. X-Git-Tag: v0.0.2~217 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0744397427b8a0bd80a41806caec387784d93e59;p=icinga2 Implement downtime notifications. --- diff --git a/lib/icinga/pluginnotificationtask.cpp b/lib/icinga/pluginnotificationtask.cpp index 4a565c681..217df959a 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(static_cast(arguments[2])); + NotificationType type = static_cast(static_cast(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(); + notificationMacros->Set("NOTIFICATIONTYPE", Notification::NotificationTypeToString(type)); + + std::vector 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::SplitCommand(command), macros); diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp index f0c918f5c..44d8542c1 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 01401b0d4..7d15eb1a8 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 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 24166b0b9..6314030a2 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 24b61bfb7..b6052c43c 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -287,6 +287,7 @@ private: Attribute m_LastResult; Attribute m_LastStateChange; Attribute m_LastHardStateChange; + Attribute m_LastInDowntime; Attribute m_EnableActiveChecks; Attribute m_EnablePassiveChecks; Attribute m_ForceNextCheck;