diff --git a/lib/icinga/pluginutility.cpp b/lib/icinga/pluginutility.cpp index 0dcc70997..8ce301ac8 100644 --- a/lib/icinga/pluginutility.cpp +++ b/lib/icinga/pluginutility.cpp @@ -32,7 +32,7 @@ using namespace icinga; void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MacroProcessor::ResolverList& macroResolvers, - const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, + const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int timeout, const std::function& callback) { Value raw_command = commandObj->GetCommandLine(); @@ -86,11 +86,7 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab Process::Ptr process = new Process(Process::PrepareCommand(command), envMacros); - if (checkable->GetCheckTimeout().IsEmpty()) - process->SetTimeout(commandObj->GetTimeout()); - else - process->SetTimeout(checkable->GetCheckTimeout()); - + process->SetTimeout(timeout); process->SetAdjustPriority(true); process->Run(std::bind(callback, command, _1)); diff --git a/lib/icinga/pluginutility.hpp b/lib/icinga/pluginutility.hpp index 756ad9d97..1cfd38d87 100644 --- a/lib/icinga/pluginutility.hpp +++ b/lib/icinga/pluginutility.hpp @@ -41,7 +41,7 @@ class PluginUtility public: static void ExecuteCommand(const Command::Ptr& commandObj, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MacroProcessor::ResolverList& macroResolvers, - const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, + const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int timeout, const std::function& callback = std::function()); static ServiceState ExitStatusToState(int exitStatus); diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index 1709583a4..31fcc658a 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -52,8 +52,13 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes resolvers.emplace_back("command", commandObj); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + int timeout = commandObj->GetTimeout(); + + if (!checkable->GetCheckTimeout().IsEmpty()) + timeout = checkable->GetCheckTimeout(); + PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), - resolvers, resolvedMacros, useResolvedMacros, + resolvers, resolvedMacros, useResolvedMacros, timeout, std::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1, _2)); if (!resolvedMacros || useResolvedMacros) diff --git a/lib/methods/plugineventtask.cpp b/lib/methods/plugineventtask.cpp index d42db23f3..550d159d1 100644 --- a/lib/methods/plugineventtask.cpp +++ b/lib/methods/plugineventtask.cpp @@ -51,8 +51,10 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable, resolvers.emplace_back("command", commandObj); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + int timeout = commandObj->GetTimeout(); + PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), - resolvers, resolvedMacros, useResolvedMacros, + resolvers, resolvedMacros, useResolvedMacros, timeout, std::bind(&PluginEventTask::ProcessFinishedHandler, checkable, _1, _2)); } diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index 948f2dbed..6bf75e75d 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -68,8 +68,10 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, resolvers.emplace_back("command", commandObj); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + int timeout = commandObj->GetTimeout(); + PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers, - resolvedMacros, useResolvedMacros, + resolvedMacros, useResolvedMacros, timeout, std::bind(&PluginNotificationTask::ProcessFinishedHandler, checkable, _1, _2)); }