Access custom attributes as ${host,service,user}.vars.<name>$.

Refs #5855
This commit is contained in:
Michael Friedrich 2014-04-05 17:13:17 +02:00
parent 34092f0a52
commit e309a5d330
3 changed files with 58 additions and 24 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;