]> granicus.if.org Git - icinga2/commitdiff
Add event commands to CompatLogger.
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 5 Nov 2013 17:33:57 +0000 (18:33 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 5 Nov 2013 17:33:57 +0000 (18:33 +0100)
Fixes #4362

components/compat/compatlogger.cpp
components/compat/compatlogger.h

index 92fdf511e981c33417a4324e58147c5a28199011..ef61f1ccb6d899793eb294266c2928ce840c490c 100644 (file)
@@ -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());
index b6595a8df9b4fdfffb45e31c04f3ea3b14c6768f..9c280994a9e8b53a1bfde9853cc20ae6c690bd65 100644 (file)
@@ -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);