mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-28 16:14:09 +02:00
Add overrideMacros property to MacroResolver
This commit is contained in:
parent
b07471d803
commit
be2701bc8a
@ -15,6 +15,7 @@
|
|||||||
#include "remote/httputility.hpp"
|
#include "remote/httputility.hpp"
|
||||||
#include "base/utility.hpp"
|
#include "base/utility.hpp"
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
|
#include "base/defer.hpp"
|
||||||
#include "remote/actionshandler.hpp"
|
#include "remote/actionshandler.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
@ -641,6 +642,12 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
|
|||||||
|
|
||||||
/* Check if resolved_command exists and it is of type command_type */
|
/* Check if resolved_command exists and it is of type command_type */
|
||||||
Dictionary::Ptr execMacros = new Dictionary();
|
Dictionary::Ptr execMacros = new Dictionary();
|
||||||
|
|
||||||
|
MacroResolver::overrideMacros = execMacros;
|
||||||
|
Defer o ([]() {
|
||||||
|
MacroResolver::overrideMacros = nullptr;
|
||||||
|
});
|
||||||
|
|
||||||
if (command_type == "CheckCommand") {
|
if (command_type == "CheckCommand") {
|
||||||
CheckCommand::Ptr cmd = CheckCommand::GetByName(resolved_command);
|
CheckCommand::Ptr cmd = CheckCommand::GetByName(resolved_command);
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
thread_local Dictionary::Ptr MacroResolver::overrideMacros;
|
||||||
|
|
||||||
Value MacroProcessor::ResolveMacros(const Value& str, const ResolverList& resolvers,
|
Value MacroProcessor::ResolveMacros(const Value& str, const ResolverList& resolvers,
|
||||||
const CheckResult::Ptr& cr, String *missingMacro,
|
const CheckResult::Ptr& cr, String *missingMacro,
|
||||||
const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros,
|
const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros,
|
||||||
|
@ -21,6 +21,8 @@ class MacroResolver
|
|||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(MacroResolver);
|
DECLARE_PTR_TYPEDEFS(MacroResolver);
|
||||||
|
|
||||||
|
static thread_local Dictionary::Ptr overrideMacros;
|
||||||
|
|
||||||
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const = 0;
|
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,6 +29,9 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
|
|||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
MacroProcessor::ResolverList resolvers;
|
MacroProcessor::ResolverList resolvers;
|
||||||
|
if (MacroResolver::overrideMacros)
|
||||||
|
resolvers.emplace_back("override", MacroResolver::overrideMacros);
|
||||||
|
|
||||||
if (service)
|
if (service)
|
||||||
resolvers.emplace_back("service", service);
|
resolvers.emplace_back("service", service);
|
||||||
resolvers.emplace_back("host", host);
|
resolvers.emplace_back("host", host);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user