2013-10-10 19:05:49 +02:00
|
|
|
|
2014-04-06 10:57:51 +02:00
|
|
|
## <a id="custom-attributes"></a> Custom Attributes
|
2014-02-05 14:27:06 +01:00
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
### <a id="runtime-custom-attributes"></a> Using Custom Attributes at Runtime
|
2014-02-05 14:27:06 +01:00
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
Custom attributes may be used in command definitions to dynamically change how the command
|
2013-10-01 12:59:02 +02:00
|
|
|
is executed.
|
2014-04-06 10:57:51 +02:00
|
|
|
|
|
|
|
Additionally there are Icinga 2 features such as the `PerfDataWriter` type
|
|
|
|
which use custom attributes to format their output.
|
2014-04-04 18:41:54 +02:00
|
|
|
|
|
|
|
> **Tip**
|
|
|
|
>
|
|
|
|
> Custom attributes are identified by the 'vars' dictionary attribute as short name.
|
|
|
|
> Accessing the different attribute keys is possible using the '.' accessor.
|
2014-02-05 14:27:06 +01:00
|
|
|
|
2014-04-06 21:15:25 +02:00
|
|
|
Custom attributes in command definitions or performance data templates are evaluated at
|
|
|
|
runtime when executing a command. These custom attributes cannot be used elsewhere
|
|
|
|
(e.g. in other configuration attributes).
|
2013-09-27 10:44:24 +02:00
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
Here is an example of a command definition which uses user-defined custom attributes:
|
2013-09-27 10:44:24 +02:00
|
|
|
|
2014-03-27 12:30:24 +01:00
|
|
|
object CheckCommand "my-ping" {
|
2014-03-31 18:38:15 +02:00
|
|
|
import "plugin-check-command"
|
2014-03-27 12:30:24 +01:00
|
|
|
|
2013-10-01 12:59:02 +02:00
|
|
|
command = [
|
2014-03-31 13:27:39 +02:00
|
|
|
PluginDir + "/check_ping",
|
2013-10-01 12:59:02 +02:00
|
|
|
"-4",
|
|
|
|
"-H", "$address$",
|
|
|
|
"-w", "$wrta$,$wpl$%",
|
|
|
|
"-c", "$crta$,$cpl$%",
|
|
|
|
"-p", "$packets$",
|
|
|
|
"-t", "$timeout$"
|
2014-04-04 18:41:54 +02:00
|
|
|
]
|
2013-10-01 12:59:02 +02:00
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
vars.wrta = 100
|
|
|
|
vars.wpl = 5
|
|
|
|
vars.crta = 200
|
|
|
|
vars.cpl = 15
|
|
|
|
vars.packets = 5
|
|
|
|
vars.timeout = 0
|
2013-10-01 12:59:02 +02:00
|
|
|
}
|
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
Custom attribute names used at runtime must be enclosed in two `$` signs, e.g.
|
|
|
|
`$address$`. When using the `$` sign as single character, you need to escape
|
|
|
|
it with an additional dollar sign (`$$`).
|
2013-12-19 14:31:35 +01:00
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
### <a id="runtime-custom-attributes-evaluation-order"></a> Runtime Custom Attributes Evaluation Order
|
2014-02-05 14:27:06 +01:00
|
|
|
|
2013-12-19 14:31:35 +01:00
|
|
|
When executing commands Icinga 2 checks the following objects in this order to look
|
2014-04-04 18:41:54 +02:00
|
|
|
up custom attributes and their respective values:
|
2013-10-01 12:59:02 +02:00
|
|
|
|
|
|
|
1. User object (only for notifications)
|
|
|
|
2. Service object
|
|
|
|
3. Host object
|
|
|
|
4. Command object
|
2014-04-03 10:30:11 +02:00
|
|
|
5. Global custom attributes in the IcingaVars constant
|
2013-10-01 12:59:02 +02:00
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
This execution order allows you to define default values for custom attributes
|
|
|
|
in your command objects. The `my-ping` command shown above uses this to set
|
|
|
|
default values for some of the latency thresholds and timeouts.
|
2013-10-01 12:59:02 +02:00
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
When using the `my-ping` command you can override all or some of the custom
|
|
|
|
attributes in the service definition like this:
|
2013-10-01 12:59:02 +02:00
|
|
|
|
2014-04-05 14:53:12 +02:00
|
|
|
object Service "ping" {
|
|
|
|
host_name = "localhost"
|
2014-03-31 18:38:15 +02:00
|
|
|
check_command = "my-ping"
|
2013-10-01 12:59:02 +02:00
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
vars.packets = 10 // Overrides the default value of 5 given in the command
|
2013-10-01 12:59:02 +02:00
|
|
|
}
|
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
If a custom attribute isn't defined anywhere an empty value is used and a warning is
|
2013-10-01 12:59:02 +02:00
|
|
|
emitted to the Icinga 2 log.
|
|
|
|
|
|
|
|
|
2014-02-05 14:27:06 +01:00
|
|
|
> **Best Practice**
|
|
|
|
>
|
2014-04-04 18:41:54 +02:00
|
|
|
> By convention every host should have an `address` custom attribute. Hosts
|
|
|
|
> which have an IPv6 address should also have an `address6` custom attribute.
|
2014-04-05 14:53:12 +02:00
|
|
|
> This may also be mandatory requirement for using user interfaces and addons.
|
2014-04-04 18:41:54 +02:00
|
|
|
|
|
|
|
### <a id="runtime-custom-attribute-env-vars"></a> Runtime Custom Attributes as Environment Variables
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
2014-04-05 14:53:12 +02:00
|
|
|
The `env` command object attribute specifies a list of environment variables with values calculated
|
2014-04-04 22:57:56 +02:00
|
|
|
from either runtime macros or custom attributes which should be exported as environment variables
|
|
|
|
prior to executing the command.
|
2014-04-04 18:41:54 +02:00
|
|
|
|
|
|
|
This is useful for example for hiding sensitive information on the command line output
|
|
|
|
when passing credentials to database checks:
|
|
|
|
|
|
|
|
object CheckCommand "mysql-health" {
|
|
|
|
import "plugin-check-command",
|
|
|
|
|
|
|
|
command = PluginDir + "/check_mysql -H $address$ -d $db$",
|
|
|
|
/* default custom attribute values */
|
|
|
|
vars = {
|
2014-04-05 14:53:12 +02:00
|
|
|
mysql_user = "icinga_check",
|
|
|
|
mysql_pass = "password"
|
2014-04-04 18:41:54 +02:00
|
|
|
},
|
|
|
|
|
2014-04-04 22:57:56 +02:00
|
|
|
env = {
|
2014-04-05 14:53:12 +02:00
|
|
|
MYSQLUSER = "$mysql_user$",
|
|
|
|
MYSQLPASS = "$mysql_pass$"
|
2014-04-04 22:57:56 +02:00
|
|
|
}
|
2014-04-04 18:41:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
## <a id="runtime-macros"></a> Runtime Macros
|
|
|
|
|
|
|
|
Next to custom attributes there are additional runtime macros made available by Icinga 2.
|
|
|
|
These runtime macros reflect the current object state and may change over time while
|
|
|
|
custom attributes are configured statically (but can be modified at runtime using
|
|
|
|
external commands).
|
2014-02-05 14:27:06 +01:00
|
|
|
|
|
|
|
### <a id="host-runtime-macros"></a> Host Runtime Macros
|
2013-10-01 12:59:02 +02:00
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
The following host custom attributes are available in all commands that are executed for
|
2013-10-01 12:59:02 +02:00
|
|
|
hosts or services:
|
|
|
|
|
2014-04-05 14:53:12 +02:00
|
|
|
Name | Description
|
|
|
|
---------------------------|--------------
|
|
|
|
host.name | The name of the host object.
|
|
|
|
host.displayname | The value of the `display_name` attribute.
|
|
|
|
host.state | The host's current state. Can be one of `UNREACHABLE`, `UP` and `DOWN`.
|
|
|
|
host.stateid | The host's current state. Can be one of `0` (up), `1` (down) and `2` (unreachable).
|
|
|
|
host.statetype | The host's current state type. Can be one of `SOFT` and `HARD`.
|
|
|
|
host.attempt | The current check attempt number.
|
|
|
|
host.maxattempt | The maximum number of checks which are executed before changing to a hard state.
|
|
|
|
host.laststate | The host's previous state. Can be one of `UNREACHABLE`, `UP` and `DOWN`.
|
|
|
|
host.laststateid | The host's previous state. Can be one of `0` (up), `1` (down) and `2` (unreachable).
|
|
|
|
host.laststatetype | The host's previous state type. Can be one of `SOFT` and `HARD`.
|
|
|
|
host.laststatechange | The last state change's timestamp.
|
|
|
|
host.durationsec | The time since the last state change.
|
|
|
|
host.latency | The host's check latency.
|
|
|
|
host.executiontime | The host's check execution time.
|
|
|
|
host.output | The last check's output.
|
|
|
|
host.perfdata | The last check's performance data.
|
|
|
|
host.lastcheck | The timestamp when the last check was executed.
|
2014-04-04 20:09:23 +02:00
|
|
|
host.totalservices | Number of services associated with the host.
|
|
|
|
host.totalservicesok | Number of services associated with the host which are in an `OK` state.
|
|
|
|
host.totalserviceswarning | Number of services associated with the host which are in a `WARNING` 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.
|
2013-10-01 12:59:02 +02:00
|
|
|
|
2014-02-05 14:27:06 +01:00
|
|
|
### <a id="service-runtime-macros"></a> Service Runtime Macros
|
2013-10-01 12:59:02 +02:00
|
|
|
|
|
|
|
The following service macros are available in all commands that are executed for
|
|
|
|
services:
|
|
|
|
|
2014-04-05 14:53:12 +02:00
|
|
|
Name | Description
|
|
|
|
------------------------|--------------
|
|
|
|
service.description | The short name of the service object.
|
|
|
|
service.displayname | The value of the `display_name` attribute.
|
|
|
|
service.checkcommand | This is an alias for the `SERVICEDISPLAYNAME` macro.
|
|
|
|
service.state | The service's current state. Can be one of `OK`, `WARNING`, `CRITICAL` and `UNKNOWN`.
|
|
|
|
service.stateid | The service's current state. Can be one of `0` (ok), `1` (warning), `2` (critical) and `3` (unknown).
|
|
|
|
service.statetype | The service's current state type. Can be one of `SOFT` and `HARD`.
|
|
|
|
service.attempt | The current check attempt number.
|
|
|
|
service.maxattempt | The maximum number of checks which are executed before changing to a hard state.
|
|
|
|
service.laststate | The service's previous state. Can be one of `OK`, `WARNING`, `CRITICAL` and `UNKNOWN`.
|
|
|
|
service.laststateid | The service's previous state. Can be one of `0` (ok), `1` (warning), `2` (critical) and `3` (unknown).
|
|
|
|
service.laststatetype | The service's previous state type. Can be one of `SOFT` and `HARD`.
|
|
|
|
service.laststatechange | The last state change's timestamp.
|
|
|
|
service.durationsec | The time since the last state change.
|
|
|
|
service.latency | The service's check latency.
|
|
|
|
service.executiontime | The service's check execution time.
|
|
|
|
service.output | The last check's output.
|
|
|
|
service.perfdata | The last check's performance data.
|
|
|
|
service.lastcheck | The timestamp when the last check was executed.
|
2013-12-18 10:53:26 +01:00
|
|
|
|
2014-02-05 14:27:06 +01:00
|
|
|
### <a id="user-runtime-macros"></a> User Runtime Macros
|
2013-10-01 12:59:02 +02:00
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
The following custom attributes are available in all commands that are executed for
|
2013-10-01 12:59:02 +02:00
|
|
|
users:
|
|
|
|
|
2013-10-01 15:33:34 +02:00
|
|
|
Name | Description
|
|
|
|
-----------------------|--------------
|
2014-04-04 21:36:47 +02:00
|
|
|
user.name | The name of the user object.
|
|
|
|
user.displayname | The value of the display_name attribute.
|
2013-12-18 10:53:26 +01:00
|
|
|
|
2014-02-05 14:27:06 +01:00
|
|
|
|
|
|
|
### <a id="notification-runtime-macros"></a> Notification Runtime Macros
|
2013-12-18 10:53:26 +01:00
|
|
|
|
2014-04-04 22:57:56 +02:00
|
|
|
Name | Description
|
|
|
|
-----------------------|--------------
|
|
|
|
notification.type | The type of the notification.
|
|
|
|
notification.author | The author of the notification comment, if existing.
|
|
|
|
notification.comment | The comment of the notification, if existing.
|
2013-12-18 10:53:26 +01:00
|
|
|
|
2014-02-05 14:27:06 +01:00
|
|
|
### <a id="global-runtime-macros"></a> Global Runtime Macros
|
2013-10-01 15:33:34 +02:00
|
|
|
|
2014-02-05 14:27:06 +01:00
|
|
|
The following macros are available in all executed commands:
|
2013-10-01 15:33:34 +02:00
|
|
|
|
|
|
|
Name | Description
|
|
|
|
-----------------------|--------------
|
2014-04-04 19:35:47 +02:00
|
|
|
icinga.timet | Current UNIX timestamp.
|
|
|
|
icinga.longdatetime | Current date and time including timezone information. Example: `2014-01-03 11:23:08 +0000`
|
|
|
|
icinga.shortdatetime | Current date and time. Example: `2014-01-03 11:23:08`
|
|
|
|
icinga.date | Current date. Example: `2014-01-03`
|
|
|
|
icinga.time | Current time including timezone information. Example: `11:23:08 +0000`
|