db_ido: Add eventhandlers.

refs #4768
This commit is contained in:
Michael Friedrich 2013-10-01 11:04:30 +02:00
parent c07857dea8
commit 16de7f853b
4 changed files with 55 additions and 0 deletions

View File

@ -66,6 +66,8 @@ void ServiceDbObject::StaticInitialize(void)
Service::OnFlappingChanged.connect(bind(&ServiceDbObject::AddFlappingHistory, _1, _2));
Service::OnNewCheckResult.connect(bind(&ServiceDbObject::AddServiceCheckHistory, _1, _2));
Service::OnEventCommandExecuted.connect(bind(&ServiceDbObject::AddEventHandlerHistory, _1));
ExternalCommandProcessor::OnNewExternalCommand.connect(bind(&ServiceDbObject::AddExternalCommandHistory, _1, _2, _3));
}
@ -1322,6 +1324,52 @@ void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const
}
}
/* eventhandlers */
void ServiceDbObject::AddEventHandlerHistory(const Service::Ptr& service)
{
Host::Ptr host = service->GetHost();
if (!host)
return;
Log(LogDebug, "db_ido", "add eventhandler history for '" + service->GetName() + "'");
double now = Utility::GetTime();
unsigned long event_time = static_cast<long>(now);
unsigned long event_time_usec = (now - event_time) * 1000 * 1000;
DbQuery query1;
query1.Table = "eventhandlers";
query1.Type = DbQueryInsert;
Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
fields1->Set("eventhandler_type", 1); /* service */
fields1->Set("object_id", service);
fields1->Set("state", service->GetState());
fields1->Set("state_type", service->GetStateType());
fields1->Set("start_time", DbValue::FromTimestamp(event_time));
fields1->Set("start_time_usec", event_time_usec);
fields1->Set("end_time", DbValue::FromTimestamp(event_time));
fields1->Set("end_time_usec", event_time_usec);
fields1->Set("command_object_id", service->GetEventCommand());
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
query1.Fields = fields1;
OnQuery(query1);
if (host->GetCheckService() == service) {
fields1->Set("eventhandler_type", 0); /* host */
fields1->Set("object_id", host);
fields1->Set("state", host->GetState());
fields1->Set("state_type", host->GetStateType());
query1.Fields = fields1;
OnQuery(query1);
}
}
/* externalcommands */
void ServiceDbObject::AddExternalCommandHistory(double time, const String& command, const std::vector<String>& arguments)
{

View File

@ -110,6 +110,7 @@ private:
static void AddFlappingHistory(const Service::Ptr& service, FlappingState flapping_state);
static void AddServiceCheckHistory(const Service::Ptr& service, const Dictionary::Ptr &cr);
static void AddEventHandlerHistory(const Service::Ptr& service);
static void AddExternalCommandHistory(double time, const String& command, const std::vector<String>& arguments);
};

View File

@ -22,6 +22,8 @@
using namespace icinga;
boost::signals2::signal<void (const Service::Ptr&)> Service::OnEventCommandExecuted;
EventCommand::Ptr Service::GetEventCommand(void) const
{
return EventCommand::GetByName(m_EventCommand);
@ -35,5 +37,8 @@ void Service::ExecuteEventHandler(void)
return;
Log(LogDebug, "icinga", "Executing event handler for service '" + GetName() + "'");
ec->Execute(GetSelf());
OnEventCommandExecuted(GetSelf());
}

View File

@ -250,6 +250,7 @@ public:
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;
static boost::signals2::signal<void (const Service::Ptr&)> OnEventCommandExecuted;
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;