mirror of https://github.com/Icinga/icinga2.git
Implement downtime notifications.
This commit is contained in:
parent
9e1f48049e
commit
0744397427
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -141,10 +141,19 @@ void Service::TriggerDowntimes(void)
|
|||
if (!downtimes)
|
||||
return;
|
||||
|
||||
ObjectLock olock(downtimes);
|
||||
std::vector<String> ids;
|
||||
|
||||
String id;
|
||||
BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), downtimes) {
|
||||
{
|
||||
ObjectLock olock(downtimes);
|
||||
|
||||
String id;
|
||||
BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), downtimes) {
|
||||
ids.push_back(id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FOREACH(const String& id, ids) {
|
||||
TriggerDowntime(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue