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));
}
}
}
+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>()) {
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());
}
}
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);
};
/* remove acknowledgements */
if (GetAcknowledgement() == AcknowledgementNormal ||
(GetAcknowledgement() == AcknowledgementSticky && GetStateType() == StateTypeHard && GetState() == StateOK)) {
- SetAcknowledgement(AcknowledgementNone);
- SetAcknowledgementExpiry(0);
+ ClearAcknowledgement();
}
/* reschedule service dependencies */
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();
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;
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
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;
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());
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;