]> granicus.if.org Git - icinga2/commitdiff
Provide 1.x fallback using GetName() for address macros.
authorMichael Friedrich <Michael.Friedrich@netways.de>
Sat, 5 Apr 2014 15:45:28 +0000 (17:45 +0200)
committerMichael Friedrich <Michael.Friedrich@netways.de>
Sat, 5 Apr 2014 15:45:28 +0000 (17:45 +0200)
Refs #5855

lib/icinga/host.cpp

index 095066c89bf7c4aea40477fe907211977bc3c758..0836f55d395c427fa9fc37d2f1b04148f3eb993b 100644 (file)
@@ -261,6 +261,39 @@ bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re
        String key;
        Dictionary::Ptr vars;
 
+       /* special treatment for address macros providing name fallback */
+       if (macro == "address" || macro == "address6") {
+               vars = GetVars();
+
+               String value;
+               if (vars && vars->Contains(macro))
+                       value = vars->Get(key);
+
+               if (value.IsEmpty()) {
+                       *result = GetName();
+                       return true;
+               } else {
+                       *result = value;
+                       return true;
+               }
+       }
+       else if (macro == "host.vars.address" || macro == "host.vars.address6") {
+               key = macro.SubStr(10);
+               vars = GetVars();
+
+               String value;
+               if (vars && vars->Contains(macro))
+                       value = vars->Get(key);
+
+               if (value.IsEmpty()) {
+                       *result = GetName();
+                       return true;
+               } else {
+                       *result = value;
+                       return true;
+               }
+       }
+
        /* require prefix for object macros */
        if (macro.SubStr(0, 5) == "host.") {
                key = macro.SubStr(5);