diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index cdf5aaf50..095066c89 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -258,11 +258,23 @@ String Host::StateTypeToString(StateType type) bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const { + String key; + Dictionary::Ptr vars; + /* require prefix for object macros */ if (macro.SubStr(0, 5) == "host.") { - String key = macro.SubStr(5); + key = macro.SubStr(5); - if (key == "name") { + if (key.SubStr(0, 5) == "vars.") { + vars = GetVars(); + String vars_key = key.SubStr(5); + + if (vars && vars->Contains(vars_key)) { + *result = vars->Get(vars_key); + return true; + } + } + else if (key == "name") { *result = GetName(); return true; } @@ -369,13 +381,13 @@ bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re return true; } } - } + } else { + vars = GetVars(); - Dictionary::Ptr vars = GetVars(); - - if (vars && vars->Contains(macro)) { - *result = vars->Get(macro); - return true; + if (vars && vars->Contains(macro)) { + *result = vars->Get(macro); + return true; + } } return false; diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index c12f0b9ac..04b093d6e 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -128,11 +128,22 @@ String Service::StateTypeToString(StateType type) bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const { + String key; + Dictionary::Ptr vars; + /* require prefix for object macros */ if (macro.SubStr(0, 8) == "service.") { - String key = macro.SubStr(8); + key = macro.SubStr(8); - if (key == "description") { + if (key.SubStr(0, 5) == "vars.") { + vars = GetVars(); + String vars_key = key.SubStr(5); + + if (vars && vars->Contains(vars_key)) { + *result = vars->Get(vars_key); + return true; + } + } else if (key == "description") { *result = GetShortName(); return true; } else if (key == "displayname") { @@ -199,13 +210,13 @@ bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Stri return true; } } - } + } else { + vars = GetVars(); - Dictionary::Ptr vars = GetVars(); - - if (vars && vars->Contains(macro)) { - *result = vars->Get(macro); - return true; + if (vars && vars->Contains(macro)) { + *result = vars->Get(macro); + return true; + } } return false; diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index 1feb9f8c7..4568ce84f 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -68,24 +68,35 @@ TimePeriod::Ptr User::GetNotificationPeriod(void) const bool User::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const { + String key; + Dictionary::Ptr vars; + /* require prefix for object macros */ if (macro.SubStr(0, 5) == "user.") { - String key = macro.SubStr(5); + key = macro.SubStr(5); - if (key == "name") { + if (key.SubStr(0, 5) == "vars.") { + vars = GetVars(); + String vars_key = key.SubStr(5); + + if (vars && vars->Contains(vars_key)) { + *result = vars->Get(vars_key); + return true; + } + } else if (key == "name") { *result = GetName(); return true; } else if (key == "displayname") { *result = GetDisplayName(); return true; } - } + } else { + vars = GetVars(); - Dictionary::Ptr vars = GetVars(); - - if (vars && vars->Contains(macro)) { - *result = vars->Get(macro); - return true; + if (vars && vars->Contains(macro)) { + *result = vars->Get(macro); + return true; + } } return false;