Fix event command execution not calling finish handler

fixes #6856
This commit is contained in:
Michael Friedrich 2014-08-06 17:49:29 +02:00
parent 731ee15d4d
commit d20ee37196
3 changed files with 17 additions and 2 deletions

View 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

View 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());
}
}

View 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);
};
}