]> granicus.if.org Git - icinga2/commitdiff
DB IDO: Fix that downtime is not in effect after restart
authorMichael Friedrich <michael.friedrich@netways.de>
Wed, 23 Mar 2016 12:42:00 +0000 (13:42 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Wed, 23 Mar 2016 12:42:00 +0000 (13:42 +0100)
fixes #10843

lib/db_ido/dbevents.cpp

index e621ea8e55a8e0ede53199858f1e3d09839de9ff..3b34974a3ff3ef9346f5a85bda80c2b479adb013 100644 (file)
@@ -505,8 +505,9 @@ void DbEvents::AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime
        fields1->Set("duration", downtime->GetDuration());
        fields1->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
        fields1->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
-       fields1->Set("was_started", 0);
-       fields1->Set("is_in_effect", 0);
+       fields1->Set("was_started", ((downtime->GetStartTime() <= Utility::GetTime()) ? 1 : 0));
+       fields1->Set("is_in_effect", (downtime->IsActive() ? 1 : 0));
+       fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
        String node = IcingaApplication::GetInstance()->GetNodeName();
@@ -527,6 +528,39 @@ void DbEvents::AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime
        query1.Fields = fields1;
 
        queries.push_back(query1);
+
+       /* host/service status */
+       if (!historical) {
+               Host::Ptr host;
+               Service::Ptr service;
+               tie(host, service) = GetHostService(checkable);
+
+               DbQuery query2;
+               if (service)
+                       query2.Table = "servicestatus";
+               else
+                       query2.Table = "hoststatus";
+
+               query2.Type = DbQueryUpdate;
+               query2.Category = DbCatState;
+               query2.StatusUpdate = true;
+               query2.Object = DbObject::GetOrCreateByObject(checkable);
+
+               Dictionary::Ptr fields2 = new Dictionary();
+               fields2->Set("scheduled_downtime_depth", checkable->GetDowntimeDepth());
+
+               query2.Fields = fields2;
+
+               query2.WhereCriteria = new Dictionary();
+               if (service)
+                       query2.WhereCriteria->Set("service_object_id", service);
+               else
+                       query2.WhereCriteria->Set("host_object_id", host);
+
+               query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+               queries.push_back(query2);
+       }
 }
 
 void DbEvents::RemoveDowntime(const Downtime::Ptr& downtime)
@@ -564,6 +598,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downt
        fields3->Set("was_cancelled", downtime->GetWasCancelled() ? 1 : 0);
        fields3->Set("actual_end_time", DbValue::FromTimestamp(time_bag.first));
        fields3->Set("actual_end_time_usec", time_bag.second);
+       fields3->Set("is_in_effect", 0);
        query3.Fields = fields3;
 
        query3.WhereCriteria = new Dictionary();
@@ -623,7 +658,7 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime)
        fields1->Set("was_started", 1);
        fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first));
        fields1->Set("actual_start_time_usec", time_bag.second);
-       fields1->Set("is_in_effect", 1);
+       fields1->Set("is_in_effect", (downtime->IsActive() ? 1 : 0));
        fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
        fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */