mirror of https://github.com/Icinga/icinga2.git
parent
c36d785f9f
commit
fb44744680
|
@ -1732,6 +1732,7 @@ There are several ways of using custom attributes with [apply rules](3-monitorin
|
|||
[boolean](15-language-reference.md#boolean-literals)) for expression conditions (`assign where`, `ignore where`)
|
||||
* As [array](15-language-reference.md#array) or [dictionary](15-language-reference.md#dictionary) attribute with nested values
|
||||
(e.g. dictionaries in dictionaries) in [apply for](3-monitoring-basics.md#using-apply-for) rules.
|
||||
* As a [function object](#functions)
|
||||
|
||||
Features like [DB IDO](3-monitoring-basics.md#db-ido), Livestatus(#setting-up-livestatus) or StatusData(#status-data)
|
||||
dump this column as encoded JSON string, and set `is_json` resp. `cv_is_json` to `1`.
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "base/logger.hpp"
|
||||
#include "base/context.hpp"
|
||||
#include "base/dynamicobject.hpp"
|
||||
#include "base/scriptframe.hpp"
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
|
@ -166,6 +167,8 @@ Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverLis
|
|||
size_t offset, pos_first, pos_second;
|
||||
offset = 0;
|
||||
|
||||
Dictionary::Ptr resolvers_this;
|
||||
|
||||
String result = str;
|
||||
while ((pos_first = result.FindFirstOf("$", offset)) != String::NPos) {
|
||||
pos_second = result.FindFirstOf("$", pos_first + 1);
|
||||
|
@ -194,6 +197,22 @@ Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverLis
|
|||
found = true;
|
||||
}
|
||||
|
||||
if (resolved_macro.IsObjectType<Function>()) {
|
||||
Function::Ptr func = resolved_macro;
|
||||
|
||||
if (!resolvers_this) {
|
||||
resolvers_this = new Dictionary();
|
||||
|
||||
BOOST_FOREACH(const ResolverSpec& resolver, resolvers) {
|
||||
resolvers_this->Set(resolver.first, resolver.second);
|
||||
}
|
||||
}
|
||||
|
||||
ScriptFrame frame(resolvers_this);
|
||||
std::vector<Value> args;
|
||||
resolved_macro = func->Invoke(args);
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
if (!missingMacro)
|
||||
Log(LogWarning, "MacroProcessor")
|
||||
|
|
Loading…
Reference in New Issue