mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 07:04:37 +02:00
Implement cluster events for acknowledgements.
This commit is contained in:
parent
10e31dfa50
commit
90d929595d
@ -65,6 +65,8 @@ void ClusterComponent::Start(void)
|
|||||||
Service::OnCommentRemoved.connect(bind(&ClusterComponent::CommentRemovedHandler, this, _1, _2, _3));
|
Service::OnCommentRemoved.connect(bind(&ClusterComponent::CommentRemovedHandler, this, _1, _2, _3));
|
||||||
Service::OnDowntimeAdded.connect(bind(&ClusterComponent::DowntimeAddedHandler, 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::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));
|
Endpoint::OnMessageReceived.connect(bind(&ClusterComponent::MessageHandler, this, _1, _2));
|
||||||
}
|
}
|
||||||
@ -504,6 +506,46 @@ void ClusterComponent::DowntimeRemovedHandler(const Service::Ptr& service, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
|
BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
|
||||||
@ -667,6 +709,30 @@ void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Diction
|
|||||||
String id = params->Get("id");
|
String id = params->Get("id");
|
||||||
|
|
||||||
service->RemoveDowntime(id, sender->GetName());
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +92,8 @@ private:
|
|||||||
void CommentRemovedHandler(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);
|
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 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);
|
void MessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -530,8 +530,7 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr, const String& author
|
|||||||
/* remove acknowledgements */
|
/* remove acknowledgements */
|
||||||
if (GetAcknowledgement() == AcknowledgementNormal ||
|
if (GetAcknowledgement() == AcknowledgementNormal ||
|
||||||
(GetAcknowledgement() == AcknowledgementSticky && GetStateType() == StateTypeHard && GetState() == StateOK)) {
|
(GetAcknowledgement() == AcknowledgementSticky && GetStateType() == StateTypeHard && GetState() == StateOK)) {
|
||||||
SetAcknowledgement(AcknowledgementNone);
|
ClearAcknowledgement();
|
||||||
SetAcknowledgementExpiry(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reschedule service dependencies */
|
/* reschedule service dependencies */
|
||||||
|
@ -34,6 +34,9 @@ using namespace icinga;
|
|||||||
|
|
||||||
REGISTER_TYPE(Service);
|
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)
|
void Service::Start(void)
|
||||||
{
|
{
|
||||||
DynamicObject::Start();
|
DynamicObject::Start();
|
||||||
@ -210,19 +213,13 @@ AcknowledgementType Service::GetAcknowledgement(void)
|
|||||||
|
|
||||||
if (expiry != 0 && expiry < Utility::GetTime()) {
|
if (expiry != 0 && expiry < Utility::GetTime()) {
|
||||||
avalue = AcknowledgementNone;
|
avalue = AcknowledgementNone;
|
||||||
SetAcknowledgement(avalue);
|
ClearAcknowledgement();
|
||||||
SetAcknowledgementExpiry(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return avalue;
|
return avalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::SetAcknowledgement(AcknowledgementType acknowledgement)
|
|
||||||
{
|
|
||||||
m_Acknowledgement = acknowledgement;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Service::IsAcknowledged(void)
|
bool Service::IsAcknowledged(void)
|
||||||
{
|
{
|
||||||
return GetAcknowledgement() != AcknowledgementNone;
|
return GetAcknowledgement() != AcknowledgementNone;
|
||||||
@ -236,31 +233,30 @@ double Service::GetAcknowledgementExpiry(void) const
|
|||||||
return static_cast<double>(m_AcknowledgementExpiry);
|
return static_cast<double>(m_AcknowledgementExpiry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::SetAcknowledgementExpiry(double timestamp)
|
void Service::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority)
|
||||||
{
|
|
||||||
m_AcknowledgementExpiry = timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Service::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry)
|
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
SetAcknowledgement(type);
|
m_Acknowledgement = type;
|
||||||
SetAcknowledgementExpiry(expiry);
|
m_AcknowledgementExpiry = expiry;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) AddComment(CommentAcknowledgement, author, comment, 0);
|
(void) AddComment(CommentAcknowledgement, author, comment, 0);
|
||||||
|
|
||||||
OnNotificationsRequested(GetSelf(), NotificationAcknowledgement, GetLastCheckResult(), author, comment);
|
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());
|
||||||
|
|
||||||
SetAcknowledgement(AcknowledgementNone);
|
m_Acknowledgement = AcknowledgementNone;
|
||||||
SetAcknowledgementExpiry(0);
|
m_AcknowledgementExpiry = 0;
|
||||||
|
|
||||||
|
Utility::QueueAsyncCallback(bind(boost::ref(OnAcknowledgementCleared), GetSelf(), authority));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<Host::Ptr> Service::GetParentHosts(void) const
|
std::set<Host::Ptr> Service::GetParentHosts(void) const
|
||||||
|
@ -135,7 +135,10 @@ public:
|
|||||||
bool IsReachable(void) const;
|
bool IsReachable(void) const;
|
||||||
|
|
||||||
AcknowledgementType GetAcknowledgement(void);
|
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 */
|
/* Checks */
|
||||||
Array::Ptr GetCheckers(void) const;
|
Array::Ptr GetCheckers(void) const;
|
||||||
@ -214,14 +217,8 @@ public:
|
|||||||
bool GetForceNextCheck(void) const;
|
bool GetForceNextCheck(void) const;
|
||||||
void SetForceNextCheck(bool forced, const String& authority = String());
|
void SetForceNextCheck(bool forced, const String& authority = String());
|
||||||
|
|
||||||
double GetAcknowledgementExpiry(void) const;
|
|
||||||
void SetAcknowledgementExpiry(double timestamp);
|
|
||||||
|
|
||||||
static void UpdateStatistics(const Dictionary::Ptr& cr);
|
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 ExecuteCheck(void);
|
||||||
void ProcessCheckResult(const Dictionary::Ptr& cr, const String& authority = String());
|
void ProcessCheckResult(const Dictionary::Ptr& cr, const String& authority = String());
|
||||||
|
|
||||||
@ -250,6 +247,8 @@ public:
|
|||||||
static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnDowntimeRemoved;
|
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&, FlappingState)> OnFlappingChanged;
|
||||||
static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&)> OnDowntimeTriggered;
|
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;
|
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user