Nagios Training: Passive Host Checks

by Mike on September 15, 2009 · 1 comment

in Nagios

Create a Passive Host Check Test
It is important that you get a test script working correctly before you get too excited about putting together a real script as you want to understand the process and work out any issues before you start writing scripts.

Lesson 4 | Lesson 6

Here is a simple script for sending information about the state of the server to the Nagios server.  Note the path is for a CentOS server so adjust yours as needed and you can see the host name is nagpass and the Nagios server IP is  All of these must be adjusted to your network.  The script is only intended to show you how to communicate to the server and view the information on the web interface.

# Passive Host Check Test Script
CMD=”nagpass;0;Host Status”
/bin/echo $CMD | /usr/sbin/send_nsca -H -d ‘;’ -c $CFG
exit 0

CFG is a variable that contains the path to the send_nsca.cfg file.  This file of course must contain the password and encryption type for communicating with  the Nagios server.  Remember, the password on the client must be the same password on the server so they can communicate.  See the Nagios server set up for passive checks if this is unclear.
The CMD variable is a pre-configured message that will be send via send_nsca.  The host message contains the hostname of the client (nagpass), the status “0” which indicates the server is up and a text message.

The CMD variable is piped in to the send_nsca command with the Nagios server indicated by the “-H”.  Change the IP or hostname for your Nagios server.  The delimiter is indicated by the “-d ‘;’” which shows that it is the semi-colon and finally the configuration file is sent using the CFG variable.
Create a directory on your client server for all of the scripts you will end up writing so they are in one place.  Save the script above as and chmod 755 to make it executable.  Then run the script, making sure your send_nsca.cfg file contains the same password and encryption type as on the Nagios server.

Here is the response you should see on the Nagios server in the /var/log/messages.  Note the indication that xinetd is listening for the nsca and that the second line indicates that it is a host check and the information from the client has been transferred.
xinetd[3685]: EXIT: nsca status=0 pid=22238 duration=0(sec)

Now testing the passive host check use the status of “0” the first time on the client and run the script you should see this on the web interface.


Then change the status to “1” and you should see an indication that the server is down on the web interface.


Here you can see that flapping is detected.  You can stop flap detection with this setting in the /etc/nagios/objects/hosts.cfg.

define host{
use                           linux-box
host_name                     nagpass
active_checks_enabled         1
passive_checks_enabled        1
flap_detection_enabled        0

As you change states of the host for testing you can see a summary by opening the host on the web interface and choosing the availability report.  Here is an example.


At this point you have completed the process of using a test script to change states for a host on the Nagios server using passive checks.

Check External Commands on Nagios Server
At the command line on the server verify that it will accept commands on the external interface.  If this does not work do not go any further until you solve it as if it does not work on the local Nagios server it sure will not work from the clients.

echo “['date +%s'] PROCESS_HOST_CHECK_RESULT;nagpass;2;test” > /var/nagios/rw/nagios.cmd

View /var/log/messages on Nagios Server
If you see something similar you can go to the next step and start working on the client.
Sep 10 16:19:58 fw3 nagios: EXTERNAL COMMAND: PROCESS_HOST_CHECK_RESULT;nagpass;2;test
Sep 10 16:20:03 fw3 nagios: PASSIVE HOST CHECK: nagpass;2;test

Previous post:

Next post: