]> granicus.if.org Git - icinga2/commitdiff
ido: Add acknowledgements.
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 24 Sep 2013 09:49:02 +0000 (11:49 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 24 Sep 2013 11:38:09 +0000 (13:38 +0200)
refs #4379

lib/ido/servicedbobject.cpp
lib/ido/servicedbobject.h

index 9cef308af646b49e5ef88fb585e9b51350817089..a32d64be0969c0c5813d480dd0026db16d112a15 100644 (file)
@@ -40,11 +40,16 @@ INITIALIZE_ONCE(ServiceDbObject, &ServiceDbObject::StaticInitialize);
 
 void ServiceDbObject::StaticInitialize(void)
 {
+       /* Status */
        Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddComment, _1, _2));
        Service::OnCommentRemoved.connect(boost::bind(&ServiceDbObject::RemoveComment, _1, _2));
        Service::OnDowntimeAdded.connect(boost::bind(&ServiceDbObject::AddDowntime, _1, _2));
        Service::OnDowntimeRemoved.connect(boost::bind(&ServiceDbObject::RemoveDowntime, _1, _2));
        Service::OnDowntimeTriggered.connect(boost::bind(&ServiceDbObject::TriggerDowntime, _1, _2));
+
+       /* History */
+       Service::OnAcknowledgementSet.connect(boost::bind(&ServiceDbObject::AddAcknowledgement, _1, _2, _3, _4, _5, _6));
+
 }
 
 ServiceDbObject::ServiceDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
@@ -603,6 +608,7 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction
        fields1->Set("actual_start_time_usec", actual_start_time_usec);
        fields1->Set("is_in_effect", 1);
        fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->Get("trigger_time")));
+       fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
        query1.WhereCriteria = boost::make_shared<Dictionary>();
        query1.WhereCriteria->Set("object_id", service);
@@ -624,6 +630,7 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction
                fields2->Set("actual_start_time_usec", actual_start_time_usec);
                fields2->Set("is_in_effect", 1);
                fields2->Set("trigger_time", DbValue::FromTimestamp(downtime->Get("trigger_time")));
+               fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
 
                query2.WhereCriteria = boost::make_shared<Dictionary>();
                query2.WhereCriteria->Set("object_id", host);
@@ -633,3 +640,62 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction
                OnQuery(query2);
        }
 }
+
+void ServiceDbObject::AddAcknowledgement(const Service::Ptr& service, const String& author, const String& comment,
+                                        AcknowledgementType type, double expiry, const String& authority)
+{
+       Host::Ptr host = service->GetHost();
+
+       if (!host)
+               return;
+
+       Log(LogDebug, "ido", "add acknowledgement for '" + service->GetName() + "'");
+
+       double now = Utility::GetTime();
+       unsigned long entry_time = static_cast<long>(now);
+       unsigned long entry_time_usec = (now - entry_time) * 1000 * 1000;
+       unsigned long end_time = static_cast<long>(expiry);
+
+       DbQuery query1;
+       query1.Table = "acknowledgements";
+       query1.Type = DbQueryInsert;
+
+       Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
+       fields1->Set("entry_time", DbValue::FromTimestamp(entry_time));
+       fields1->Set("entry_time_usec", entry_time_usec);
+       fields1->Set("acknowledgement_type", type);
+       fields1->Set("object_id", service);
+       fields1->Set("state", service->GetState());
+       fields1->Set("author_name", author);
+       fields1->Set("comment_data", comment);
+       fields1->Set("is_sticky", type == AcknowledgementSticky ? 1 : 0);
+       fields1->Set("end_time", DbValue::FromTimestamp(end_time));
+       fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+       query1.Fields = fields1;
+       OnQuery(query1);
+
+       if (host->GetHostCheckService() == service) {
+
+               DbQuery query2;
+               query2.Table = "acknowledgements";
+               query2.Type = DbQueryInsert;
+
+               Dictionary::Ptr fields2 = boost::make_shared<Dictionary>();
+               fields2->Set("entry_time", DbValue::FromTimestamp(entry_time));
+               fields2->Set("entry_time_usec", entry_time_usec);
+               fields2->Set("acknowledgement_type", type);
+               fields2->Set("object_id", host);
+               fields2->Set("state", service->GetState());
+               fields2->Set("author_name", author);
+               fields2->Set("comment_data", comment);
+               fields2->Set("is_sticky", type == AcknowledgementSticky ? 1 : 0);
+               fields2->Set("end_time", DbValue::FromTimestamp(end_time));
+               fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+               query2.Fields = fields2;
+               OnQuery(query2);
+       }
+}
+
+
index 30499de559541b8fa429b3a264209524ca535a47..d3f63bd382fd46b2355b30eb62845234302a7293 100644 (file)
@@ -51,6 +51,7 @@ protected:
        virtual void OnStatusUpdate(void);
 
 private:
+        /* Status */
        static void AddComments(const Service::Ptr& service);
        static void AddComment(const Service::Ptr& service, const Dictionary::Ptr& comment);
        static void AddCommentByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& comment);
@@ -63,6 +64,10 @@ private:
         static void RemoveDowntimes(const Service::Ptr& service);
        static void RemoveDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime);
        static void TriggerDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime);
+
+        /* History */
+        static void AddAcknowledgement(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority);
+
 };
 
 }