m_Endpoint = Endpoint::MakeEndpoint("compatlog_" + GetName(), false);
m_Endpoint->RegisterTopicHandler("checker::CheckResult",
boost::bind(&CompatLog::CheckResultRequestHandler, this, _3));
- m_Endpoint->RegisterTopicHandler("icinga::Downtime",
- boost::bind(&CompatLog::DowntimeRequestHandler, this, _3));
m_Endpoint->RegisterTopicHandler("icinga::NotificationSent",
boost::bind(&CompatLog::NotificationSentRequestHandler, this, _3));
+ Service::OnDowntimeChanged.connect(bind(&CompatLog::DowntimeHandler, this, _1, _2));
+
m_RotationTimer = boost::make_shared<Timer>();
m_RotationTimer->OnTimerExpired.connect(boost::bind(&CompatLog::RotationTimerHandler, this));
m_RotationTimer->Start();
/**
* @threadsafety Always.
*/
-void CompatLog::DowntimeRequestHandler(const RequestMessage& request)
+void CompatLog::DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state)
{
- DowntimeMessage params;
- if (!request.GetParams(¶ms))
- return;
-
- String svcname = params.GetService();
- Service::Ptr service = Service::GetByName(svcname);
-
Host::Ptr host = service->GetHost();
if (!host)
return;
- DowntimeState downtime_state = params.GetState();
String downtime_state_str;
String downtime_output;
#ifndef COMPATLOG_H
#define COMPATLOG_H
+#include "icinga/service.h"
#include "remoting/endpoint.h"
#include "base/dynamicobject.h"
#include "base/timer.h"
Endpoint::Ptr m_Endpoint;
void CheckResultRequestHandler(const RequestMessage& request);
- void DowntimeRequestHandler(const RequestMessage& request);
void NotificationSentRequestHandler(const RequestMessage& request);
+ void DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state);
Timer::Ptr m_RotationTimer;
void RotationTimerHandler(void);
static Timer::Ptr l_DowntimesCacheTimer;
static Timer::Ptr l_DowntimesExpireTimer;
+boost::signals2::signal<void (const Service::Ptr&, DowntimeState)> Service::OnDowntimeChanged;
+
+void Service::DowntimeRequestHandler(const RequestMessage& request)
+{
+ DowntimeMessage params;
+ if (!request.GetParams(¶ms))
+ return;
+
+ String svcname = params.GetService();
+ Service::Ptr service = Service::GetByName(svcname);
+
+ OnDowntimeChanged(service, params.GetState());
+}
+
int Service::GetNextDowntimeID(void)
{
boost::mutex::scoped_lock lock(l_DowntimeMutex);
#include "icinga/checkcommand.h"
#include "icinga/icingaapplication.h"
#include "icinga/macroprocessor.h"
+#include "icinga/downtimemessage.h"
#include "config/configitembuilder.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
REGISTER_TYPE(Service);
+boost::once_flag Service::m_OnceFlag = BOOST_ONCE_INIT;
+
Service::Service(const Dictionary::Ptr& serializedObject)
: DynamicObject(serializedObject), m_CheckRunning(false)
{
RegisterAttribute("enable_flapping", Attribute_Config, &m_EnableFlapping);
SetSchedulingOffset(rand());
+
+ boost::call_once(m_OnceFlag, &Service::Initialize);
}
Service::~Service(void)
Service::InvalidateCommentsCache();
}
+void Service::Initialize(void)
+{
+ m_Endpoint = Endpoint::MakeEndpoint("service", false);
+ m_Endpoint->RegisterTopicHandler("icinga::Downtime",
+ boost::bind(&Service::DowntimeRequestHandler, _3));
+}
+
void Service::OnRegistrationCompleted(void)
{
ASSERT(!OwnsLock());
#include "icinga/host.h"
#include "icinga/timeperiod.h"
#include "icinga/notification.h"
+#include "remoting/requestmessage.h"
+#include "remoting/endpoint.h"
+#include "base/i2-base.h"
#include "base/dynamicobject.h"
#include "base/array.h"
#include <boost/signals2.hpp>
+#include <boost/thread/once.hpp>
namespace icinga
{
static boost::signals2::signal<void (const Service::Ptr&)> OnCheckerChanged;
static boost::signals2::signal<void (const Service::Ptr&)> OnNextCheckChanged;
+ static boost::signals2::signal<void (const Service::Ptr&, DowntimeState)> OnDowntimeChanged;
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
bool m_CheckRunning;
long m_SchedulingOffset;
+ static boost::once_flag m_OnceFlag;
+ static Endpoint::Ptr m_Endpoint;
+
+ static void Initialize(void);
+
/* Downtimes */
Attribute<Dictionary::Ptr> m_Downtimes;
static void DowntimesExpireTimerHandler(void);
+ static void DowntimeRequestHandler(const RequestMessage& request);
void RemoveExpiredDowntimes(void);