mirror of https://github.com/Icinga/icinga2.git
parent
ea3c3e0c3e
commit
7b4f1e217a
|
@ -201,11 +201,13 @@
|
||||||
%attribute %dictionary "*" {
|
%attribute %dictionary "*" {
|
||||||
%attribute %string "key"
|
%attribute %string "key"
|
||||||
%attribute %string "value"
|
%attribute %string "value"
|
||||||
|
%attribute %function "value"
|
||||||
%attribute %string "description"
|
%attribute %string "description"
|
||||||
%attribute %number "required"
|
%attribute %number "required"
|
||||||
%attribute %number "skip_key"
|
%attribute %number "skip_key"
|
||||||
%attribute %number "repeat_key"
|
%attribute %number "repeat_key"
|
||||||
%attribute %string "set_if"
|
%attribute %string "set_if"
|
||||||
|
%attribute %function "set_if"
|
||||||
%attribute %number "order"
|
%attribute %number "order"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -59,8 +59,10 @@ Value MacroProcessor::ResolveMacros(const Value& str, const ResolverList& resolv
|
||||||
}
|
}
|
||||||
|
|
||||||
result = resultArr;
|
result = resultArr;
|
||||||
|
} else if (str.IsObjectType<Function>()) {
|
||||||
|
result = EvaluateFunction(str, resolvers, cr, missingMacro, escapeFn, resolvedMacros, useResolvedMacros, 0);
|
||||||
} else {
|
} else {
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Command is not a string or array."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Macro is not a string or array."));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -166,6 +168,26 @@ Value MacroProcessor::InternalResolveMacrosShim(const std::vector<Value>& args,
|
||||||
resolvedMacros, useResolvedMacros, recursionLevel);
|
resolvedMacros, useResolvedMacros, recursionLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value MacroProcessor::EvaluateFunction(const Function::Ptr& func, const ResolverList& resolvers,
|
||||||
|
const CheckResult::Ptr& cr, String *missingMacro,
|
||||||
|
const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros,
|
||||||
|
bool useResolvedMacros, int recursionLevel)
|
||||||
|
{
|
||||||
|
Dictionary::Ptr resolvers_this = new Dictionary();
|
||||||
|
|
||||||
|
BOOST_FOREACH(const ResolverSpec& resolver, resolvers) {
|
||||||
|
resolvers_this->Set(resolver.first, resolver.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolvers_this->Set("macro", new Function(boost::bind(&MacroProcessor::InternalResolveMacrosShim,
|
||||||
|
_1, boost::cref(resolvers), cr, missingMacro, boost::cref(escapeFn), resolvedMacros, useResolvedMacros,
|
||||||
|
recursionLevel)));
|
||||||
|
|
||||||
|
ScriptFrame frame(resolvers_this);
|
||||||
|
std::vector<Value> args;
|
||||||
|
return func->Invoke(args);
|
||||||
|
}
|
||||||
|
|
||||||
Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverList& resolvers,
|
Value MacroProcessor::InternalResolveMacros(const String& 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,
|
||||||
|
@ -210,23 +232,8 @@ Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverLis
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resolved_macro.IsObjectType<Function>()) {
|
if (resolved_macro.IsObjectType<Function>()) {
|
||||||
Function::Ptr func = resolved_macro;
|
resolved_macro = EvaluateFunction(resolved_macro, resolvers, cr, missingMacro, escapeFn,
|
||||||
|
resolvedMacros, useResolvedMacros, recursionLevel);
|
||||||
if (!resolvers_this) {
|
|
||||||
resolvers_this = new Dictionary();
|
|
||||||
|
|
||||||
BOOST_FOREACH(const ResolverSpec& resolver, resolvers) {
|
|
||||||
resolvers_this->Set(resolver.first, resolver.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
resolvers_this->Set("macro", new Function(boost::bind(&MacroProcessor::InternalResolveMacrosShim,
|
|
||||||
_1, boost::cref(resolvers), cr, missingMacro, boost::cref(escapeFn), resolvedMacros, useResolvedMacros,
|
|
||||||
recursionLevel)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptFrame frame(resolvers_this);
|
|
||||||
std::vector<Value> args;
|
|
||||||
resolved_macro = func->Invoke(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
|
|
@ -61,6 +61,11 @@ private:
|
||||||
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,
|
||||||
bool useResolvedMacros, int recursionLevel);
|
bool useResolvedMacros, int recursionLevel);
|
||||||
|
static Value EvaluateFunction(const Function::Ptr& func, const ResolverList& resolvers,
|
||||||
|
const CheckResult::Ptr& cr, String *missingMacro,
|
||||||
|
const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros,
|
||||||
|
bool useResolvedMacros, int recursionLevel);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab
|
||||||
arg.Key = kv.first;
|
arg.Key = kv.first;
|
||||||
|
|
||||||
bool required = false;
|
bool required = false;
|
||||||
String argval;
|
Value argval;
|
||||||
|
|
||||||
if (arginfo.IsObjectType<Dictionary>()) {
|
if (arginfo.IsObjectType<Dictionary>()) {
|
||||||
Dictionary::Ptr argdict = arginfo;
|
Dictionary::Ptr argdict = arginfo;
|
||||||
|
@ -123,11 +123,11 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab
|
||||||
arg.RepeatKey = argdict->Get("repeat_key");
|
arg.RepeatKey = argdict->Get("repeat_key");
|
||||||
arg.Order = argdict->Get("order");
|
arg.Order = argdict->Get("order");
|
||||||
|
|
||||||
String set_if = argdict->Get("set_if");
|
Value set_if = argdict->Get("set_if");
|
||||||
|
|
||||||
if (!set_if.IsEmpty()) {
|
if (!set_if.IsEmpty()) {
|
||||||
String missingMacro;
|
String missingMacro;
|
||||||
String set_if_resolved = MacroProcessor::ResolveMacros(set_if, macroResolvers,
|
Value set_if_resolved = MacroProcessor::ResolveMacros(set_if, macroResolvers,
|
||||||
cr, &missingMacro, MacroProcessor::EscapeCallback(), resolvedMacros,
|
cr, &missingMacro, MacroProcessor::EscapeCallback(), resolvedMacros,
|
||||||
useResolvedMacros);
|
useResolvedMacros);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue