From 617925374b43debf60d78ff20fcc18c7b7f5aee3 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 28 Sep 2018 14:32:57 +0200 Subject: [PATCH] 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 --- lib/icinga/pluginutility.cpp | 8 ++------ lib/icinga/pluginutility.hpp | 2 +- lib/methods/pluginchecktask.cpp | 7 ++++++- lib/methods/plugineventtask.cpp | 4 +++- lib/methods/pluginnotificationtask.cpp | 4 +++- 5 files changed, 15 insertions(+), 10 deletions(-) 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)); } -- 2.40.0