]> granicus.if.org Git - icinga2/commitdiff
db_ido: Add eventhandlers.
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 1 Oct 2013 09:04:30 +0000 (11:04 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 1 Oct 2013 09:04:30 +0000 (11:04 +0200)
refs #4768

lib/db_ido/servicedbobject.cpp
lib/db_ido/servicedbobject.h
lib/icinga/service-event.cpp
lib/icinga/service.h

index 4193bd924bb22aea7facc88df18bd17e828e1feb..8c2c1fde83eaa3ec40fd4a6408109d886017037a 100644 (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)
 {
index 8a3228e5dceacf87713013b42e28190cafc14129..1b8fd7230354cd9d179c57bc4c7d83e6f98e818d 100644 (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);
 };
 
index f7574b9ab97aaad624aca26d37d754aa01f9911e..084a0e4633a9642dcb62e8aa004eb152a0a9b1d4 100644 (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());
 }
\ No newline at end of file
index 4d4203c5df7c7da207ed57ac5dc47d227b3235a0..0371f79d75bc6b939800f478e74ffb0fbdcbfcf3 100644 (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;