Fix ExecuteCommandProcessFinishedHandler parameters

This commit is contained in:
Mattia Codato 2020-07-13 16:54:37 +02:00
parent b9510e72dd
commit a3027d7177
4 changed files with 10 additions and 12 deletions

View File

@ -20,7 +20,7 @@ boost::signals2::signal<void (const Checkable::Ptr&, const String&, double, cons
boost::signals2::signal<void (const Checkable::Ptr&, double)> Checkable::OnFlappingChange;
static Timer::Ptr l_CheckablesFireSuppressedNotifications;
thread_local std::function<void(const Checkable::Ptr&, const CheckResult::Ptr&, const Value& /* commandLine */, const ProcessResult&)> Checkable::ExecuteCommandProcessFinishedHandler;
thread_local std::function<void(const Value& commandLine, const ProcessResult&)> Checkable::ExecuteCommandProcessFinishedHandler;
void Checkable::StaticInitialize()
{

View File

@ -57,7 +57,7 @@ public:
DECLARE_OBJECTNAME(Checkable);
static void StaticInitialize();
static thread_local std::function<void(const Checkable::Ptr&, const CheckResult::Ptr&, const Value& /* commandLine */, const ProcessResult&)> ExecuteCommandProcessFinishedHandler;
static thread_local std::function<void(const Value& commandLine, const ProcessResult&)> ExecuteCommandProcessFinishedHandler;
Checkable();

View File

@ -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<String, String> 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.";

View File

@ -44,15 +44,14 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
timeout = checkable->GetCheckTimeout();
std::function<void(const Value& commandLine, const ProcessResult&)> 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);