]> granicus.if.org Git - icinga2/commitdiff
Fix that check_timeout was used for Event/Notification commands too 6643/head
authorMichael Friedrich <michael.friedrich@icinga.com>
Fri, 28 Sep 2018 12:32:57 +0000 (14:32 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Fri, 28 Sep 2018 12:32:57 +0000 (14:32 +0200)
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
lib/icinga/pluginutility.hpp
lib/methods/pluginchecktask.cpp
lib/methods/plugineventtask.cpp
lib/methods/pluginnotificationtask.cpp

index 0dcc70997f71ecf1c28f08c7478abc9fd5060a87..8ce301ac8b0f5ec4bc43a2083232c4b1ab19d2d0 100644 (file)
@@ -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<void(const Value& commandLine, const ProcessResult&)>& 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));
index 756ad9d97db8abbe2c79d419c9c1b2cbf028b5a6..1cfd38d87161cede48127da37ef21e5477b92fa6 100644 (file)
@@ -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<void(const Value& commandLine, const ProcessResult&)>& callback = std::function<void(const Value& commandLine, const ProcessResult&)>());
 
        static ServiceState ExitStatusToState(int exitStatus);
index 1709583a430a045c400a8371c76ff5ac522b7dc8..31fcc658afb369cb02b8436ddf41af77114da3db 100644 (file)
@@ -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)
index d42db23f3a8494711673753f9ab0c47543e8b305..550d159d16031d275b47a696ebd8bcadd64be720 100644 (file)
@@ -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));
 }
 
index 948f2dbed205d0cfa8850466b0f90bc605c7fb11..6bf75e75d10557d1e19ea079f0659302fbeb5a92 100644 (file)
@@ -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));
 }