]> granicus.if.org Git - icinga2/commitdiff
Implement cluster event for SetForceNextNotification.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 29 Aug 2013 09:37:51 +0000 (11:37 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 29 Aug 2013 09:37:51 +0000 (11:37 +0200)
components/cluster/clustercomponent.cpp
components/cluster/clustercomponent.h
lib/icinga/service-notification.cpp
lib/icinga/service.h

index 628a14bf09e02d32f018cfd4cd4ddb8d634391e3..90d1868c934aaf8194c1c4c5bb7f78c233576609 100644 (file)
@@ -56,6 +56,7 @@ void ClusterComponent::Start(void)
        Service::OnNextCheckChanged.connect(bind(&ClusterComponent::NextCheckChangedHandler, this, _1, _2, _3));
        Notification::OnNextNotificationChanged.connect(bind(&ClusterComponent::NextNotificationChangedHandler, this, _1, _2, _3));
        Service::OnForceNextCheckChanged.connect(bind(&ClusterComponent::ForceNextCheckChangedHandler, this, _1, _2, _3));
+       Service::OnForceNextNotificationChanged.connect(bind(&ClusterComponent::ForceNextNotificationChangedHandler, this, _1, _2, _3));
        Service::OnEnableActiveChecksChanged.connect(bind(&ClusterComponent::EnableActiveChecksChangedHandler, this, _1, _2, _3));
        Service::OnEnablePassiveChecksChanged.connect(bind(&ClusterComponent::EnablePassiveChecksChangedHandler, this, _1, _2, _3));
        Service::OnCommentAdded.connect(bind(&ClusterComponent::CommentAddedHandler, this, _1, _2, _3));
@@ -330,6 +331,25 @@ void ClusterComponent::ForceNextCheckChangedHandler(const Service::Ptr& service,
        }
 }
 
+void ClusterComponent::ForceNextNotificationChangedHandler(const Service::Ptr& service, bool forced, const String& authority)
+{
+       if (!authority.IsEmpty() && authority != GetIdentity())
+               return;
+
+       Dictionary::Ptr params = boost::make_shared<Dictionary>();
+       params->Set("service", service->GetName());
+       params->Set("forced", forced);
+
+       Dictionary::Ptr message = boost::make_shared<Dictionary>();
+       message->Set("jsonrpc", "2.0");
+       message->Set("method", "cluster::SetForceNextNotification");
+       message->Set("params", params);
+
+       BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
+               endpoint->SendMessage(message);
+       }
+}
+
 void ClusterComponent::EnableActiveChecksChangedHandler(const Service::Ptr& service, bool enabled, const String& authority)
 {
        if (!authority.IsEmpty() && authority != GetIdentity())
@@ -492,6 +512,17 @@ void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Diction
                bool forced = params->Get("forced");
 
                service->SetForceNextCheck(forced, sender->GetName());
+       } else if (message->Get("method") == "cluster::SetForceNextNotification") {
+               String svc = params->Get("service");
+
+               Service::Ptr service = Service::GetByName(svc);
+
+               if (!service)
+                       return;
+
+               bool forced = params->Get("forced");
+
+               service->SetForceNextNotification(forced, sender->GetName());
        } else if (message->Get("method") == "cluster::SetEnableActiveChecks") {
                String svc = params->Get("service");
 
index c72d8f3bec7c5ed21aed3d992c6845b2830a33f4..9dc3e7f2e08b96b97b55499fa6d14f87fa32a30d 100644 (file)
@@ -83,6 +83,7 @@ private:
        void NextCheckChangedHandler(const Service::Ptr& service, double nextCheck, const String& authority);
        void NextNotificationChangedHandler(const Notification::Ptr& notification, double nextCheck, const String& authority);
        void ForceNextCheckChangedHandler(const Service::Ptr& service, bool forced, const String& authority);
+       void ForceNextNotificationChangedHandler(const Service::Ptr& service, bool forced, const String& authority);
        void EnableActiveChecksChangedHandler(const Service::Ptr& service, bool enabled, const String& authority);
        void EnablePassiveChecksChangedHandler(const Service::Ptr& service, bool enabled, const String& authority);
        void CommentAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority);
index a2ada86b78a6c55cbc59ddccebeb6cf80161f217..5510619608d690a7f5928db45921d011fce43e57 100644 (file)
@@ -22,6 +22,7 @@
 #include "base/objectlock.h"
 #include "base/logger_fwd.h"
 #include "base/timer.h"
+#include "base/utility.h"
 #include "config/configitembuilder.h"
 #include <boost/tuple/tuple.hpp>
 #include <boost/smart_ptr/make_shared.hpp>
@@ -219,7 +220,9 @@ bool Service::GetForceNextNotification(void) const
        return static_cast<bool>(m_ForceNextNotification);
 }
 
-void Service::SetForceNextNotification(bool forced)
+void Service::SetForceNextNotification(bool forced, const String& authority)
 {
        m_ForceNextNotification = forced ? 1 : 0;
+
+       Utility::QueueAsyncCallback(bind(boost::ref(OnForceNextNotificationChanged), GetSelf(), forced, authority));
 }
index 58e9db000eebc46ff6d2fe1392eec2af6a240072..3febc6931681107106d227580680443b12b3f0c3 100644 (file)
@@ -236,6 +236,7 @@ public:
 
        static boost::signals2::signal<void (const Service::Ptr&, double, const String&)> OnNextCheckChanged;
        static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnForceNextCheckChanged;
+       static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnForceNextNotificationChanged;
        static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableActiveChecksChanged;
        static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnablePassiveChecksChanged;
        static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnNewCheckResult;
@@ -306,7 +307,7 @@ public:
        void AddNotification(const Notification::Ptr& notification);
        void RemoveNotification(const Notification::Ptr& notification);
 
-       void SetForceNextNotification(bool force);
+       void SetForceNextNotification(bool force, const String& authority = String());
        bool GetForceNextNotification(void) const;
 
        void ResetNotificationNumbers(void);