2 ## <a id="custom-attributes"></a> Custom Attributes
4 ### <a id="runtime-custom-attributes"></a> Using Custom Attributes at Runtime
6 Custom attributes may be used in command definitions to dynamically change how the command
9 Additionally there are Icinga 2 features such as the `PerfDataWriter` type
10 which use custom attributes to format their output.
14 > Custom attributes are identified by the 'vars' dictionary attribute as short name.
15 > Accessing the different attribute keys is possible using the '.' accessor.
17 Custom attributes in command definitions or performance data templates are evaluated at
18 runtime when executing a command. These custom attributes cannot be used elsewhere
19 (e.g. in other configuration attributes).
21 Here is an example of a command definition which uses user-defined custom attributes:
23 object CheckCommand "my-ping" {
24 import "plugin-check-command"
27 PluginDir + "/check_ping",
30 "-w", "$wrta$,$wpl$%",
31 "-c", "$crta$,$cpl$%",
44 Custom attribute names used at runtime must be enclosed in two `$` signs, e.g.
45 `$address$`. When using the `$` sign as single character, you need to escape
46 it with an additional dollar sign (`$$`).
48 ### <a id="runtime-custom-attributes-evaluation-order"></a> Runtime Custom Attributes Evaluation Order
50 When executing commands Icinga 2 checks the following objects in this order to look
51 up custom attributes and their respective values:
53 1. User object (only for notifications)
57 5. Global custom attributes in the Vars constant
59 This execution order allows you to define default values for custom attributes
60 in your command objects. The `my-ping` command shown above uses this to set
61 default values for some of the latency thresholds and timeouts.
63 When using the `my-ping` command you can override all or some of the custom
64 attributes in the service definition like this:
66 object Service "ping" {
67 host_name = "localhost"
68 check_command = "my-ping"
70 vars.packets = 10 // Overrides the default value of 5 given in the command
73 If a custom attribute isn't defined anywhere an empty value is used and a warning is
74 emitted to the Icinga 2 log.
79 > By convention every host should have an `address` custom attribute. Hosts
80 > which have an IPv6 address should also have an `address6` custom attribute.
81 > This may also be mandatory requirement for using user interfaces and addons.
83 ### <a id="runtime-custom-attribute-env-vars"></a> Runtime Custom Attributes as Environment Variables
87 The `env` command object attribute specifies a list of environment variables with values calculated
88 from either runtime macros or custom attributes which should be exported as environment variables
89 prior to executing the command.
91 This is useful for example for hiding sensitive information on the command line output
92 when passing credentials to database checks:
94 object CheckCommand "mysql-health" {
95 import "plugin-check-command",
97 command = PluginDir + "/check_mysql -H $address$ -d $db$",
98 /* default custom attribute values */
100 mysql_user = "icinga_check",
101 mysql_pass = "password"
105 MYSQLUSER = "$mysql_user$",
106 MYSQLPASS = "$mysql_pass$"
110 ## <a id="runtime-macros"></a> Runtime Macros
112 Next to custom attributes there are additional runtime macros made available by Icinga 2.
113 These runtime macros reflect the current object state and may change over time while
114 custom attributes are configured statically (but can be modified at runtime using
117 ### <a id="host-runtime-macros"></a> Host Runtime Macros
119 The following host custom attributes are available in all commands that are executed for
123 -----------------------------|--------------
124 host.name | The name of the host object.
125 host.display_name | The value of the `display_name` attribute.
126 host.state | The host's current state. Can be one of `UNREACHABLE`, `UP` and `DOWN`.
127 host.stateid | The host's current state. Can be one of `0` (up), `1` (down) and `2` (unreachable).
128 host.statetype | The host's current state type. Can be one of `SOFT` and `HARD`.
129 host.check_attempt | The current check attempt number.
130 host.max_check_attempts | The maximum number of checks which are executed before changing to a hard state.
131 host.last_state | The host's previous state. Can be one of `UNREACHABLE`, `UP` and `DOWN`.
132 host.last_state_id | The host's previous state. Can be one of `0` (up), `1` (down) and `2` (unreachable).
133 host.last_state_type | The host's previous state type. Can be one of `SOFT` and `HARD`.
134 host.last_state_change | The last state change's timestamp.
135 host.duration_sec | The time since the last state change.
136 host.latency | The host's check latency.
137 host.execution_time | The host's check execution time.
138 host.output | The last check's output.
139 host.perfdata | The last check's performance data.
140 host.last_check | The timestamp when the last check was executed.
141 host.total_services | Number of services associated with the host.
142 host.total_services_ok | Number of services associated with the host which are in an `OK` state.
143 host.total_services_warning | Number of services associated with the host which are in a `WARNING` state.
144 host.total_services_unknown | Number of services associated with the host which are in an `UNKNOWN` state.
145 host.total_services_critical | Number of services associated with the host which are in a `CRITICAL` state.
147 ### <a id="service-runtime-macros"></a> Service Runtime Macros
149 The following service macros are available in all commands that are executed for
153 ---------------------------|--------------
154 service.name | The short name of the service object.
155 service.display_name | The value of the `display_name` attribute.
156 service.check_command | This is an alias for the `SERVICEDISPLAYNAME` macro.
157 service.state | The service's current state. Can be one of `OK`, `WARNING`, `CRITICAL` and `UNKNOWN`.
158 service.state_id | The service's current state. Can be one of `0` (ok), `1` (warning), `2` (critical) and `3` (unknown).
159 service.state_type | The service's current state type. Can be one of `SOFT` and `HARD`.
160 service.check_attempt | The current check attempt number.
161 service.max_check_attempts | The maximum number of checks which are executed before changing to a hard state.
162 service.last_state | The service's previous state. Can be one of `OK`, `WARNING`, `CRITICAL` and `UNKNOWN`.
163 service.last_state_id | The service's previous state. Can be one of `0` (ok), `1` (warning), `2` (critical) and `3` (unknown).
164 service.last_state_type | The service's previous state type. Can be one of `SOFT` and `HARD`.
165 service.last_state_change | The last state change's timestamp.
166 service.duration_sec | The time since the last state change.
167 service.latency | The service's check latency.
168 service.execution_time | The service's check execution time.
169 service.output | The last check's output.
170 service.perfdata | The last check's performance data.
171 service.last_check | The timestamp when the last check was executed.
173 ### <a id="command-runtime-macros"></a> Command Runtime Macros
175 The following custom attributes are available in all commands:
178 -----------------------|--------------
179 command.name | The name of the command object.
181 ### <a id="user-runtime-macros"></a> User Runtime Macros
183 The following custom attributes are available in all commands that are executed for
187 -----------------------|--------------
188 user.name | The name of the user object.
189 user.display_name | The value of the display_name attribute.
191 ### <a id="notification-runtime-macros"></a> Notification Runtime Macros
194 -----------------------|--------------
195 notification.type | The type of the notification.
196 notification.author | The author of the notification comment, if existing.
197 notification.comment | The comment of the notification, if existing.
199 ### <a id="global-runtime-macros"></a> Global Runtime Macros
201 The following macros are available in all executed commands:
204 -----------------------|--------------
205 icinga.timet | Current UNIX timestamp.
206 icinga.long_date_time | Current date and time including timezone information. Example: `2014-01-03 11:23:08 +0000`
207 icinga.short_date_time | Current date and time. Example: `2014-01-03 11:23:08`
208 icinga.date | Current date. Example: `2014-01-03`
209 icinga.time | Current time including timezone information. Example: `11:23:08 +0000`