]> granicus.if.org Git - icinga2/commitdiff
Implement downtime notifications.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 18 Mar 2013 11:55:41 +0000 (12:55 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 18 Mar 2013 11:55:41 +0000 (12:55 +0100)
lib/icinga/pluginnotificationtask.cpp
lib/icinga/service-check.cpp
lib/icinga/service-downtime.cpp
lib/icinga/service.cpp
lib/icinga/service.h

index 4a565c681f8c3d1ab6f08c317024ce20cee0a138..217df959a0ff8f061f1d57f413573204dac8845b 100644 (file)
@@ -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);
 
index f0c918f5ce90d5b0aae24539859403cdd0c17a31..44d8542c1694f569dcde6f2be7614cb2e818c49e 100644 (file)
@@ -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);
 }
index 01401b0d450c7bfe85083c9d208184f91e870dfa..7d15eb1a82abd0f9b7817d9fd39b8a2f5e56fcd0 100644 (file)
@@ -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);
        }
 }
index 24166b0b95d1ecaf3930aae72487b7ed51612595..6314030a20c0a925afc36c1787dbc6b7def95d88 100644 (file)
@@ -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);
index 24b61bfb74e2cfa09c5a720dd10c18e5fd1b3d29..b6052c43c1c72916bbacb2fc862419ddd1390cb1 100644 (file)
@@ -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;