Implement cluster events for notifications/flapping.

This commit is contained in:
Gunnar Beutner 2013-08-29 13:06:36 +02:00
parent 24b7aed259
commit 0a60128080
6 changed files with 78 additions and 7 deletions

View 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");

View 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);

View 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

View 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)

View 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

View 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;