Implement $user.<name>$ runtime macros.

Refs #5855
This commit is contained in:
Michael Friedrich 2014-04-04 21:36:47 +02:00
parent 0a0399826f
commit aba4f1a0d5
3 changed files with 23 additions and 45 deletions

View File

@ -152,8 +152,6 @@ external commands).
### <a id="host-runtime-macros"></a> Host Runtime Macros ### <a id="host-runtime-macros"></a> Host Runtime Macros
TODO
The following host custom attributes are available in all commands that are executed for The following host custom attributes are available in all commands that are executed for
hosts or services: 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.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. 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.
### <a id="service-runtime-macros"></a> Service Runtime Macros ### <a id="service-runtime-macros"></a> Service Runtime Macros
TODO
The following service macros are available in all commands that are executed for The following service macros are available in all commands that are executed for
services: services:
@ -220,18 +210,13 @@ services:
### <a id="user-runtime-macros"></a> User Runtime Macros ### <a id="user-runtime-macros"></a> User Runtime Macros
TODO
The following custom attributes are available in all commands that are executed for The following custom attributes are available in all commands that are executed for
users: users:
Name | Description Name | Description
-----------------------|-------------- -----------------------|--------------
USERNAME | The name of the user object. user.name | The name of the user object.
USERDISPLAYNAME | The value of the display_name attribute. user.displayname | 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.
### <a id="notification-runtime-macros"></a> Notification Runtime Macros ### <a id="notification-runtime-macros"></a> Notification Runtime Macros

View File

@ -305,6 +305,11 @@ Changes to host runtime macros
Icinga 1.x | Icinga 2 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 Changes to service runtime macros

View File

@ -68,37 +68,25 @@ TimePeriod::Ptr User::GetNotificationPeriod(void) const
bool User::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const bool User::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
{ {
if (macro == "USERNAME" || macro == "CONTACTNAME") { /* require prefix for object macros */
*result = GetName(); if (macro.SubStr(0, 5) == "user.") {
return true; String key = macro.SubStr(5);
} 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;
if (macro == "USEREMAIL" || macro == "CONTACTEMAIL") if (key == "name") {
tmacro = "email"; *result = GetName();
else if (macro == "USERPAGER" || macro == "CONTACTPAGER") return true;
tmacro = "pager"; } else if (key == "displayname") {
else *result = GetDisplayName();
tmacro = macro;
Dictionary::Ptr vars = GetVars();
if (vars && vars->Contains(tmacro)) {
*result = vars->Get(tmacro);
return true; return true;
} }
return false; Dictionary::Ptr vars = GetVars();
if (vars && vars->Contains(key)) {
*result = vars->Get(key);
return true;
}
} }
return false;
} }