From a3027d717730dca65121930b95a408f71a0aa50e Mon Sep 17 00:00:00 2001 From: Mattia Codato Date: Mon, 13 Jul 2020 16:54:37 +0200 Subject: [PATCH] Fix ExecuteCommandProcessFinishedHandler parameters --- lib/icinga/checkable.cpp | 2 +- lib/icinga/checkable.hpp | 2 +- lib/icinga/clusterevents-check.cpp | 7 +++---- lib/methods/pluginchecktask.cpp | 11 +++++------ 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index 3f31d5667..22d1d0cf4 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -20,7 +20,7 @@ boost::signals2::signal Checkable::OnFlappingChange; static Timer::Ptr l_CheckablesFireSuppressedNotifications; -thread_local std::function Checkable::ExecuteCommandProcessFinishedHandler; +thread_local std::function Checkable::ExecuteCommandProcessFinishedHandler; void Checkable::StaticInitialize() { diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index dd74b85db..cfa04339a 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -57,7 +57,7 @@ public: DECLARE_OBJECTNAME(Checkable); static void StaticInitialize(); - static thread_local std::function ExecuteCommandProcessFinishedHandler; + static thread_local std::function ExecuteCommandProcessFinishedHandler; Checkable(); diff --git a/lib/icinga/clusterevents-check.cpp b/lib/icinga/clusterevents-check.cpp index 3564c99b7..b6f0e17ae 100644 --- a/lib/icinga/clusterevents-check.cpp +++ b/lib/icinga/clusterevents-check.cpp @@ -135,7 +135,7 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons return; } - Checkable::ExecuteCommandProcessFinishedHandler = [listener, sourceEndpoint, origin, params] (const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Value& commandLine, const ProcessResult& pr) -> void { + Checkable::ExecuteCommandProcessFinishedHandler = [checkable, listener, sourceEndpoint, origin, params] (const Value& commandLine, const ProcessResult& pr) { Checkable::CurrentConcurrentChecks.fetch_sub(1); Checkable::DecreasePendingChecks(); @@ -150,6 +150,7 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons String output = pr.Output.Trim(); std::pair co = PluginUtility::ParseCheckOutput(output); + CheckResult::Ptr cr = new CheckResult(); cr->SetCommand(commandLine); cr->SetOutput(co.first); cr->SetPerformanceData(PluginUtility::SplitPerfdata(co.second)); @@ -174,10 +175,8 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons listener->SyncSendMessage(sourceEndpoint, executedMessage); } }; - } else { - Checkable::ExecuteCommandProcessFinishedHandler = nullptr; } - + if (!listener->GetAcceptCommands()) { Log(LogWarning, "ApiListener") << "Ignoring command. '" << listener->GetName() << "' does not accept commands."; diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index 43851f31d..9dcbd7936 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -44,15 +44,14 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes timeout = checkable->GetCheckTimeout(); + std::function callback; if (Checkable::ExecuteCommandProcessFinishedHandler) { - PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), - resolvers, resolvedMacros, useResolvedMacros, timeout, - std::bind(Checkable::ExecuteCommandProcessFinishedHandler, checkable, cr, _1, _2)); + callback = Checkable::ExecuteCommandProcessFinishedHandler; } else { - PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), - resolvers, resolvedMacros, useResolvedMacros, timeout, - std::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1, _2)); + callback = std::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1, _2); } + PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), + resolvers, resolvedMacros, useResolvedMacros, timeout, callback); if (!resolvedMacros || useResolvedMacros) { Checkable::CurrentConcurrentChecks.fetch_add(1);