Merging Multiple Nagios Check Outputs Using Macros

Macros in Nagios are a powerful tool. There are countless (see link) macros in existence that allow users to obtain Nagios check data easily. Among such macros, there exists $SERVICEOUTPUT$ that replaces itself with a string of the output of a chosen service. To specify such a service you can use the following syntax:


These type of macros are known as on-demand macros. In our particular case we want to merge 2 checks together by grabbing each check’s output, parsing a chosen value, and summing those values together. This summed value will be displayed with a 3rd check. For example, to get the output of the ‘Load’ service check you would use this macro:


To set up this custom check you can do the follow:

1. Download the python script and place it in a preferred location (/usr/local/nagios/libexec.dirnamehere). You can download the source script on Github.

2. Go to the script directory.

3. Allow the script to be executable.

sudo chmod 755

4. Set up a command on your XI server that runs the script. Make sure to wrap all your argument macros in double quotes.

/usr/local/nagios/libexec.(dirnamehere)/ -o1 "$ARG1$" -o2 "$ARG2$" -r1 "$ARG3$" -r2 "$ARG4$" -op "$ARG5$" -mm "$ARG6$"

Save and apply the command

5. Set up the service check, be sure to substitute the macro for $ARG1$ and $ARG2$.

6. For $ARG3$ and $ARG4$ a regex is needed to capture the value. Make sure the value is wrapped in a capture group. If the output from $ARG1$ or $ARG2$ only contains a numerical value use this regex: (.*).

7. $ARG5$ is the operation that will be performed on the captured value. Only add (a) is supported currently.

8. $ARG6$ is the output message. The output will replace ‘{0}’.

9. Save and apply.

10. Test your service check.