]> granicus.if.org Git - icinga2/commitdiff
Add RemoveDowntime() cancelled parameter, check for expired/triggered downtimes.
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 17 Sep 2013 17:37:10 +0000 (19:37 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 17 Sep 2013 17:37:10 +0000 (19:37 +0200)
refs #4652
refs #4710

components/cluster/clustercomponent.cpp
lib/icinga/externalcommandprocessor.cpp
lib/icinga/service-downtime.cpp
lib/icinga/service.h

index 07319631d786b8dd3583dfc0d6408e96e7e86bcd..ae6f1a42ee80c4000c0043c56ac9c16d9b8894a2 100644 (file)
@@ -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") {
index aa1b9ca62b08cf279b6623ac63e3d7e7ccfd8bcb..b2023ec8d66abffc92d1b01c5663e7e54ba51c8a 100644 (file)
@@ -898,7 +898,7 @@ void ExternalCommandProcessor::DelSvcDowntime(double, const std::vector<String>&
        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<String>& arguments)
@@ -931,7 +931,7 @@ void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>
        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<String>& arguments)
index 404c5d6c26238008e46ce755b239454ae84f53c5..1767f6ff2f05d6c1e67191b09ec4de30e47292e5 100644 (file)
@@ -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);
                }
        }
 }
index 9b17829dbebc0c69431bd261d084259abb4e1c7e..aeed0693f621ef6588d63511a3b60e063f49ca57 100644 (file)
@@ -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;