H.2 Variable and Macros

You can define your own variables in the objects host, service, and contact. The names of these always begin with an underscore and are inherited like normal variables:

define host {
   host_name linux01
   use       host_site_t,host_generic_t
   ...
   _NRPE_PORT 5666
}

The variable _NRPE_PORT is accessed with $_HOSTNRPE_PORT$, which means that the object type (HOST, SERVICE, or CONTACT) is added after the underscore. This is slightly unfortunate, as it is more difficult to read. The macro created can be used elsewhere, for example in the definition of a command:

define command {
   command_name check_nrpe
   command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p $_HOSTNRPE_PORT$
-c $ARG1$
}

Macros allow access to configuration data, states, and check ...

Get Nagios, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.