diff --git a/components/cluster/clustercomponent.cpp b/components/cluster/clustercomponent.cpp index 07319631d..ae6f1a42e 100644 --- a/components/cluster/clustercomponent.cpp +++ b/components/cluster/clustercomponent.cpp @@ -1294,7 +1294,7 @@ void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Diction String id = params->Get("id"); - service->RemoveDowntime(id, sender->GetName()); + service->RemoveDowntime(id, false, sender->GetName()); RelayMessage(sender, message, true); } else if (message->Get("method") == "cluster::SetAcknowledgement") { diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index aa1b9ca62..b2023ec8d 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -898,7 +898,7 @@ void ExternalCommandProcessor::DelSvcDowntime(double, const std::vector& int id = Convert::ToLong(arguments[0]); Log(LogInformation, "icinga", "Removing downtime ID " + arguments[0]); String rid = Service::GetDowntimeIDFromLegacyID(id); - Service::RemoveDowntime(rid); + Service::RemoveDowntime(rid, true); } void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vector& arguments) @@ -931,7 +931,7 @@ void ExternalCommandProcessor::DelHostDowntime(double, const std::vector int id = Convert::ToLong(arguments[0]); Log(LogInformation, "icinga", "Removing downtime ID " + arguments[0]); String rid = Service::GetDowntimeIDFromLegacyID(id); - Service::RemoveDowntime(rid); + Service::RemoveDowntime(rid, true); } void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector& arguments) diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp index 404c5d6c2..1767f6ff2 100644 --- a/lib/icinga/service-downtime.cpp +++ b/lib/icinga/service-downtime.cpp @@ -116,12 +116,14 @@ String Service::AddDowntime(const String& comment_id, l_DowntimesCache[uid] = GetSelf(); } + Log(LogWarning, "icinga", "added downtime with ID '" + downtime->Get("legacy_id") + "'."); + Utility::QueueAsyncCallback(boost::bind(boost::ref(OnDowntimeAdded), GetSelf(), downtime, authority)); return uid; } -void Service::RemoveDowntime(const String& id, const String& authority) +void Service::RemoveDowntime(const String& id, const bool& cancelled, const String& authority) { Service::Ptr owner = GetOwnerByDowntimeID(id); @@ -149,9 +151,13 @@ void Service::RemoveDowntime(const String& id, const String& authority) l_LegacyDowntimesCache.erase(legacy_id); l_DowntimesCache.erase(id); } - + RemoveComment(comment_id); + downtime->Set("was_cancelled", cancelled); + + Log(LogWarning, "icinga", "removed downtime with ID '" + downtime->Get("legacy_id") + "' from service '" + owner->GetName() + "'."); + Utility::QueueAsyncCallback(boost::bind(boost::ref(OnDowntimeRemoved), owner, downtime, authority)); } @@ -186,12 +192,24 @@ void Service::TriggerDowntime(const String& id) if (!downtime) return; + if (IsDowntimeActive(downtime) && IsDowntimeTriggered(downtime)) { + Log(LogWarning, "icinga", "not triggering downtime with ID '" + downtime->Get("legacy_id") + "': already triggered."); + return; + } + + if (IsDowntimeExpired(downtime)) { + Log(LogWarning, "icinga", "not triggering downtime with ID '" + downtime->Get("legacy_id") + "': expired."); + return; + } + double now = Utility::GetTime(); if (now < downtime->Get("start_time") || now > downtime->Get("end_time")) return; + Log(LogWarning, "icinga", "triggering downtime with ID '" + downtime->Get("legacy_id") + "'."); + if (downtime->Get("trigger_time") == 0) downtime->Set("trigger_time", now); @@ -257,6 +275,15 @@ bool Service::IsDowntimeActive(const Dictionary::Ptr& downtime) return (triggerTime + downtime->Get("duration") < now); } +bool Service::IsDowntimeTriggered(const Dictionary::Ptr& downtime) +{ + double now = Utility::GetTime(); + + double triggerTime = downtime->Get("trigger_time"); + + return (triggerTime > 0 && triggerTime <= now); +} + bool Service::IsDowntimeExpired(const Dictionary::Ptr& downtime) { return (downtime->Get("end_time") < Utility::GetTime()); @@ -310,7 +337,7 @@ void Service::RemoveExpiredDowntimes(void) if (!expiredDowntimes.empty()) { BOOST_FOREACH(const String& id, expiredDowntimes) { - RemoveDowntime(id); + RemoveDowntime(id, false); } } } diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 9b17829db..aeed0693f 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -262,7 +262,7 @@ public: const String& triggeredBy, double duration, const String& id = String(), const String& authority = String()); - static void RemoveDowntime(const String& id, const String& = String()); + static void RemoveDowntime(const String& id, const bool& cancelled, const String& = String()); void TriggerDowntimes(void); static void TriggerDowntime(const String& id); @@ -272,6 +272,7 @@ public: static Dictionary::Ptr GetDowntimeByID(const String& id); static bool IsDowntimeActive(const Dictionary::Ptr& downtime); + static bool IsDowntimeTriggered(const Dictionary::Ptr& downtime); static bool IsDowntimeExpired(const Dictionary::Ptr& downtime); bool IsInDowntime(void) const;