From 4966dfd2416c8ab0ef3bf4c535d76a144e0acaa2 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Sat, 5 Apr 2014 17:45:28 +0200 Subject: [PATCH] Provide 1.x fallback using GetName() for address macros. Refs #5855 --- lib/icinga/host.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 095066c89..0836f55d3 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -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);