]> granicus.if.org Git - icinga2/commitdiff
Fix event command execution not calling finish handler
authorMichael Friedrich <michael.friedrich@netways.de>
Wed, 6 Aug 2014 15:49:29 +0000 (17:49 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Wed, 6 Aug 2014 15:49:29 +0000 (17:49 +0200)
fixes #6856

lib/base/threadpool.cpp
lib/methods/plugineventtask.cpp
lib/methods/plugineventtask.hpp

index 365fe1fc9a02eb6fa7dc815b512bf501831e54bd..c7adb9cd41bd6dc7521ebeec20ca6b0057514632 100644 (file)
@@ -130,7 +130,8 @@ void ThreadPool::WorkerThread::ThreadProc(Queue& queue)
 #endif /* _DEBUG */
 
                try {
-                       wi.Callback();
+                       if (wi.Callback)
+                               wi.Callback();
                } catch (const std::exception& ex) {
                        std::ostringstream msgbuf;
                        msgbuf << "Exception thrown in event handler: " << std::endl
index 033616c1f1a0422f270b8cb8b83289af2c4961f6..f3f274c133ea510f4d2512a689ea28e84ac8cf2e 100644 (file)
@@ -48,5 +48,16 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable)
        resolvers.push_back(std::make_pair("command", commandObj));
        resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
 
-       PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), resolvers);
+       PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), resolvers, boost::bind(&PluginEventTask::ProcessFinishedHandler, checkable, _1, _2));
+}
+
+void PluginEventTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, const Value& command, const ProcessResult& pr)
+{
+       if (pr.ExitStatus != 0) {
+               std::ostringstream msgbuf;
+               msgbuf << "Event command '" << command << "' for object '"
+                      << checkable->GetName() << "' failed; exit status: "
+                      << pr.ExitStatus << ", output: " << pr.Output;
+               Log(LogWarning, "PluginEventTask", msgbuf.str());
+       }
 }
index ce57021b07e78ff8144e249c1a41e23629892a8f..5a71ee1cadf9f7aaa0db5b9b25a9c2f03ab3bff7 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "methods/i2-methods.hpp"
 #include "icinga/service.hpp"
+#include "base/process.hpp"
 
 namespace icinga
 {
@@ -38,6 +39,8 @@ public:
 
 private:
        PluginEventTask(void);
+
+        static void ProcessFinishedHandler(const Checkable::Ptr& checkable, const Value& command, const ProcessResult& pr);
 };
 
 }