Defining macros in a resource file

In this recipe, we'll learn how to define custom user macros in resource files. This is good practice for strings used in check_command definitions or other directives that are shared by more than one host or service. For example, in lieu of writing the full path in a command_name directive as follows:

command_name=/usr/local/nagios/libexec/check_ssh $HOSTADDRESS$

We could instead write:

command_name=$USER1$/check_ssh $HOSTADDRESS$

As a result, if the location of the check_ssh script changes, we only need to change the value of $USER1$ in the appropriate resource file to update all of its uses throughout the configuration.

Most of the macros in Nagios Core are defined automatically by the monitoring server, but up ...

Get Nagios Core Administration Cookbook 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.