From: Michael Friedrich Date: Wed, 6 Aug 2014 15:49:29 +0000 (+0200) Subject: Fix event command execution not calling finish handler X-Git-Tag: v2.0.2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d20ee3719678029b4184a90163e1b4f36143885b;p=icinga2 Fix event command execution not calling finish handler fixes #6856 --- diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp index 365fe1fc9..c7adb9cd4 100644 --- a/lib/base/threadpool.cpp +++ b/lib/base/threadpool.cpp @@ -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 diff --git a/lib/methods/plugineventtask.cpp b/lib/methods/plugineventtask.cpp index 033616c1f..f3f274c13 100644 --- a/lib/methods/plugineventtask.cpp +++ b/lib/methods/plugineventtask.cpp @@ -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()); + } } diff --git a/lib/methods/plugineventtask.hpp b/lib/methods/plugineventtask.hpp index ce57021b0..5a71ee1ca 100644 --- a/lib/methods/plugineventtask.hpp +++ b/lib/methods/plugineventtask.hpp @@ -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); }; }