From: Gunnar Beutner Date: Thu, 29 Aug 2013 11:48:18 +0000 (+0200) Subject: Implement cluster events for acknowledgements. X-Git-Tag: v0.0.3~661 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90d929595d5c8d6f736a34652561bfc61700bb75;p=icinga2 Implement cluster events for acknowledgements. --- diff --git a/components/cluster/clustercomponent.cpp b/components/cluster/clustercomponent.cpp index 231f0c2ac..c3390cd7b 100644 --- a/components/cluster/clustercomponent.cpp +++ b/components/cluster/clustercomponent.cpp @@ -65,6 +65,8 @@ void ClusterComponent::Start(void) Service::OnCommentRemoved.connect(bind(&ClusterComponent::CommentRemovedHandler, this, _1, _2, _3)); Service::OnDowntimeAdded.connect(bind(&ClusterComponent::DowntimeAddedHandler, this, _1, _2, _3)); Service::OnDowntimeRemoved.connect(bind(&ClusterComponent::DowntimeRemovedHandler, this, _1, _2, _3)); + Service::OnAcknowledgementSet.connect(bind(&ClusterComponent::AcknowledgementSetHandler, this, _1, _2, _3, _4, _5, _6)); + Service::OnAcknowledgementCleared.connect(bind(&ClusterComponent::AcknowledgementClearedHandler, this, _1, _2)); Endpoint::OnMessageReceived.connect(bind(&ClusterComponent::MessageHandler, this, _1, _2)); } @@ -504,6 +506,46 @@ void ClusterComponent::DowntimeRemovedHandler(const Service::Ptr& service, const } } +void ClusterComponent::AcknowledgementSetHandler(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority) +{ + if (!authority.IsEmpty() && authority != GetIdentity()) + return; + + Dictionary::Ptr params = boost::make_shared(); + params->Set("service", service->GetName()); + params->Set("author", author); + params->Set("comment", comment); + params->Set("type", type); + params->Set("expiry", expiry); + + Dictionary::Ptr message = boost::make_shared(); + message->Set("jsonrpc", "2.0"); + message->Set("method", "cluster::SetAcknowledgement"); + message->Set("params", params); + + BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects()) { + endpoint->SendMessage(message); + } +} + +void ClusterComponent::AcknowledgementClearedHandler(const Service::Ptr& service, const String& authority) +{ + if (!authority.IsEmpty() && authority != GetIdentity()) + return; + + Dictionary::Ptr params = boost::make_shared(); + params->Set("service", service->GetName()); + + Dictionary::Ptr message = boost::make_shared(); + message->Set("jsonrpc", "2.0"); + message->Set("method", "cluster::ClearAcknowledgement"); + message->Set("params", params); + + BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects()) { + endpoint->SendMessage(message); + } +} + void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message) { BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects()) { @@ -667,6 +709,30 @@ void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Diction String id = params->Get("id"); service->RemoveDowntime(id, sender->GetName()); + } else if (message->Get("method") == "cluster::SetAcknowledgement") { + String svc = params->Get("service"); + + Service::Ptr service = Service::GetByName(svc); + + if (!service) + return; + + String author = params->Get("author"); + String comment = params->Get("comment"); + int type = params->Get("type"); + double expiry = params->Get("expiry"); + + service->AcknowledgeProblem(author, comment, static_cast(type), expiry, sender->GetName()); + } else if (message->Get("method") == "cluster::ClearAcknowledgement") { + String svc = params->Get("service"); + + Service::Ptr service = Service::GetByName(svc); + + if (!service) + return; + + ObjectLock olock(service); + service->ClearAcknowledgement(sender->GetName()); } } diff --git a/components/cluster/clustercomponent.h b/components/cluster/clustercomponent.h index 991e051c8..e33bc86d2 100644 --- a/components/cluster/clustercomponent.h +++ b/components/cluster/clustercomponent.h @@ -92,6 +92,8 @@ private: void CommentRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority); void DowntimeAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority); void DowntimeRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority); + void AcknowledgementSetHandler(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority); + void AcknowledgementClearedHandler(const Service::Ptr& service, const String& authority); void MessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message); }; diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp index 772094cb9..80774201a 100644 --- a/lib/icinga/service-check.cpp +++ b/lib/icinga/service-check.cpp @@ -530,8 +530,7 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr, const String& author /* remove acknowledgements */ if (GetAcknowledgement() == AcknowledgementNormal || (GetAcknowledgement() == AcknowledgementSticky && GetStateType() == StateTypeHard && GetState() == StateOK)) { - SetAcknowledgement(AcknowledgementNone); - SetAcknowledgementExpiry(0); + ClearAcknowledgement(); } /* reschedule service dependencies */ diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index c9102d032..ff874b0c2 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -34,6 +34,9 @@ using namespace icinga; REGISTER_TYPE(Service); +boost::signals2::signal Service::OnAcknowledgementSet; +boost::signals2::signal Service::OnAcknowledgementCleared; + void Service::Start(void) { DynamicObject::Start(); @@ -210,19 +213,13 @@ AcknowledgementType Service::GetAcknowledgement(void) if (expiry != 0 && expiry < Utility::GetTime()) { avalue = AcknowledgementNone; - SetAcknowledgement(avalue); - SetAcknowledgementExpiry(0); + ClearAcknowledgement(); } } return avalue; } -void Service::SetAcknowledgement(AcknowledgementType acknowledgement) -{ - m_Acknowledgement = acknowledgement; -} - bool Service::IsAcknowledged(void) { return GetAcknowledgement() != AcknowledgementNone; @@ -236,31 +233,30 @@ double Service::GetAcknowledgementExpiry(void) const return static_cast(m_AcknowledgementExpiry); } -void Service::SetAcknowledgementExpiry(double timestamp) -{ - m_AcknowledgementExpiry = timestamp; -} - -void Service::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry) +void Service::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority) { { ObjectLock olock(this); - SetAcknowledgement(type); - SetAcknowledgementExpiry(expiry); + m_Acknowledgement = type; + m_AcknowledgementExpiry = expiry; } (void) AddComment(CommentAcknowledgement, author, comment, 0); OnNotificationsRequested(GetSelf(), NotificationAcknowledgement, GetLastCheckResult(), author, comment); + + Utility::QueueAsyncCallback(bind(boost::ref(OnAcknowledgementSet), GetSelf(), author, comment, type, expiry, authority)); } -void Service::ClearAcknowledgement(void) +void Service::ClearAcknowledgement(const String& authority) { - ObjectLock olock(this); + ASSERT(OwnsLock()); + + m_Acknowledgement = AcknowledgementNone; + m_AcknowledgementExpiry = 0; - SetAcknowledgement(AcknowledgementNone); - SetAcknowledgementExpiry(0); + Utility::QueueAsyncCallback(bind(boost::ref(OnAcknowledgementCleared), GetSelf(), authority)); } std::set Service::GetParentHosts(void) const diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 5ab542a95..428455b85 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -135,7 +135,10 @@ public: bool IsReachable(void) const; AcknowledgementType GetAcknowledgement(void); - void SetAcknowledgement(AcknowledgementType acknowledgement); + double GetAcknowledgementExpiry(void) const; + + void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry = 0, const String& authority = String()); + void ClearAcknowledgement(const String& authority = String()); /* Checks */ Array::Ptr GetCheckers(void) const; @@ -214,14 +217,8 @@ public: bool GetForceNextCheck(void) const; void SetForceNextCheck(bool forced, const String& authority = String()); - double GetAcknowledgementExpiry(void) const; - void SetAcknowledgementExpiry(double timestamp); - static void UpdateStatistics(const Dictionary::Ptr& cr); - void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry = 0); - void ClearAcknowledgement(void); - void ExecuteCheck(void); void ProcessCheckResult(const Dictionary::Ptr& cr, const String& authority = String()); @@ -250,6 +247,8 @@ public: static boost::signals2::signal OnDowntimeRemoved; static boost::signals2::signal OnFlappingChanged; static boost::signals2::signal OnDowntimeTriggered; + static boost::signals2::signal OnAcknowledgementSet; + static boost::signals2::signal OnAcknowledgementCleared; virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;