From 829d07aefe4973ad222217bf34107db6d47a4274 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 4 Dec 2019 15:19:03 +0100 Subject: [PATCH] Introduce Checkable#acknowledgement_last_change refs #7689 --- lib/db_ido/dbevents.cpp | 2 +- lib/icinga/apiactions.cpp | 2 +- lib/icinga/apievents.cpp | 4 ++-- lib/icinga/apievents.hpp | 4 ++-- lib/icinga/checkable.cpp | 16 ++++++++++------ lib/icinga/checkable.hpp | 8 ++++---- lib/icinga/checkable.ti | 1 + lib/icinga/clusterevents.cpp | 10 ++++++---- lib/icinga/clusterevents.hpp | 4 ++-- lib/icingadb/icingadb-objects.cpp | 26 +++++++++++++------------- lib/icingadb/icingadb.hpp | 8 ++++---- 11 files changed, 46 insertions(+), 39 deletions(-) diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index 68bef4f8a..5bd74f289 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -49,7 +49,7 @@ void DbEvents::StaticInitialize() /* History */ Comment::OnCommentAdded.connect(std::bind(&DbEvents::AddCommentHistory, _1)); Downtime::OnDowntimeAdded.connect(std::bind(&DbEvents::AddDowntimeHistory, _1)); - Checkable::OnAcknowledgementSet.connect(std::bind(&DbEvents::AddAcknowledgementHistory, _1, _2, _3, _4, _5, _6)); + Checkable::OnAcknowledgementSet.connect(std::bind(&DbEvents::AddAcknowledgementHistory, _1, _2, _3, _4, _5, _7)); Checkable::OnNotificationSentToAllUsers.connect(std::bind(&DbEvents::AddNotificationHistory, _1, _2, _3, _4, _5, _6, _7)); diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 875fc2a3f..8a7e8a9a8 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -235,7 +235,7 @@ Dictionary::Ptr ApiActions::AcknowledgeProblem(const ConfigObject::Ptr& object, Comment::AddComment(checkable, CommentAcknowledgement, HttpUtility::GetLastParameter(params, "author"), HttpUtility::GetLastParameter(params, "comment"), persistent, timestamp); checkable->AcknowledgeProblem(HttpUtility::GetLastParameter(params, "author"), - HttpUtility::GetLastParameter(params, "comment"), sticky, notify, persistent, timestamp); + HttpUtility::GetLastParameter(params, "comment"), sticky, notify, persistent, Utility::GetTime(), timestamp); return ApiActions::CreateResult(200, "Successfully acknowledged problem for object '" + checkable->GetName() + "'."); } diff --git a/lib/icinga/apievents.cpp b/lib/icinga/apievents.cpp index 1bec0e35a..375ffe2fd 100644 --- a/lib/icinga/apievents.cpp +++ b/lib/icinga/apievents.cpp @@ -182,7 +182,7 @@ void ApiEvents::FlappingChangedHandler(const Checkable::Ptr& checkable, const Me void ApiEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, - bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin) + bool notify, bool persistent, double, double expiry, const MessageOrigin::Ptr& origin) { std::vector queues = EventQueue::GetQueuesForType("AcknowledgementSet"); auto inboxes (EventsRouter::GetInstance().GetInboxes(EventType::AcknowledgementSet)); @@ -221,7 +221,7 @@ void ApiEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable, inboxes.Push(std::move(result)); } -void ApiEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, const MessageOrigin::Ptr& origin) +void ApiEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double, const MessageOrigin::Ptr& origin) { std::vector queues = EventQueue::GetQueuesForType("AcknowledgementCleared"); auto inboxes (EventsRouter::GetInstance().GetInboxes(EventType::AcknowledgementCleared)); diff --git a/lib/icinga/apievents.hpp b/lib/icinga/apievents.hpp index cc9f1b1a5..67dca6238 100644 --- a/lib/icinga/apievents.hpp +++ b/lib/icinga/apievents.hpp @@ -29,8 +29,8 @@ public: static void AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, - bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin); - static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, const MessageOrigin::Ptr& origin); + bool notify, bool persistent, double, double expiry, const MessageOrigin::Ptr& origin); + static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double, const MessageOrigin::Ptr& origin); static void CommentAddedHandler(const Comment::Ptr& comment); static void CommentRemovedHandler(const Comment::Ptr& comment); diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index e5362bb86..8690bf56e 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -15,8 +15,8 @@ using namespace icinga; REGISTER_TYPE_WITH_PROTOTYPE(Checkable, Checkable::GetPrototype()); INITIALIZE_ONCE(&Checkable::StaticInitialize); -boost::signals2::signal Checkable::OnAcknowledgementSet; -boost::signals2::signal Checkable::OnAcknowledgementCleared; +boost::signals2::signal Checkable::OnAcknowledgementSet; +boost::signals2::signal Checkable::OnAcknowledgementCleared; static Timer::Ptr l_CheckablesFireSuppressedNotifications; @@ -122,7 +122,7 @@ bool Checkable::IsAcknowledged() const return const_cast(this)->GetAcknowledgement() != AcknowledgementNone; } -void Checkable::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin) +void Checkable::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify, bool persistent, double changeTime, double expiry, const MessageOrigin::Ptr& origin) { SetAcknowledgementRaw(type); SetAcknowledgementExpiry(expiry); @@ -133,10 +133,12 @@ void Checkable::AcknowledgeProblem(const String& author, const String& comment, Log(LogInformation, "Checkable") << "Acknowledgement set for checkable '" << GetName() << "'."; - OnAcknowledgementSet(this, author, comment, type, notify, persistent, expiry, origin); + OnAcknowledgementSet(this, author, comment, type, notify, persistent, changeTime, expiry, origin); + + SetAcknowledgementLastChange(changeTime); } -void Checkable::ClearAcknowledgement(const String& removedBy, const MessageOrigin::Ptr& origin) +void Checkable::ClearAcknowledgement(const String& removedBy, double changeTime, const MessageOrigin::Ptr& origin) { ObjectLock oLock (this); @@ -157,7 +159,9 @@ void Checkable::ClearAcknowledgement(const String& removedBy, const MessageOrigi << "Acknowledgement cleared for checkable '" << GetName() << "'."; if (wasAcked) { - OnAcknowledgementCleared(this, removedBy, origin); + OnAcknowledgementCleared(this, removedBy, changeTime, origin); + + SetAcknowledgementLastChange(changeTime); } } diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index b9130f87a..85a2cd7f9 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -68,8 +68,8 @@ public: AcknowledgementType GetAcknowledgement(); - void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify = true, bool persistent = false, double expiry = 0, const MessageOrigin::Ptr& origin = nullptr); - void ClearAcknowledgement(const String& removedBy, const MessageOrigin::Ptr& origin = nullptr); + void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify = true, bool persistent = false, double changeTime = Utility::GetTime(), double expiry = 0, const MessageOrigin::Ptr& origin = nullptr); + void ClearAcknowledgement(const String& removedBy, double changeTime = Utility::GetTime(), const MessageOrigin::Ptr& origin = nullptr); int GetSeverity() const override; bool GetProblem() const override; @@ -112,8 +112,8 @@ public: const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&)> OnNotificationSentToAllUsers; static boost::signals2::signal OnAcknowledgementSet; - static boost::signals2::signal OnAcknowledgementCleared; + bool, bool, double, double, const MessageOrigin::Ptr&)> OnAcknowledgementSet; + static boost::signals2::signal OnAcknowledgementCleared; static boost::signals2::signal OnNextCheckUpdated; static boost::signals2::signal OnEventCommandExecuted; diff --git a/lib/icinga/checkable.ti b/lib/icinga/checkable.ti index 72eb52781..98d18cd7f 100644 --- a/lib/icinga/checkable.ti +++ b/lib/icinga/checkable.ti @@ -147,6 +147,7 @@ abstract class Checkable : CustomVarObject default {{{ return AcknowledgementNone; }}} }; [state] Timestamp acknowledgement_expiry; + [state] Timestamp acknowledgement_last_change; [state] bool force_next_notification; [no_storage] Timestamp last_check { get; diff --git a/lib/icinga/clusterevents.cpp b/lib/icinga/clusterevents.cpp index 8309f2212..bc2728e4a 100644 --- a/lib/icinga/clusterevents.cpp +++ b/lib/icinga/clusterevents.cpp @@ -473,7 +473,7 @@ Value ClusterEvents::ForceNextNotificationChangedAPIHandler(const MessageOrigin: void ClusterEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, - bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin) + bool notify, bool persistent, double changeTime, double expiry, const MessageOrigin::Ptr& origin) { ApiListener::Ptr listener = ApiListener::GetInstance(); @@ -494,6 +494,7 @@ void ClusterEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable, params->Set("notify", notify); params->Set("persistent", persistent); params->Set("expiry", expiry); + params->Set("change_time", changeTime); Dictionary::Ptr message = new Dictionary(); message->Set("jsonrpc", "2.0"); @@ -546,12 +547,12 @@ Value ClusterEvents::AcknowledgementSetAPIHandler(const MessageOrigin::Ptr& orig checkable->AcknowledgeProblem(params->Get("author"), params->Get("comment"), static_cast(static_cast(params->Get("acktype"))), - params->Get("notify"), params->Get("persistent"), params->Get("expiry"), origin); + params->Get("notify"), params->Get("persistent"), params->Get("change_time"), params->Get("expiry"), origin); return Empty; } -void ClusterEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, const MessageOrigin::Ptr& origin) +void ClusterEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double changeTime, const MessageOrigin::Ptr& origin) { ApiListener::Ptr listener = ApiListener::GetInstance(); @@ -567,6 +568,7 @@ void ClusterEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkabl if (service) params->Set("service", service->GetShortName()); params->Set("author", removedBy); + params->Set("change_time", changeTime); Dictionary::Ptr message = new Dictionary(); message->Set("jsonrpc", "2.0"); @@ -608,7 +610,7 @@ Value ClusterEvents::AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr& return Empty; } - checkable->ClearAcknowledgement(params->Get("author"), origin); + checkable->ClearAcknowledgement(params->Get("author"), params->Get("change_time"), origin); return Empty; } diff --git a/lib/icinga/clusterevents.hpp b/lib/icinga/clusterevents.hpp index d814ebd49..fb876fcf9 100644 --- a/lib/icinga/clusterevents.hpp +++ b/lib/icinga/clusterevents.hpp @@ -39,10 +39,10 @@ public: static Value ForceNextNotificationChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); static void AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, - bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin); + bool notify, bool persistent, double changeTime, double expiry, const MessageOrigin::Ptr& origin); static Value AcknowledgementSetAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, const MessageOrigin::Ptr& origin); + static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double changeTime, const MessageOrigin::Ptr& origin); static Value AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); static Value ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index 0969321c9..00d479f79 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -60,15 +60,15 @@ void IcingaDB::ConfigStaticInitialize() IcingaDB::StateChangeHandler(checkable, cr, type); }); - Checkable::OnAcknowledgementSet.connect([](const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool, bool persistent, double expiry, const MessageOrigin::Ptr&) { - AcknowledgementSetHandler(checkable, author, comment, type, persistent, expiry); + Checkable::OnAcknowledgementSet.connect([](const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool, bool persistent, double changeTime, double expiry, const MessageOrigin::Ptr&) { + AcknowledgementSetHandler(checkable, author, comment, type, persistent, changeTime, expiry); }); - Checkable::OnAcknowledgementCleared.connect([](const Checkable::Ptr& checkable, const String& removedBy, const MessageOrigin::Ptr&) { - AcknowledgementClearedHandler(checkable, removedBy); + Checkable::OnAcknowledgementCleared.connect([](const Checkable::Ptr& checkable, const String& removedBy, double changeTime, const MessageOrigin::Ptr&) { + AcknowledgementClearedHandler(checkable, removedBy, changeTime); }); /* triggered when acknowledged host/service goes back to ok and when the acknowledgement gets deleted */ - Checkable::OnAcknowledgementCleared.connect([](const Checkable::Ptr& checkable, const String&, const MessageOrigin::Ptr&) { + Checkable::OnAcknowledgementCleared.connect([](const Checkable::Ptr& checkable, const String&, double, const MessageOrigin::Ptr&) { IcingaDB::StateChangeHandler(checkable); }); @@ -1669,7 +1669,7 @@ void IcingaDB::SendNextUpdate(const Checkable::Ptr& checkable) ); } -void IcingaDB::SendAcknowledgementSet(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double expiry) +void IcingaDB::SendAcknowledgementSet(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double changeTime, double expiry) { if (!m_Rcon || !m_Rcon->IsConnected()) return; @@ -1683,7 +1683,7 @@ void IcingaDB::SendAcknowledgementSet(const Checkable::Ptr& checkable, const Str "id", Utility::NewUniqueID(), "environment_id", SHA1(GetEnvironment()), "host_id", GetObjectIdentifier(host), - "event_time", Convert::ToString(TimestampToMilliseconds(Utility::GetTime())), + "event_time", Convert::ToString(TimestampToMilliseconds(changeTime)), "event_type", "ack_set", "author", author, "comment", comment, @@ -1716,7 +1716,7 @@ void IcingaDB::SendAcknowledgementSet(const Checkable::Ptr& checkable, const Str m_Rcon->FireAndForgetQuery(std::move(xAdd), Prio::History); } -void IcingaDB::SendAcknowledgementCleared(const Checkable::Ptr& checkable, const String& removedBy) +void IcingaDB::SendAcknowledgementCleared(const Checkable::Ptr& checkable, const String& removedBy, double changeTime) { if (!m_Rcon || !m_Rcon->IsConnected()) return; @@ -1730,7 +1730,7 @@ void IcingaDB::SendAcknowledgementCleared(const Checkable::Ptr& checkable, const "id", Utility::NewUniqueID(), "environment_id", SHA1(GetEnvironment()), "host_id", GetObjectIdentifier(host), - "event_time", Convert::ToString(TimestampToMilliseconds(Utility::GetTime())), + "event_time", Convert::ToString(TimestampToMilliseconds(changeTime)), "event_type", "ack_clear", "author", removedBy }); @@ -2007,7 +2007,7 @@ struct AuthorComment String Comment; }; -void IcingaDB::AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double expiry) +void IcingaDB::AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double changeTime, double expiry) { auto rws (ConfigType::GetObjectsByType()); @@ -2015,12 +2015,12 @@ void IcingaDB::AcknowledgementSetHandler(const Checkable::Ptr& checkable, const auto ac (Shared::Make(AuthorComment{author, comment})); for (auto& rw : rws) { - rw->m_WorkQueue.Enqueue([rw, checkable, ac, type, persistent, expiry]() { rw->SendAcknowledgementSet(checkable, ac->Author, ac->Comment, type, persistent, expiry); }); + rw->m_WorkQueue.Enqueue([rw, checkable, ac, type, persistent, changeTime, expiry]() { rw->SendAcknowledgementSet(checkable, ac->Author, ac->Comment, type, persistent, changeTime, expiry); }); } } } -void IcingaDB::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy) +void IcingaDB::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double changeTime) { auto rws (ConfigType::GetObjectsByType()); @@ -2028,7 +2028,7 @@ void IcingaDB::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, co auto rb (Shared::Make(removedBy)); for (auto& rw : rws) { - rw->m_WorkQueue.Enqueue([rw, checkable, rb]() { rw->SendAcknowledgementCleared(checkable, *rb); }); + rw->m_WorkQueue.Enqueue([rw, checkable, rb, changeTime]() { rw->SendAcknowledgementCleared(checkable, *rb, changeTime); }); } } } diff --git a/lib/icingadb/icingadb.hpp b/lib/icingadb/icingadb.hpp index 0ed792030..c5200330c 100644 --- a/lib/icingadb/icingadb.hpp +++ b/lib/icingadb/icingadb.hpp @@ -67,8 +67,8 @@ private: void SendRemovedComment(const Comment::Ptr& comment); void SendFlappingChanged(const Checkable::Ptr& checkable, const Value& value); void SendNextUpdate(const Checkable::Ptr& checkable); - void SendAcknowledgementSet(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double expiry); - void SendAcknowledgementCleared(const Checkable::Ptr& checkable, const String& removedBy); + void SendAcknowledgementSet(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double changeTime, double expiry); + void SendAcknowledgementCleared(const Checkable::Ptr& checkable, const String& removedBy, double changeTime); std::vector UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType, const String& typeNameOverride); Dictionary::Ptr SerializeState(const Checkable::Ptr& checkable); @@ -106,8 +106,8 @@ private: static void CommentRemovedHandler(const Comment::Ptr& comment); static void FlappingChangedHandler(const Checkable::Ptr& checkable, const Value& value); static void NewCheckResultHandler(const Checkable::Ptr& checkable); - static void AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double expiry); - static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy); + static void AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double changeTime, double expiry); + static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double changeTime); void AssertOnWorkQueue();