mirror of https://github.com/Icinga/icinga2.git
Add ExecuteCommandProcessFinishedHandler and checkable param to ExecuteRemoteCheck
This commit is contained in:
parent
c3d9f6c17b
commit
15159b1632
|
@ -492,7 +492,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
|||
}
|
||||
}
|
||||
|
||||
void Checkable::ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros)
|
||||
void Checkable::ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros, const Checkable::Ptr& checkable)
|
||||
{
|
||||
CONTEXT("Executing remote check for object '" + GetName() + "'");
|
||||
|
||||
|
@ -503,7 +503,11 @@ void Checkable::ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros)
|
|||
cr->SetScheduleStart(scheduled_start);
|
||||
cr->SetExecutionStart(before_check);
|
||||
|
||||
GetCheckCommand()->Execute(this, cr, resolvedMacros, true);
|
||||
if (!checkable) {
|
||||
GetCheckCommand()->Execute(this, cr, resolvedMacros, true);
|
||||
} else {
|
||||
GetCheckCommand()->Execute(checkable, cr, resolvedMacros, true);
|
||||
}
|
||||
}
|
||||
|
||||
void Checkable::ExecuteCheck()
|
||||
|
|
|
@ -20,6 +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;
|
||||
|
||||
void Checkable::StaticInitialize()
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "base/atomic.hpp"
|
||||
#include "base/timer.hpp"
|
||||
#include "base/process.hpp"
|
||||
#include "icinga/i2-icinga.hpp"
|
||||
#include "icinga/checkable-ti.hpp"
|
||||
#include "icinga/timeperiod.hpp"
|
||||
|
@ -14,6 +15,7 @@
|
|||
#include "remote/endpoint.hpp"
|
||||
#include "remote/messageorigin.hpp"
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
@ -55,6 +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;
|
||||
|
||||
Checkable();
|
||||
|
||||
|
@ -94,7 +97,7 @@ public:
|
|||
|
||||
static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type);
|
||||
|
||||
void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = nullptr);
|
||||
void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = nullptr, const Checkable::Ptr& checkbale = nullptr);
|
||||
void ExecuteCheck();
|
||||
void ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin = nullptr);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "base/configuration.hpp"
|
||||
#include "base/serializer.hpp"
|
||||
#include "base/exception.hpp"
|
||||
#include "methods/executeactiontask.hpp"
|
||||
#include <boost/thread/once.hpp>
|
||||
#include <thread>
|
||||
|
||||
|
@ -97,12 +98,38 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons
|
|||
return;
|
||||
}
|
||||
|
||||
Checkable::Ptr checkable = nullptr;
|
||||
if (params->Contains("source")) {
|
||||
Log(LogCritical, "ApiListener", "Not implemented.");
|
||||
|
||||
String uuid = params->Get("source");
|
||||
|
||||
return;
|
||||
Host::Ptr host = Host::GetByName(params->Get("host"));
|
||||
if (!host) {
|
||||
Log(LogCritical, "ApiListener", "Host not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (params->Contains("service"))
|
||||
checkable = host->GetServiceByShortName(params->Get("service"));
|
||||
else
|
||||
checkable = host;
|
||||
|
||||
if (!checkable) {
|
||||
Log(LogCritical, "ApiListener", "Checkable not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
ObjectLock oLock (checkable);
|
||||
|
||||
if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
|
||||
Log(LogNotice, "ApiListener")
|
||||
<< "Discarding 'ExecuteCheckFromQueue' event for checkable '" << checkable->GetName()
|
||||
<< "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
|
||||
return;
|
||||
}
|
||||
|
||||
Checkable::ExecuteCommandProcessFinishedHandler = ExecuteActionTask::ProcessFinishedHandler;
|
||||
} else {
|
||||
Checkable::ExecuteCommandProcessFinishedHandler = nullptr;
|
||||
}
|
||||
|
||||
if (!listener->GetAcceptCommands()) {
|
||||
|
@ -182,7 +209,7 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons
|
|||
|
||||
if (command_type == "check_command") {
|
||||
try {
|
||||
host->ExecuteRemoteCheck(macros);
|
||||
host->ExecuteRemoteCheck(macros, checkable);
|
||||
} catch (const std::exception& ex) {
|
||||
CheckResult::Ptr cr = new CheckResult();
|
||||
cr->SetState(ServiceUnknown);
|
||||
|
|
|
@ -54,7 +54,7 @@ void ExecuteActionTask::ProcessFinishedHandler(const Checkable::Ptr& checkable,
|
|||
|
||||
executedParams->Set("check_result", cr);
|
||||
|
||||
/* FIXME command endpoint was overwrite by macro? */
|
||||
/* FIXME command endpoint overwritten by macro? */
|
||||
Endpoint::Ptr commandEndpoint = checkable->GetCommandEndpoint();
|
||||
bool local = !commandEndpoint || commandEndpoint == Endpoint::GetLocalEndpoint();
|
||||
if (local) {
|
||||
|
|
|
@ -43,9 +43,16 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
|
|||
if (!checkable->GetCheckTimeout().IsEmpty())
|
||||
timeout = checkable->GetCheckTimeout();
|
||||
|
||||
PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(),
|
||||
resolvers, resolvedMacros, useResolvedMacros, timeout,
|
||||
std::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1, _2));
|
||||
|
||||
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
||||
PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(),
|
||||
resolvers, resolvedMacros, useResolvedMacros, timeout,
|
||||
std::bind(Checkable::ExecuteCommandProcessFinishedHandler, checkable, cr, _1, _2));
|
||||
} else {
|
||||
PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(),
|
||||
resolvers, resolvedMacros, useResolvedMacros, timeout,
|
||||
std::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1, _2));
|
||||
}
|
||||
|
||||
if (!resolvedMacros || useResolvedMacros) {
|
||||
Checkable::CurrentConcurrentChecks.fetch_add(1);
|
||||
|
|
Loading…
Reference in New Issue