From: Gunnar Beutner Date: Thu, 29 Aug 2013 09:37:51 +0000 (+0200) Subject: Implement cluster event for SetForceNextNotification. X-Git-Tag: v0.0.3~664 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=24b7aed2592fa33f914169670ee3967b0f206e41;p=icinga2 Implement cluster event for SetForceNextNotification. --- diff --git a/components/cluster/clustercomponent.cpp b/components/cluster/clustercomponent.cpp index 628a14bf0..90d1868c9 100644 --- a/components/cluster/clustercomponent.cpp +++ b/components/cluster/clustercomponent.cpp @@ -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(); + params->Set("service", service->GetName()); + params->Set("forced", forced); + + Dictionary::Ptr message = boost::make_shared(); + message->Set("jsonrpc", "2.0"); + message->Set("method", "cluster::SetForceNextNotification"); + message->Set("params", params); + + BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects()) { + 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"); diff --git a/components/cluster/clustercomponent.h b/components/cluster/clustercomponent.h index c72d8f3be..9dc3e7f2e 100644 --- a/components/cluster/clustercomponent.h +++ b/components/cluster/clustercomponent.h @@ -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); diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index a2ada86b7..551061960 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -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 #include @@ -219,7 +220,9 @@ bool Service::GetForceNextNotification(void) const return static_cast(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)); } diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 58e9db000..3febc6931 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -236,6 +236,7 @@ public: static boost::signals2::signal OnNextCheckChanged; static boost::signals2::signal OnForceNextCheckChanged; + static boost::signals2::signal OnForceNextNotificationChanged; static boost::signals2::signal OnEnableActiveChecksChanged; static boost::signals2::signal OnEnablePassiveChecksChanged; static boost::signals2::signal 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);