Fix that check_timeout was used for Event/Notification commands too

We may add specific timeouts for event/notification commands
later, for now the original timeout inside the EventCommand/NotificationCommand
is used.

fixes #6304
This commit is contained in:
Michael Friedrich 2018-09-28 14:32:57 +02:00
parent 7acf3689a7
commit 617925374b
5 changed files with 15 additions and 10 deletions

View File

@ -32,7 +32,7 @@ using namespace icinga;
void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkable::Ptr& checkable, void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkable::Ptr& checkable,
const CheckResult::Ptr& cr, const MacroProcessor::ResolverList& macroResolvers, 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<void(const Value& commandLine, const ProcessResult&)>& callback) const std::function<void(const Value& commandLine, const ProcessResult&)>& callback)
{ {
Value raw_command = commandObj->GetCommandLine(); 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); Process::Ptr process = new Process(Process::PrepareCommand(command), envMacros);
if (checkable->GetCheckTimeout().IsEmpty()) process->SetTimeout(timeout);
process->SetTimeout(commandObj->GetTimeout());
else
process->SetTimeout(checkable->GetCheckTimeout());
process->SetAdjustPriority(true); process->SetAdjustPriority(true);
process->Run(std::bind(callback, command, _1)); process->Run(std::bind(callback, command, _1));

View File

@ -41,7 +41,7 @@ class PluginUtility
public: public:
static void ExecuteCommand(const Command::Ptr& commandObj, const Checkable::Ptr& checkable, static void ExecuteCommand(const Command::Ptr& commandObj, const Checkable::Ptr& checkable,
const CheckResult::Ptr& cr, const MacroProcessor::ResolverList& macroResolvers, 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<void(const Value& commandLine, const ProcessResult&)>& callback = std::function<void(const Value& commandLine, const ProcessResult&)>()); const std::function<void(const Value& commandLine, const ProcessResult&)>& callback = std::function<void(const Value& commandLine, const ProcessResult&)>());
static ServiceState ExitStatusToState(int exitStatus); static ServiceState ExitStatusToState(int exitStatus);

View File

@ -52,8 +52,13 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
resolvers.emplace_back("command", commandObj); resolvers.emplace_back("command", commandObj);
resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
int timeout = commandObj->GetTimeout();
if (!checkable->GetCheckTimeout().IsEmpty())
timeout = checkable->GetCheckTimeout();
PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(),
resolvers, resolvedMacros, useResolvedMacros, resolvers, resolvedMacros, useResolvedMacros, timeout,
std::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1, _2)); std::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1, _2));
if (!resolvedMacros || useResolvedMacros) if (!resolvedMacros || useResolvedMacros)

View File

@ -51,8 +51,10 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable,
resolvers.emplace_back("command", commandObj); resolvers.emplace_back("command", commandObj);
resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
int timeout = commandObj->GetTimeout();
PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(),
resolvers, resolvedMacros, useResolvedMacros, resolvers, resolvedMacros, useResolvedMacros, timeout,
std::bind(&PluginEventTask::ProcessFinishedHandler, checkable, _1, _2)); std::bind(&PluginEventTask::ProcessFinishedHandler, checkable, _1, _2));
} }

View File

@ -68,8 +68,10 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
resolvers.emplace_back("command", commandObj); resolvers.emplace_back("command", commandObj);
resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
int timeout = commandObj->GetTimeout();
PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers, PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers,
resolvedMacros, useResolvedMacros, resolvedMacros, useResolvedMacros, timeout,
std::bind(&PluginNotificationTask::ProcessFinishedHandler, checkable, _1, _2)); std::bind(&PluginNotificationTask::ProcessFinishedHandler, checkable, _1, _2));
} }