1
0
mirror of https://github.com/Icinga/icinga2.git synced 2025-04-08 17:05:25 +02:00

Add event commands to CompatLogger.

Fixes 
This commit is contained in:
Michael Friedrich 2013-11-05 18:33:57 +01:00
parent 5718cbebe4
commit 20a2fd2388
2 changed files with 52 additions and 0 deletions

@ -20,6 +20,7 @@
#include "compat/compatlogger.h"
#include "icinga/service.h"
#include "icinga/checkcommand.h"
#include "icinga/eventcommand.h"
#include "icinga/notification.h"
#include "icinga/macroprocessor.h"
#include "icinga/externalcommandprocessor.h"
@ -58,6 +59,7 @@ void CompatLogger::Start(void)
Service::OnFlappingChanged.connect(bind(&CompatLogger::FlappingHandler, this, _1, _2));
Service::OnDowntimeTriggered.connect(boost::bind(&CompatLogger::TriggerDowntimeHandler, this, _1, _2));
Service::OnDowntimeRemoved.connect(boost::bind(&CompatLogger::RemoveDowntimeHandler, this, _1, _2));
Service::OnEventCommandExecuted.connect(bind(&CompatLogger::EventCommandHandler, this, _1));
ExternalCommandProcessor::OnNewExternalCommand.connect(boost::bind(&CompatLogger::ExternalCommandHandler, this, _2, _3));
m_RotationTimer = boost::make_shared<Timer>();
@ -393,6 +395,55 @@ void CompatLogger::ExternalCommandHandler(const String& command, const std::vect
}
}
void CompatLogger::EventCommandHandler(const Service::Ptr& service)
{
Host::Ptr host = service->GetHost();
if (!host)
return;
EventCommand::Ptr event_command = service->GetEventCommand();
String event_command_name = event_command->GetName();
String state = Service::StateToString(service->GetState());
String state_type = Service::StateTypeToString(service->GetStateType());
long current_attempt = service->GetCheckAttempt();
std::ostringstream msgbuf;
msgbuf << "SERVICE EVENT HANDLER: "
<< host->GetName() << ";"
<< service->GetShortName() << ";"
<< state << ";"
<< state_type << ";"
<< current_attempt << ";"
<< event_command_name;
{
ObjectLock oLock(this);
WriteLine(msgbuf.str());
}
if (service == host->GetCheckService()) {
std::ostringstream msgbuf;
msgbuf << "HOST EVENT HANDLER: "
<< host->GetName() << ";"
<< state << ";"
<< state_type << ";"
<< current_attempt << ";"
<< event_command_name;
{
ObjectLock oLock(this);
WriteLine(msgbuf.str());
}
}
{
ObjectLock oLock(this);
Flush();
}
}
void CompatLogger::WriteLine(const String& line)
{
ASSERT(OwnsLock());

@ -59,6 +59,7 @@ private:
void TriggerDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime);
void RemoveDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime);
void ExternalCommandHandler(const String& command, const std::vector<String>& arguments);
void EventCommandHandler(const Service::Ptr& service);
Timer::Ptr m_RotationTimer;
void RotationTimerHandler(void);