Add overrideMacros property to MacroResolver

This commit is contained in:
Mattia Codato 2020-07-03 15:13:51 +02:00
parent b07471d803
commit be2701bc8a
4 changed files with 14 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include "remote/httputility.hpp"
#include "base/utility.hpp"
#include "base/convert.hpp"
#include "base/defer.hpp"
#include "remote/actionshandler.hpp"
#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 */
Dictionary::Ptr execMacros = new Dictionary();
MacroResolver::overrideMacros = execMacros;
Defer o ([]() {
MacroResolver::overrideMacros = nullptr;
});
if (command_type == "CheckCommand") {
CheckCommand::Ptr cmd = CheckCommand::GetByName(resolved_command);
if (!cmd)

View File

@ -15,6 +15,8 @@
using namespace icinga;
thread_local Dictionary::Ptr MacroResolver::overrideMacros;
Value MacroProcessor::ResolveMacros(const Value& str, const ResolverList& resolvers,
const CheckResult::Ptr& cr, String *missingMacro,
const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros,

View File

@ -21,6 +21,8 @@ class MacroResolver
public:
DECLARE_PTR_TYPEDEFS(MacroResolver);
static thread_local Dictionary::Ptr overrideMacros;
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const = 0;
};

View File

@ -29,6 +29,9 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
tie(host, service) = GetHostService(checkable);
MacroProcessor::ResolverList resolvers;
if (MacroResolver::overrideMacros)
resolvers.emplace_back("override", MacroResolver::overrideMacros);
if (service)
resolvers.emplace_back("service", service);
resolvers.emplace_back("host", host);