diff --git a/doc/3-monitoring-basics.md b/doc/3-monitoring-basics.md index 5ef81b105a6..eafecb5f686 100644 --- a/doc/3-monitoring-basics.md +++ b/doc/3-monitoring-basics.md @@ -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`. diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index 53b770322ba..280ba938ae9 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -25,6 +25,7 @@ #include "base/logger.hpp" #include "base/context.hpp" #include "base/dynamicobject.hpp" +#include "base/scriptframe.hpp" #include #include #include @@ -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::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 args; + resolved_macro = func->Invoke(args); + } + if (!found) { if (!missingMacro) Log(LogWarning, "MacroProcessor")