diff --git a/doc/3.03-custom-attributes-runtime-macros.md b/doc/3.03-custom-attributes-runtime-macros.md index e904bf29f..6f438bcf9 100644 --- a/doc/3.03-custom-attributes-runtime-macros.md +++ b/doc/3.03-custom-attributes-runtime-macros.md @@ -152,8 +152,6 @@ external commands). ### Host Runtime Macros -TODO - The following host custom attributes are available in all commands that are executed for hosts or services: @@ -182,16 +180,8 @@ hosts or services: host.totalservicesunknown | Number of services associated with the host which are in an `UNKNOWN` state. host.totalservicescritical | Number of services associated with the host which are in a `CRITICAL` state. -> **Note** -> -> `HOSTADDRESS` and `HOSTADDRESS6` macros are available as legacy vars. The -> Icinga 2 Template Library (`ITL`) examples use the `$address$` macro instead -> requiring that macro key to be defined. - ### Service Runtime Macros -TODO - The following service macros are available in all commands that are executed for services: @@ -220,18 +210,13 @@ services: ### User Runtime Macros -TODO - The following custom attributes are available in all commands that are executed for users: Name | Description -----------------------|-------------- - USERNAME | The name of the user object. - USERDISPLAYNAME | The value of the display_name attribute. - USEREMAIL | This is an alias for the `email` macro. - USERPAGER | This is an alias for the `pager` macro. - + user.name | The name of the user object. + user.displayname | The value of the display_name attribute. ### Notification Runtime Macros diff --git a/doc/8-differences-between-icinga-1x-and-2.md b/doc/8-differences-between-icinga-1x-and-2.md index dde71baaa..30a65a2fd 100644 --- a/doc/8-differences-between-icinga-1x-and-2.md +++ b/doc/8-differences-between-icinga-1x-and-2.md @@ -305,6 +305,11 @@ Changes to host runtime macros Icinga 1.x | Icinga 2 -----------------------|---------------------- + USERNAME | user.name + USERDISPLAYNAME | user.displayname + USEREMAIL | email if set as `email` custom attribute. + USERPAGER | pager if set as `pager` custom attribute. + Changes to service runtime macros diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index 966c08f90..62c0d1fe0 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -68,37 +68,25 @@ TimePeriod::Ptr User::GetNotificationPeriod(void) const bool User::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const { - if (macro == "USERNAME" || macro == "CONTACTNAME") { - *result = GetName(); - return true; - } else if (macro == "USERDISPLAYNAME" || macro == "CONTACTALIAS") { - *result = GetDisplayName(); - return true; - } else if (macro.SubStr(0, 5) == "_USER") { - Dictionary::Ptr vars = GetVars(); - *result = vars ? vars->Get(macro.SubStr(5)) : ""; - return true; - } else if (macro.SubStr(0, 8) == "_CONTACT") { - Dictionary::Ptr vars = GetVars(); - *result = vars ? vars->Get(macro.SubStr(8)) : ""; - return true; - } else { - String tmacro; + /* require prefix for object macros */ + if (macro.SubStr(0, 5) == "user.") { + String key = macro.SubStr(5); - if (macro == "USEREMAIL" || macro == "CONTACTEMAIL") - tmacro = "email"; - else if (macro == "USERPAGER" || macro == "CONTACTPAGER") - tmacro = "pager"; - else - tmacro = macro; - - Dictionary::Ptr vars = GetVars(); - - if (vars && vars->Contains(tmacro)) { - *result = vars->Get(tmacro); + if (key == "name") { + *result = GetName(); + return true; + } else if (key == "displayname") { + *result = GetDisplayName(); return true; } - return false; + Dictionary::Ptr vars = GetVars(); + + if (vars && vars->Contains(key)) { + *result = vars->Get(key); + return true; + } } + + return false; }