Nagios – Configuring Global Event Commands Using

Nagios – Configuring Global Event Commands Using

Today I finally worked out how to configure the script as a Global Event Command after scouring the web for the solution.  As with most things Nagios related, the documentation out there is a little light so I thought I’d put this up in case it helps others.

I’ll be doing a full set of Wiki pages for setting up distributed monitoring with Nagios Core and NRDP when I get a chance but for now, here’s a quick and dirty post on how to configure the script as a Global Event Command.

Configure The Command Definitions

  • Edit /usr/local/nagios/etc/objects/commands.cfg
vi /usr/local/nagios/etc/objects/commands.cfg
  • Go to the end of the file and add in a new command as shown below, substituting the {Your Nagios server address here} with the IP Address of your Nagios Server with NRDP installed and configured and substituting {Your nrdp token here} with the token you created when setting up NRDP:
define command {
 command_name global_host_send_nrdp
 command_line /usr/bin/printf "%b" "$HOSTNAME$\t$HOSTSTATEID$\t$HOSTOUTPUT$" | $USER3$/ -u http://{Your Nagios server address here}/nrdp/ -t {Your nrdp token here}
  • Save and exit the file

Configure The Global Host Event Command

  • Edit /usr/local/nagios/etc/nagios.cfg
vi /usr/local/nagios/etc/nagios.cfg
  • Search for the line #global_host_event_handler=somecommand and change it to the following:
  • Save and exit the file
  • Restart the nagios service

Command Definition Explanation

I pieced together the command definition which sends the correct information to a host definition on my central Nagios Core 4.4.5 server which is configured for passive checks.  The send_nrpd Client knowledge base article from Nagios NRDP – send_nrdp Client gave me some of the information on how to construct the command but it fell in to place when I read the Using STDIN section.

Once I realised that you can use printf to pipe the information in to the command it was just a case of using the Nagios macros in the same way as the stock notify_host_by_email as well as referring to the Standard Macros in Nagios page.

The command_line used in this example uses the standard macros shown below with \t as the delimiter:


This then sends a check result to the central Nagios Core server providing the hostname e.g., the Hosts State ID ( 0=UP, 1=DOWN, 2=UNREACHABLE), and the output of the active check on the remote Nagios Core server e.g. PING OK – Packet loss = 0%, RTA = 0.04 ms

After that it was a case of setting up hosts with the same hostname on each Nagios Core server, setting the central Nagios Core server’s hosts to passive checks, and the remote Nagios Core server’s hosts to active checks !

Update 06-12-19

After adding my virtual environment servers to the mix for basic checks by the remote Nagios Core server I noticed that it wasn’t notifying when a server was UP.  This meant my central Nagios console showed lots of Unknowns rather the UP.

A quick check through the config revealed that I’d used the windows-server host definition template and that the notifications_options were only set for d,r so changing them to d,u,r and restarting Nagios fixed the issue.

Leave a Reply

Your email address will not be published. Required fields are marked *