diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index 6c96bdce6..f3b7a61d6 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -47,6 +47,8 @@ void DbEvents::StaticInitialize(void) Service::OnDowntimeAdded.connect(boost::bind(&DbEvents::AddDowntime, _1, _2)); Service::OnDowntimeRemoved.connect(boost::bind(&DbEvents::RemoveDowntime, _1, _2)); Service::OnDowntimeTriggered.connect(boost::bind(&DbEvents::TriggerDowntime, _1, _2)); + Service::OnAcknowledgementSet.connect(boost::bind(&DbEvents::AddAcknowledgement, _1, _4)); + Service::OnAcknowledgementCleared.connect(boost::bind(&DbEvents::RemoveAcknowledgement, _1)); /* History */ Service::OnCommentAdded.connect(boost::bind(&DbEvents::AddCommentHistory, _1, _2)); @@ -461,6 +463,51 @@ void DbEvents::AddAcknowledgementHistory(const Checkable::Ptr& checkable, const DbObject::OnQuery(query1); } +void DbEvents::AddAcknowledgement(const Checkable::Ptr& checkable, AcknowledgementType type) +{ + Log(LogDebug, "db_ido", "add acknowledgement for '" + checkable->GetName() + "'"); + + AddAcknowledgementInternal(checkable, type, true); +} + +void DbEvents::RemoveAcknowledgement(const Checkable::Ptr& checkable) +{ + Log(LogDebug, "db_ido", "remove acknowledgement for '" + checkable->GetName() + "'"); + + AddAcknowledgementInternal(checkable, AcknowledgementNone, false); +} + +void DbEvents::AddAcknowledgementInternal(const Checkable::Ptr& checkable, AcknowledgementType type, bool add) +{ + Host::Ptr host; + Service::Ptr service; + tie(host, service) = GetHostService(checkable); + + DbQuery query1; + if (service) + query1.Table = "servicestatus"; + else + query1.Table = "hoststatus"; + + query1.Type = DbQueryUpdate; + query1.Category = DbCatAcknowledgement; + + Dictionary::Ptr fields1 = make_shared(); + fields1->Set("acknowledgement_type", type); + fields1->Set("problem_has_been_acknowledged", add ? 1 : 0); + query1.Fields = fields1; + + query1.WhereCriteria = make_shared(); + if (service) + query1.WhereCriteria->Set("service_object_id", service); + else + query1.WhereCriteria->Set("host_object_id", host); + + query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ + + DbObject::OnQuery(query1); +} + /* notifications */ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set& users, NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text) diff --git a/lib/db_ido/dbevents.h b/lib/db_ido/dbevents.h index 97fd0f993..4ba36f6f0 100644 --- a/lib/db_ido/dbevents.h +++ b/lib/db_ido/dbevents.h @@ -79,6 +79,10 @@ public: static void RemoveDowntime(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime); static void TriggerDowntime(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime); + static void AddAcknowledgement(const Checkable::Ptr& checkable, AcknowledgementType type); + static void RemoveAcknowledgement(const Checkable::Ptr& checkable); + static void AddAcknowledgementInternal(const Checkable::Ptr& checkable, AcknowledgementType type, bool add); + /* comment, downtime, acknowledgement history */ static void AddCommentHistory(const Checkable::Ptr& checkable, const Comment::Ptr& comment); static void AddDowntimeHistory(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime);