CompatLog: Fix downtimes.

fixes #4652
This commit is contained in:
Michael Friedrich 2013-09-17 19:40:23 +02:00
parent bcc370b82c
commit 9a21af719d
2 changed files with 109 additions and 64 deletions

View File

@ -52,9 +52,10 @@ void CompatLog::Start(void)
DynamicObject::Start(); DynamicObject::Start();
Service::OnNewCheckResult.connect(bind(&CompatLog::CheckResultHandler, this, _1, _2)); Service::OnNewCheckResult.connect(bind(&CompatLog::CheckResultHandler, this, _1, _2));
// Service::OnDowntimeTriggered.connect(bind(&CompatLog::DowntimeHandler, this, _1));
Service::OnNotificationSentChanged.connect(bind(&CompatLog::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6)); Service::OnNotificationSentChanged.connect(bind(&CompatLog::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6));
Service::OnFlappingChanged.connect(bind(&CompatLog::FlappingHandler, this, _1, _2)); Service::OnFlappingChanged.connect(bind(&CompatLog::FlappingHandler, this, _1, _2));
Service::OnDowntimeTriggered.connect(boost::bind(&CompatLog::TriggerDowntimeHandler, this, _1, _2));
Service::OnDowntimeRemoved.connect(boost::bind(&CompatLog::RemoveDowntimeHandler, this, _1, _2));
m_RotationTimer = boost::make_shared<Timer>(); m_RotationTimer = boost::make_shared<Timer>();
m_RotationTimer->OnTimerExpired.connect(boost::bind(&CompatLog::RotationTimerHandler, this)); m_RotationTimer->OnTimerExpired.connect(boost::bind(&CompatLog::RotationTimerHandler, this));
@ -167,69 +168,111 @@ void CompatLog::CheckResultHandler(const Service::Ptr& service, const Dictionary
} }
} }
///** /**
// * @threadsafety Always. * @threadsafety Always.
// */ */
//void CompatLog::DowntimeHandler(const Service::Ptr& service) void CompatLog::TriggerDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime)
//{ {
// Host::Ptr host = service->GetHost(); Host::Ptr host = service->GetHost();
//
// if (!host) if (!host)
// return; return;
//
// String downtime_state_str; if (!downtime)
// String downtime_output; return;
//
// switch (downtime_state) { String downtime_output = "Service has entered a period of scheduled downtime.";
// case DowntimeStarted: String downtime_state_str = "STARTED";
// downtime_output = "Service has entered a period of scheduled downtime.";
// downtime_state_str = "STARTED"; std::ostringstream msgbuf;
// break; msgbuf << "SERVICE DOWNTIME ALERT: "
// case DowntimeStopped: << host->GetName() << ";"
// downtime_output = "Service has exited from a period of scheduled downtime."; << service->GetShortName() << ";"
// downtime_state_str = "STOPPED"; << downtime_state_str << "; "
// break; << downtime_output
// case DowntimeCancelled: << "";
// downtime_output = "Scheduled downtime for service has been cancelled.";
// downtime_state_str = "CANCELLED"; {
// break; ObjectLock oLock(this);
// default: WriteLine(msgbuf.str());
// Log(LogCritical, "compat", "Unknown downtime state: " + Convert::ToString(downtime_state)); }
// return;
// } if (service == host->GetHostCheckService()) {
// std::ostringstream msgbuf;
// std::ostringstream msgbuf; msgbuf << "HOST DOWNTIME ALERT: "
// msgbuf << "SERVICE DOWNTIME ALERT: " << host->GetName() << ";"
// << host->GetName() << ";" << downtime_state_str << "; "
// << service->GetShortName() << ";" << downtime_output
// << downtime_state_str << "; " << "";
// << downtime_output
// << ""; {
// ObjectLock oLock(this);
// { WriteLine(msgbuf.str());
// ObjectLock oLock(this); }
// WriteLine(msgbuf.str()); }
// }
// {
// if (service == host->GetHostCheckService()) { ObjectLock oLock(this);
// std::ostringstream msgbuf; Flush();
// msgbuf << "HOST DOWNTIME ALERT: " }
// << host->GetName() << ";" }
// << downtime_state_str << "; "
// << downtime_output /**
// << ""; * @threadsafety Always.
// */
// { void CompatLog::RemoveDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime)
// ObjectLock oLock(this); {
// WriteLine(msgbuf.str()); Host::Ptr host = service->GetHost();
// }
// } if (!host)
// return;
// {
// ObjectLock oLock(this); if (!downtime)
// Flush(); return;
// }
//} String downtime_output;
String downtime_state_str;
if (downtime->Get("was_cancelled") == true) {
downtime_output = "Scheduled downtime for service has been cancelled.";
downtime_state_str = "CANCELLED";
} else {
downtime_output = "Service has exited from a period of scheduled downtime.";
downtime_state_str = "STOPPED";
}
std::ostringstream msgbuf;
msgbuf << "SERVICE DOWNTIME ALERT: "
<< host->GetName() << ";"
<< service->GetShortName() << ";"
<< downtime_state_str << "; "
<< downtime_output
<< "";
{
ObjectLock oLock(this);
WriteLine(msgbuf.str());
}
if (service == host->GetHostCheckService()) {
std::ostringstream msgbuf;
msgbuf << "HOST DOWNTIME ALERT: "
<< host->GetName() << ";"
<< downtime_state_str << "; "
<< downtime_output
<< "";
{
ObjectLock oLock(this);
WriteLine(msgbuf.str());
}
}
{
ObjectLock oLock(this);
Flush();
}
}
/** /**
* @threadsafety Always. * @threadsafety Always.

View File

@ -65,6 +65,8 @@ private:
void DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state); void DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state);
void NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user, NotificationType const& notification_type, Dictionary::Ptr const& cr, const String& author, const String& comment_text); void NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user, NotificationType const& notification_type, Dictionary::Ptr const& cr, const String& author, const String& comment_text);
void FlappingHandler(const Service::Ptr& service, FlappingState flapping_state); void FlappingHandler(const Service::Ptr& service, FlappingState flapping_state);
void TriggerDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime);
void RemoveDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime);
Timer::Ptr m_RotationTimer; Timer::Ptr m_RotationTimer;
void RotationTimerHandler(void); void RotationTimerHandler(void);