]> granicus.if.org Git - icinga2/commitdiff
Implement cluster events for acknowledgements.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 29 Aug 2013 11:48:18 +0000 (13:48 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 29 Aug 2013 11:48:18 +0000 (13:48 +0200)
components/cluster/clustercomponent.cpp
components/cluster/clustercomponent.h
lib/icinga/service-check.cpp
lib/icinga/service.cpp
lib/icinga/service.h

index 231f0c2ac8daac7f0e5a7d0c50d2d9867ba32a1c..c3390cd7b37bcf6193a8200c9e74c0bf8c49af77 100644 (file)
@@ -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<Dictionary>();
+       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<Dictionary>();
+       message->Set("jsonrpc", "2.0");
+       message->Set("method", "cluster::SetAcknowledgement");
+       message->Set("params", params);
+
+       BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
+               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<Dictionary>();
+       params->Set("service", service->GetName());
+
+       Dictionary::Ptr message = boost::make_shared<Dictionary>();
+       message->Set("jsonrpc", "2.0");
+       message->Set("method", "cluster::ClearAcknowledgement");
+       message->Set("params", params);
+
+       BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
+               endpoint->SendMessage(message);
+       }
+}
+
 void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message)
 {
        BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
@@ -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<AcknowledgementType>(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());
        }
 }
 
index 991e051c8baafda4f62ba70d954f144c90dbd957..e33bc86d2cbcffed943baf24f5d5fbb813e1f9b0 100644 (file)
@@ -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);
 
 };
index 772094cb968faa3ce9029c016f57ae079d382ba0..80774201a6ead2e1ae675856df50b9b12491c41a 100644 (file)
@@ -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 */
index c9102d032fa04de52d821133efd52fb24a343bb9..ff874b0c21d75d222576b76881364ad5112a05f6 100644 (file)
@@ -34,6 +34,9 @@ using namespace icinga;
 
 REGISTER_TYPE(Service);
 
+boost::signals2::signal<void (const Service::Ptr&, const String&, const String&, AcknowledgementType, double, const String&)> Service::OnAcknowledgementSet;
+boost::signals2::signal<void (const Service::Ptr&, const String&)> 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<double>(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<Host::Ptr> Service::GetParentHosts(void) const
index 5ab542a95ff0701c5089822a55a24427619a6a24..428455b858742e821ccac959934042ab0b691fce 100644 (file)
@@ -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<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnDowntimeRemoved;
        static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
        static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&)> OnDowntimeTriggered;
+       static boost::signals2::signal<void (const Service::Ptr&, const String&, const String&, AcknowledgementType, double, const String&)> OnAcknowledgementSet;
+       static boost::signals2::signal<void (const Service::Ptr&, const String&)> OnAcknowledgementCleared;
 
        virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;