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

index 90d1868c934aaf8194c1c4c5bb7f78c233576609..231f0c2ac8daac7f0e5a7d0c50d2d9867ba32a1c 100644 (file)
@@ -59,6 +59,8 @@ void ClusterComponent::Start(void)
        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::OnEnableNotificationsChanged.connect(bind(&ClusterComponent::EnableNotificationsChangedHandler, this, _1, _2, _3));
+       Service::OnEnableFlappingChanged.connect(bind(&ClusterComponent::EnableFlappingChangedHandler, this, _1, _2, _3));
        Service::OnCommentAdded.connect(bind(&ClusterComponent::CommentAddedHandler, this, _1, _2, _3));
        Service::OnCommentRemoved.connect(bind(&ClusterComponent::CommentRemovedHandler, this, _1, _2, _3));
        Service::OnDowntimeAdded.connect(bind(&ClusterComponent::DowntimeAddedHandler, this, _1, _2, _3));
@@ -388,6 +390,44 @@ void ClusterComponent::EnablePassiveChecksChangedHandler(const Service::Ptr& ser
        }
 }
 
+void ClusterComponent::EnableNotificationsChangedHandler(const Service::Ptr& service, bool enabled, const String& authority)
+{
+       if (!authority.IsEmpty() && authority != GetIdentity())
+               return;
+
+       Dictionary::Ptr params = boost::make_shared<Dictionary>();
+       params->Set("service", service->GetName());
+       params->Set("enabled", enabled);
+
+       Dictionary::Ptr message = boost::make_shared<Dictionary>();
+       message->Set("jsonrpc", "2.0");
+       message->Set("method", "cluster::SetEnableNotifications");
+       message->Set("params", params);
+
+       BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
+               endpoint->SendMessage(message);
+       }
+}
+
+void ClusterComponent::EnableFlappingChangedHandler(const Service::Ptr& service, bool enabled, const String& authority)
+{
+       if (!authority.IsEmpty() && authority != GetIdentity())
+               return;
+
+       Dictionary::Ptr params = boost::make_shared<Dictionary>();
+       params->Set("service", service->GetName());
+       params->Set("enabled", enabled);
+
+       Dictionary::Ptr message = boost::make_shared<Dictionary>();
+       message->Set("jsonrpc", "2.0");
+       message->Set("method", "cluster::SetEnableFlapping");
+       message->Set("params", params);
+
+       BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
+               endpoint->SendMessage(message);
+       }
+}
+
 void ClusterComponent::CommentAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority)
 {
        if (!authority.IsEmpty() && authority != GetIdentity())
@@ -545,6 +585,28 @@ void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Diction
                bool enabled = params->Get("enabled");
 
                service->SetEnablePassiveChecks(enabled, sender->GetName());
+       } else if (message->Get("method") == "cluster::SetEnableNotifications") {
+               String svc = params->Get("service");
+
+               Service::Ptr service = Service::GetByName(svc);
+
+               if (!service)
+                       return;
+
+               bool enabled = params->Get("enabled");
+
+               service->SetEnableNotifications(enabled, sender->GetName());
+       } else if (message->Get("method") == "cluster::SetEnableFlapping") {
+               String svc = params->Get("service");
+
+               Service::Ptr service = Service::GetByName(svc);
+
+               if (!service)
+                       return;
+
+               bool enabled = params->Get("enabled");
+
+               service->SetEnableFlapping(enabled, sender->GetName());
        } else if (message->Get("method") == "cluster::SetNextNotification") {
                String nfc = params->Get("notification");
 
index 9dc3e7f2e08b96b97b55499fa6d14f87fa32a30d..991e051c8baafda4f62ba70d954f144c90dbd957 100644 (file)
@@ -86,6 +86,8 @@ private:
        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 EnableNotificationsChangedHandler(const Service::Ptr& service, bool enabled, const String& authority);
+       void EnableFlappingChangedHandler(const Service::Ptr& service, bool enabled, const String& authority);
        void CommentAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority);
        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);
index 00f51268b08376c62018352fb57832675fad2a38..36cdd202f6ffd1beace7ae677610c0261ab151f5 100644 (file)
@@ -43,6 +43,8 @@ boost::signals2::signal<void (const Service::Ptr&, double, const String&)> Servi
 boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> Service::OnForceNextCheckChanged;
 boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> Service::OnEnableActiveChecksChanged;
 boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> Service::OnEnablePassiveChecksChanged;
+boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> Service::OnEnableNotificationsChanged;
+boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> Service::OnEnableFlappingChanged;
 boost::signals2::signal<void (const Service::Ptr&, FlappingState)> Service::OnFlappingChanged;
 
 CheckCommand::Ptr Service::GetCheckCommand(void) const
index 562af91310265168905a9c5c9dfd5de772480efb..56f7239c7a226680bda39f1c388e3758c74896aa 100644 (file)
@@ -57,11 +57,12 @@ bool Service::GetEnableFlapping(void) const
 
 }
 
-void Service::SetEnableFlapping(bool enabled)
+void Service::SetEnableFlapping(bool enabled, const String& authority)
 {
-       OnFlappingChanged(GetSelf(), enabled ? FlappingEnabled : FlappingDisabled);
-
        m_EnableFlapping = enabled;
+
+       OnFlappingChanged(GetSelf(), enabled ? FlappingEnabled : FlappingDisabled);
+       Utility::QueueAsyncCallback(bind(boost::ref(OnEnableFlappingChanged), GetSelf(), enabled, authority));
 }
 
 void Service::UpdateFlappingStatus(bool stateChange)
index 5510619608d690a7f5928db45921d011fce43e57..d7c520f8ed59461ff69e80060527a64b51644185 100644 (file)
@@ -207,9 +207,11 @@ bool Service::GetEnableNotifications(void) const
                return m_EnableNotifications;
 }
 
-void Service::SetEnableNotifications(bool enabled)
+void Service::SetEnableNotifications(bool enabled, const String& authority)
 {
        m_EnableNotifications = enabled;
+
+       Utility::QueueAsyncCallback(bind(boost::ref(OnEnableNotificationsChanged), GetSelf(), enabled, authority));
 }
 
 bool Service::GetForceNextNotification(void) const
index 3febc6931681107106d227580680443b12b3f0c3..5ab542a95ff0701c5089822a55a24427619a6a24 100644 (file)
@@ -239,14 +239,16 @@ public:
        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&, bool, const String&)> OnEnableNotificationsChanged;
+       static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableFlappingChanged;
        static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnNewCheckResult;
        static boost::signals2::signal<void (const Service::Ptr&, NotificationType, const Dictionary::Ptr&, const String&, const String&)> OnNotificationsRequested;
        static boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> OnNotificationSentChanged;
-       static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
        static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnCommentAdded;
        static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnCommentRemoved;
        static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnDowntimeAdded;
        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;
 
        virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
@@ -299,7 +301,7 @@ public:
        Dictionary::Ptr GetNotificationDescriptions(void) const;
 
        bool GetEnableNotifications(void) const;
-       void SetEnableNotifications(bool enabled);
+       void SetEnableNotifications(bool enabled, const String& authority = String());
 
        void SendNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author = "", const String& text = "");
 
@@ -320,7 +322,7 @@ public:
 
        /* Flapping Detection */
        bool GetEnableFlapping(void) const;
-       void SetEnableFlapping(bool enabled);
+       void SetEnableFlapping(bool enabled, const String& authority = String());
 
        double GetFlappingCurrent(void) const;
        double GetFlappingThreshold(void) const;