## Using Macros In Commands

Macros

One of the features available in Nagios is the ability to use macros in command defintions. Immediately prior to the execution of a command, Nagios will replace all macros in the command with their corresponding values. This allows you to define a few generic commands to handle all your needs.

Macro Substitution

Before any commands (host and service checks, notifications, event handlers, etc.) are executed, Nagios will replace any macros it finds in the command definition with their corresponding values.

When you use host and service macros in command definitions, they refer to values for the host or service for which the command is being run. Let's try an example. Assuming we are using a host definition and a check_ping command defined like this:

    define host{
    	host_name		linuxbox
    	address		192.168.1.2
    	check_command	check_ping
    	...
    	}

    define command{
    	command_name    check_ping
    	command_line    /usr/local/nagios/libexec/check_ping -H $HOSTADDRESS$ -w 100.0,90% -c 200.0,60%
    	}

the expanded/final command line to be executed for the host's check command would look like this:

    	/usr/local/nagios/libexec/check_ping -H 192.168.1.2 -w 100.0,90% -c 200.0,60%

You can pass arguments to commands as well, which is quite handy if you'd like to keep your command definitions rather generic. Arguments are specified in the object (i.e. host or service) definition, by seperating them from the command name with exclamation points (!) like so:

    define service{
    	host_name		linuxbox
    	service_description	PING
    	...
    	check_command	check_ping!200.0,80%!400.0,40%
    	...
    	}

In the example above, the service check command has two arguments (which can be referenced with $ARGn$ macros). The $ARG1$ macro will be "200.0,80%" and $ARG2$ will be "400.0,40%" (both without quotes). Assuming we are using the host definition given earlier and a check_ping command defined like this:

    define command{
    	command_name    check_ping
    	command_line    /usr/local/nagios/libexec/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
    	}

the expanded/final command line to be executed for the service's check command would look like this:

    	/usr/local/nagios/libexec/check_ping -H 192.168.1.2 -w 200.0,80% -c 400.0,40%

On-Demand Macros

Normally when you use host and service macros in command definitions, they refer to values for the host or service for which the command is being run. For instance, if a host check command is being executed for a host named "linuxbox", all the host macros listed in the table below will refer to values for that host ("linuxbox").

If you would like to reference values for another host or service in a command (for which the command is not being run), you can use what are called "on-demand" macros. On-demand macros look like normal macros, except for the fact that they contain an identifier for the host or service from which they should get their value. Here's the basic format for on-demand macros:

- $HOSTMACRO:host_name$
- $SERVICEMACRO:host_name:service_description$

Note that the macro name is seperated from the host or service identifier by a colon (:). For on-demand service macros, the service identifier consists of both a host name and a service description - these are seperated by a colon (:) as well.

Examples of on-demand host and service macros follow:

    $HOSTDOWNTIME:myhost$
    $SERVICESTATEID:novellserver:DS Database$

Macro Cleansing

Some macros are stripped of potentially dangerous shell metacharacters before being substituted into commands to be executed. Which characters are stripped from the macros depends on the setting of the illegal_macro_output_chars directive. The following macros are stripped of potentially dangerous characters:

1. $HOSTOUTPUT$
2. $HOSTPERFDATA$
3. $HOSTACKAUTHOR$
4. $HOSTACKCOMMENT$
5. $SERVICEOUTPUT$
6. $SERVICEPERFDATA$
7. $SERVICEACKAUTHOR$
8. $SERVICEACKCOMMENT$

Macros as Environment Variables

Starting with Nagios 2.0, most macros have been made available as environment variables. This means that scripts that are run from Nagios (i.e. service and host check commands, notification commands, etc.) can reference these macros directly as standard environment variables. For purposes of security and sanity, $USERn$ and "on-demand" host and service macros are not made available as environment variables. Environment variables that contain macros are named the same as their corresponding macro names (listed below), with "NAGIOS_" prepended to their names. For example, the $HOSTNAME$ macro would be available as an environment variable named "NAGIOS_HOSTNAME".

Macro Validity

Although macros can be used in all commands you define, not all macros may be "valid" in a particular type of command. For example, some macros may only be valid during service notification commands, whereas other may only be valid during host check commands. There are ten types of commands that Nagios recognizes and treats differently. They are as follows:

1. Service checks
2. Service notifications
3. Host checks
4. Host notifications
5. Service event handlers and/or a global service event handler
6. Host event handlers and/or a global host event handler
7. OCSP command
8. OCHP command
9. Service performance data commands
10. Host performance data commands

The tables below list all macros currently available in Nagios, along with a brief description of each and the types of commands in which they are valid. If a macro is used in a command in which it is invalid, it is replaced with an empty string. It should be noted that macros consist of all uppercase characters and are enclosed in $ characters.

Macro Availability Chart

Legend:

No | The macro is not available
Yes | The macro is available

Macro Name | Service Checks | Service Notifications | Host Checks | Host Notifications | Service Event Handlers, Global Service Event Handler, OCSP Command | Host Event Handlers, Global Host Event Handler, OCHP Command | Service Performance Data Commands | Host Performance Data Commands
--- | --- | --- | --- | --- | --- | --- | --- | ---
Host Macros: 3
$HOSTNAME$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTALIAS$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTADDRESS$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTSTATE$ | Yes | Yes | Yes 1 | Yes | Yes | Yes | Yes | Yes
$HOSTSTATEID$ | Yes | Yes | Yes 1 | Yes | Yes | Yes | Yes | Yes
$HOSTSTATETYPE$ | Yes | Yes | Yes 1 | Yes | Yes | Yes | Yes | Yes
$HOSTATTEMPT$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTLATENCY$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTEXECUTIONTIME$ | Yes | Yes | Yes 1 | Yes | Yes | Yes | Yes | Yes
$HOSTDURATION$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTDURATIONSEC$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTDOWNTIME$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTPERCENTCHANGE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTGROUPNAME$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTGROUPALIAS$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$LASTHOSTCHECK$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$LASTHOSTSTATECHANGE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$LASTHOSTUP$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$LASTHOSTDOWN$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$LASTHOSTUNREACHABLE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTOUTPUT$ | Yes | Yes | Yes 1 | Yes | Yes | Yes | Yes | Yes
$HOSTPERFDATA$ | Yes | Yes | Yes 1 | Yes | Yes | Yes | Yes | Yes
$HOSTCHECKCOMMAND$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTACKAUTHOR$ | No | No | No | Yes | No | No | No | No
$HOSTACKCOMMENT$ | No | No | No | Yes | No | No | No | No
$HOSTACTIONURL$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTNOTESURL$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTNOTES$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
Service Macros:
$SERVICEDESC$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICESTATE$ | Yes 2 | Yes | No | No | Yes | No | Yes | No
$SERVICESTATEID$ | Yes 2 | Yes | No | No | Yes | No | Yes | No
$SERVICESTATETYPE$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICEATTEMPT$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICELATENCY$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICEEXECUTIONTIME$ | Yes 2 | Yes | No | No | Yes | No | Yes | No
$SERVICEDURATION$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICEDURATIONSEC$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICEDOWNTIME$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICEPERCENTCHANGE$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICEGROUPNAME$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICEGROUPALIAS$ | Yes | Yes | No | No | Yes | No | Yes | No
$LASTSERVICECHECK$ | Yes | Yes | No | No | Yes | No | Yes | No
$LASTSERVICESTATECHANGE$ | Yes | Yes | No | No | Yes | No | Yes | No
$LASTSERVICEOK$ | Yes | Yes | No | No | Yes | No | Yes | No
$LASTSERVICEWARNING$ | Yes | Yes | No | No | Yes | No | Yes | No
$LASTSERVICEUNKNOWN$ | Yes | Yes | No | No | Yes | No | Yes | No
$LASTSERVICECRITICAL$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICEOUTPUT$ | Yes 2 | Yes | No | No | Yes | No | Yes | No
$SERVICEPERFDATA$ | Yes 2 | Yes | No | No | Yes | No | Yes | No
$SERVICECHECKCOMMAND$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICEACKAUTHOR$ | No | Yes | No | No | No | No | No | No
$SERVICEACKCOMMENT$ | No | Yes | No | No | No | No | No | No
$SERVICEACTIONURL$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICENOTESURL$ | Yes | Yes | No | No | Yes | No | Yes | No
$SERVICENOTES$ | Yes | Yes | No | No | Yes | No | Yes | No
Summary Macros:
$TOTALHOSTSUP$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALHOSTSDOWN$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALHOSTSUNREACHABLE$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALHOSTSDOWNUNHANDLED$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALHOSTSUNREACHABLEUNHANDLED$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALHOSTPROBLEMS$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALHOSTPROBLEMSUNHANDLED$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALSERVICESOK$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALSERVICESWARNING$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALSERVICESCRITICAL$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALSERVICESUNKNOWN$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALSERVICESWARNINGUNHANDLED$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALSERVICESCRITICALUNHANDLED$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALSERVICESUNKNOWNUNHANDLED$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALSERVICEPROBLEMS$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
$TOTALSERVICEPROBLEMSUNHANDLED$ | Yes | Yes 4 | Yes | Yes 4 | Yes | Yes | Yes | Yes
Notification Macros:
$NOTIFICATIONTYPE$ | No | Yes | No | Yes | No | No | No | No
$NOTIFICATIONNUMBER$ | No | Yes | No | Yes | No | No | No | No
Contact Macros:
$CONTACTNAME$ | No | Yes | No | Yes | No | No | No | No
$CONTACTALIAS$ | No | Yes | No | Yes | No | No | No | No
$CONTACTEMAIL$ | No | Yes | No | Yes | No | No | No | No
$CONTACTPAGER$ | No | Yes | No | Yes | No | No | No | No
$CONTACTADDRESSn$ | No | Yes | No | Yes | No | No | No | No
Date Macros:
$LONGDATETIME$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$SHORTDATETIME$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$DATE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$TIME$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$TIMET$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
File Macros:
$MAINCONFIGFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$STATUSDATAFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$COMMENTDATAFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$DOWNTIMEDATAFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$RETENTIONDATAFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$OBJECTCACHEFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$TEMPFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$LOGFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$RESOURCEFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$COMMANDFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$HOSTPERFDATAFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$SERVICEPERFDATAFILE$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
Misc Macros:
$PROCESSSTARTTIME$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$ADMINEMAIL$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$ADMINPAGER$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$ARGn$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
$USERn$ | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes

Macro Descriptions

Host Macros: 3
$HOSTNAME$ | Short name for the host (i.e. "biglinuxbox"). This value is taken from the host_name directive in the host definition.
$HOSTALIAS$ | Long name/description for the host. This value is taken from the alias directive in the host definition.
$HOSTADDRESS$ | Address of the host. This value is taken from the address directive in the host definition.
$HOSTSTATE$ | A string indicating the current state of the host ("UP", "DOWN", or "UNREACHABLE").
$HOSTSTATEID$ | A number that corresponds to the current state of the host: 0=UP, 1=DOWN, 2=UNREACHABLE.
$HOSTSTATETYPE$ | A string indicating the state type for the current host check ("HARD" or "SOFT"). Soft states occur when host checks return a non-OK (non-UP) state and are in the process of being retried. Hard states result when host checks have been checked a specified maximum number of times.
$HOSTATTEMPT$ | The number of the current host check retry. For instance, if this is the second time that the host is being rechecked, this will be the number two. Current attempt number is really only useful when writing host event handlers for "soft" states that take a specific action based on the host retry number.
$HOSTLATENCY$ | A (floating point) number indicating the number of seconds that a scheduled host check lagged behind its scheduled check time. For instance, if a check was scheduled for 03:14:15 and it didn't get executed until 03:14:17, there would be a check latency of 2.0 seconds. On-demand host checks have a latency of zero seconds.
$HOSTEXECUTIONTIME$ | A (floating point) number indicating the number of seconds that the host check took to execute (i.e. the amount of time the check was executing).
$HOSTDURATION$ | A string indicating the amount of time that the host has spent in its current state. Format is "XXh YYm ZZs", indicating hours, minutes and seconds.
$HOSTDURATIONSEC$ | A number indicating the number of seconds that the host has spent in its current state.
$HOSTDOWNTIME$ | A number indicating the current "downtime depth" for the host. If this host is currently in a period of scheduled downtime, the value will be greater than zero. If the host is not currently in a period of downtime, this value will be zero.
$HOSTPERCENTCHANGE$ | A (floating point) number indicating the percent state change the host has undergone. Percent state change is used by the flap detection algorithm.
$HOSTGROUPNAME$ | The short name of the hostgroup that this host belongs to. This value is taken from the hostgroup_name directive in the hostgroup definition. If the host belongs to more than one hostgroup this macro will contain the name of just one of them.
$HOSTGROUPALIAS$ | The longer name/alias of the hostgroup that this host belongs to. This value is taken from the alias directive in the hostgroup definition. If the host belongs to more than one hostgroup, this macro contains the alias of just one of them.
$LASTHOSTCHECK$ | This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time at which a check of the host was last performed.
$LASTHOSTSTATECHANGE$ | This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time the host last changed state.
$LASTHOSTUP$ | This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time at which the host was last detected as being in an UP state.
$LASTHOSTDOWN$ | This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time at which the host was last detected as being in a DOWN state.
$LASTHOSTUNREACHABLE$ | This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time at which the host was last detected as being in an UNREACHABLE state.
$HOSTOUTPUT$ | The text output from the last host check (i.e. "Ping OK").
$HOSTPERFDATA$ | This macro contains any performance data that may have been returned by the last host check.
$HOSTCHECKCOMMAND$ | This macro contains the name of the command (along with any arguments passed to it) used to perform the host check.
$HOSTACKAUTHOR$ | A string containing the name of the user who acknowledged the host problem. This macro is only valid in notifications where the $NOTIFICATIONTYPE$ macro is set to "ACKNOWLEDGEMENT".
$HOSTACKCOMMENT$ | A string containing the acknowledgement comment that was entered by the user who acknowledged the host problem. This macro is only valid in notifications where the $NOTIFICATIONTYPE$ macro is set to "ACKNOWLEDGEMENT".
$HOSTACTIONURL$ | Action URL for the host. This value is taken from the action_url directive in the extended host information definition.
$HOSTNOTESURL$ | Notes URL for the host. This value is taken from the notes_url directive in the extended host information definition.
$HOSTNOTES$ | Notes for the host. This value is taken from the notes directive in the extended host information definition.
Service Macros:
$SERVICEDESC$ | The long name/description of the service (i.e. "Main Website"). This value is taken from the description directive of the service definition.
$SERVICESTATE$ | A string indicating the current state of the service ("OK", "WARNING", "UNKNOWN", or "CRITICAL").
$SERVICESTATEID$ | A number that corresponds to the current state of the service: 0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN.
$SERVICESTATETYPE$ | A string indicating the state type for the current service check ("HARD" or "SOFT"). Soft states occur when service checks return a non-OK state and are in the process of being retried. Hard states result when service checks have been checked a specified maximum number of times.
$SERVICEATTEMPT$ | The number of the current service check retry. For instance, if this is the second time that the service is being rechecked, this will be the number two. Current attempt number is really only useful when writing service event handlers for "soft" states that take a specific action based on the service retry number.
$SERVICELATENCY$ | A (floating point) number indicating the number of seconds that a scheduled service check lagged behind its scheduled check time. For instance, if a check was scheduled for 03:14:15 and it didn't get executed until 03:14:17, there would be a check latency of 2.0 seconds.
$SERVICEEXECUTIONTIME$ | A (floating point) number indicating the number of seconds that the service check took to execute (i.e. the amount of time the check was executing).
$SERVICEDURATION$ | A string indicating the amount of time that the service has spent in its current state. Format is "XXh YYm ZZs", indicating hours, minutes and seconds.
$SERVICEDURATIONSEC$ | A number indicating the number of seconds that the service has spent in its current state.
$SERVICEDOWNTIME$ | A number indicating the current "downtime depth" for the service. If this service is currently in a period of scheduled downtime, the value will be greater than zero. If the service is not currently in a period of downtime, this value will be zero.
$SERVICEPERCENTCHANGE$ | A (floating point) number indicating the percent state change the service has undergone. Percent state change is used by the flap detection algorithm.
$SERVICEGROUPNAME$ | The short name of the servicegroup that this service belongs to. This value is taken from the servicegroup_name directive in the servicegroup definition. If the service belongs to more than one servicegroup this macro will contain the name of just one of them.
$SERVICEGROUPALIAS$ | The long name/alias of the servicegroup that this service belongs to. This value is taken from the alias directive in the servicegroup definition. If the service belongs to more than one servicegroup this macro will contain the name of just one of them.
$LASTSERVICECHECK$ | This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time at which a check of the service was last performed.
$LASTSERVICESTATECHANGE$ | This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time the service last changed state.
$LASTSERVICEOK$ | This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time at which the service was last detected as being in an OK state.
$LASTSERVICEWARNING$ | This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time at which the service was last detected as being in a WARNING state.
$LASTSERVICEUNKNOWN$ | This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time at which the service was last detected as being in an UNKNOWN state.
$LASTSERVICECRITICAL$ | This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time at which the service was last detected as being in a CRITICAL state.
$SERVICEOUTPUT$ | The text output from the last service check (i.e. "Ping OK").
$SERVICEPERFDATA$ | This macro contains any performance data that may have been returned by the last service check.
$SERVICECHECKCOMMAND$ | This macro contains the name of the command (along with any arguments passed to it) used to perform the service check.
$SERVICEACKAUTHOR$ | A string containing the name of the user who acknowledged the service problem. This macro is only valid in notifications where the $NOTIFICATIONTYPE$ macro is set to "ACKNOWLEDGEMENT".
$SERVICEACKCOMMENT$ | A string containing the acknowledgement comment that was entered by the user who acknowledged the service problem. This macro is only valid in notifications where the $NOTIFICATIONTYPE$ macro is set to "ACKNOWLEDGEMENT".
$SERVICEACTIONURL$ | Action URL for the service. This value is taken from the action_url directive in the extended service information definition.
$SERVICENOTESURL$ | Notes URL for the service. This value is taken from the notes_url directive in the extended service information definition.
$SERVICENOTES$ | Notes for the service. This value is taken from the notes directive in the extended service information definition.
Notification Macros:
$NOTIFICATIONTYPE$ | A string identifying the type of notification that is being sent ("PROBLEM", "RECOVERY", "ACKNOWLEDGEMENT", "FLAPPINGSTART" or "FLAPPINGSTOP").
$NOTIFICATIONNUMBER$ | The current notification number for the service or host. The notification number increases by one (1) each time a new notification is sent out for a host or service (except for acknowledgements). The notification number is reset to 0 when the host or service recovers (after the recovery notification has gone out). Acknowledgements do not cause the notification number to increase.
SUMMARY Macros:
$TOTALHOSTSUP$ | This macro reflects the total number of hosts that are currently in an UP state.
$TOTALHOSTSDOWN$ | This macro reflects the total number of hosts that are currently in a DOWN state.
$TOTALHOSTSUNREACHABLE$ | This macro reflects the total number of hosts that are currently in an UNREACHABLE state.
$TOTALHOSTSDOWNUNHANDLED$ | This macro reflects the total number of hosts that are currently in a DOWN state that are not currently being "handled". Unhandled host problems are those that are not acknowledged, are not currently in scheduled downtime, and for which checks are currently enabled.
$TOTALHOSTSUNREACHABLEUNHANDLED$ | This macro reflects the total number of hosts that are currently in an UNREACHABLE state that are not currently being "handled". Unhandled host problems are those that are not acknowledged, are not currently in scheduled downtime, and for which checks are currently enabled.
$TOTALHOSTPROBLEMS$ | This macro reflects the total number of hosts that are currently either in a DOWN or an UNREACHABLE state.
$TOTALHOSTPROBLEMSUNHANDLED$ | This macro reflects the total number of hosts that are currently either in a DOWN or an UNREACHABLE state that are not currently being "handled". Unhandled host problems are those that are not acknowledged, are not currently in scheduled downtime, and for which checks are currently enabled.
$TOTALSERVICESOK$ | This macro reflects the total number of services that are currently in an OK state.
$TOTALSERVICESWARNING$ | This macro reflects the total number of services that are currently in a WARNING state.
$TOTALSERVICESCRITICAL$ | This macro reflects the total number of services that are currently in a CRITICAL state.
$TOTALSERVICESUNKNOWN$ | This macro reflects the total number of services that are currently in an UNKNOWN state.
$TOTALSERVICESWARNINGUNHANDLED$ | This macro reflects the total number of services that are currently in a WARNING state that are not currently being "handled". Unhandled services problems are those that are not acknowledged, are not currently in scheduled downtime, and for which checks are currently enabled.
$TOTALSERVICESCRITICALUNHANDLED$ | This macro reflects the total number of services that are currently in a CRITICAL state that are not currently being "handled". Unhandled services problems are those that are not acknowledged, are not currently in scheduled downtime, and for which checks are currently enabled.
$TOTALSERVICESUNKNOWNUNHANDLED$ | This macro reflects the total number of services that are currently in an UNKNOWN state that are not currently being "handled". Unhandled services problems are those that are not acknowledged, are not currently in scheduled downtime, and for which checks are currently enabled.
$TOTALSERVICEPROBLEMS$ | This macro reflects the total number of services that are currently either in a WARNING, CRITICAL, or UNKNOWN state.
$TOTALSERVICEPROBLEMSUNHANDLED$ | This macro reflects the total number of services that are currently either in a WARNING, CRITICAL, or UNKNOWN state that are not currently being "handled". Unhandled services problems are those that are not acknowledged, are not currently in scheduled downtime, and for which checks are currently enabled.
Contact Macros:
$CONTACTNAME$ | Short name for the contact (i.e. "jdoe") that is being notified of a host or service problem. This value is taken from the contact_name directive in the contact definition.
$CONTACTALIAS$ | Long name/description for the contact (i.e. "John Doe") being notified. This value is taken from the alias directive in the contact definition.
$CONTACTEMAIL$ | Email address of the contact being notified. This value is taken from the email directive in the contact definition.
$CONTACTPAGER$ | Pager number/address of the contact being notified. This value is taken from the pager directive in the contact definition.
$CONTACTADDRESSn$ | Address of the contact being notified. Each contact can have six different addresses (in addition to email address and pager number). The macros for these addresses are $CONTACTADDRESS1$ - $CONTACTADDRESS6$. This value is taken from the addressx directive in the contact definition.
Date Macros:
$LONGDATETIME$ | Current date/time stamp (i.e. Fri Oct 13 00:30:28 CDT 2000). Format of date is determined by date_format directive.
$SHORTDATETIME$ | Current date/time stamp (i.e. 10-13-2000 00:30:28). Format of date is determined by date_format directive.
$DATE$ | Date stamp (i.e. 10-13-2000). Format of date is determined by date_format directive.
$TIME$ | Current time stamp (i.e. 00:30:28).
$TIMET$ | Current time stamp in time_t format (seconds since the UNIX epoch).
File Macros:
$MAINCONFIGFILE$ | The location of the main config file.
$STATUSDATAFILE$ | The location of the status data file.
$COMMENTDATAFILE$ | The location of the comment data file.
$DOWNTIMEDATAFILE$ | The location of the downtime data file.
$RETENTIONDATAFILE$ | The location of the retention data file.
$OBJECTCACHEFILE$ | The location of the object cache file.
$TEMPFILE$ | The location of the temp file.
$LOGFILE$ | The location of the log file.
$RESOURCEFILE$ | The location of the resource file.
$COMMANDFILE$ | The location of the command file.
$HOSTPERFDATAFILE$ | The location of the host performance data file (if defined).
$SERVICEPERFDATAFILE$ | The location of the service performance data file (if defined).
Misc Macros:
$PROCESSSTARTTIME$ | Time stamp in time_t format (seconds since the UNIX epoch) indicating when the Nagios process was last (re)started. You can determine the number of seconds that Nagios has been running (since it was last restarted) by subtracting $PROCESSSTARTTIME$ from $TIMET$.
$ADMINEMAIL$ | Global administrative email address. This value is taken from the admin_email directive.
$ADMINPAGER$ | Global administrative pager number/address. This value is taken from the admin_pager directive.
$ARGn$ | The nth argument passed to the command (notification, event handler, service check, etc.). Nagios supports up to 32 argument macros ($ARG1$ through $ARG32$).
$USERn$ | The nth user-definable macro. User macros can be defined in one or more resource files. Nagios supports up to 32 user macros ($USER1$ through $USER32$).

Notes

1 These macros are not valid for the host they are associated with when that host is being checked (i.e. they make no sense, as they haven't been determined yet).

2 These macros are not valid for the service they are associated with when that service is being checked (i.e. they make no sense, as they haven't been determined yet).

3 When host macros are used in service-related commands (i.e. service notifications, event handlers, etc) they refer to they host that they service is associated with.

4 When host and service summary macros are used in notification commands, the totals are filtered to reflect only those hosts and services for which the contact is authorized (i.e. hosts and services they are configured to receive notifications for).