MCPcopy Create free account
hub / github.com/Icinga/icinga2 / ResolveMacro

Method ResolveMacro

lib/icinga/macroprocessor.cpp:89–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resolvers,
90 const CheckResult::Ptr& cr, Value *result, bool *recursive_macro)
91{
92 CONTEXT("Resolving macro '" << macro << "'");
93
94 *recursive_macro = false;
95
96 std::vector<String> tokens = macro.Split(".");
97
98 String objName;
99 if (tokens.size() > 1) {
100 objName = tokens[0];
101 tokens.erase(tokens.begin());
102 }
103
104 const auto defaultResolvers (GetDefaultResolvers());
105
106 for (auto resolverList : {&resolvers, &defaultResolvers}) {
107 for (auto& resolver : *resolverList) {
108 if (!objName.IsEmpty() && objName != resolver.Name)
109 continue;
110
111 if (objName.IsEmpty()) {
112 if (!resolver.ResolveShortMacros)
113 continue;
114
115 Dictionary::Ptr vars;
116 CustomVarObject::Ptr dobj = dynamic_pointer_cast<CustomVarObject>(resolver.Obj);
117
118 if (dobj) {
119 vars = dobj->GetVars();
120 } else {
121 auto app (dynamic_pointer_cast<IcingaApplication>(resolver.Obj));
122
123 if (app) {
124 vars = app->GetVars();
125 }
126 }
127
128 if (vars && vars->Contains(macro)) {
129 *result = vars->Get(macro);
130 *recursive_macro = true;
131 return true;
132 }
133 }
134
135 auto *mresolver = dynamic_cast<MacroResolver *>(resolver.Obj.get());
136
137 if (mresolver && mresolver->ResolveMacro(boost::algorithm::join(tokens, "."), cr, result))
138 return true;
139
140 Value ref = resolver.Obj;
141 bool valid = true;
142
143 for (const String& token : tokens) {
144 if (ref.IsObjectType<Dictionary>()) {
145 Dictionary::Ptr dict = ref;
146 if (dict->Contains(token)) {

Callers

nothing calls this directly

Calls 14

GetDefaultResolversFunction · 0.85
SplitMethod · 0.80
IsObjectMethod · 0.80
sizeMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
IsEmptyMethod · 0.45
ContainsMethod · 0.45
GetMethod · 0.45
getMethod · 0.45
GetReflectionTypeMethod · 0.45
GetFieldIdMethod · 0.45

Tested by

no test coverage detected