Nagios: Setting up the NSCA addon for passive checks

The ability to set up passive checks within the enterprise is very important. You may have remote hosts with low network bandwidth, but high processing ability. You may also find your Nagios host is becoming over whelmed with the number of checks and services to be performed. Nagios’ passive checks will enable you to manage your enterprise’s hardware and software strengths and weaknesses.

How to set up NSCA has already been written and published. The document can be found at: NSCA Setup PDF. The steps taken were on-the-money with setting up the NSCA daemon and should be followed to avoid any headaches with the initial setup.

Setting up the Nagios host for passive service checks is very straight forward. There are many sources for the command configuration file on the Internet. The file needs to be deployed and loaded on the Nagios Host. Until you get the base “TestMessage” to work on the Nagios host, I would not recommend you break down the command file.

Make sure you have the NSCA addon is installed on the client. The test message is very simple to compose and consists of: HOSTNAME<tab>SERVICENAME<tab>STATE<tab>MESSAGE<return>. Make sure you follow this format, because it is the structure the nagios.cmd is looking for on the Nagios host.

My enterprise has stores that need to be monitored; however, I did not want to consume bandwidth that is needed by the stores. My solution was to create a Perl script that runs the Nagios command “check_disk” and sends the results back to the Nagios host. The Perl script can be set up in the crontab to run at specific times, so you can actually stagger the service checks.

I am a System Administrator and not a Perl guru, so this is not going to look pretty to many of you programmers in the community. I am charged with monitoring systems “yesterday,” so I put together scripts very fast. This code can be run within the crontab. The output is placed into a file and only sends notifications back to the Nagios Host when there is a change in the State. That way the Nagios Host is not being inundated with “good” checks.

Here is the code:

#!/usr/bin/perl -w
use strict;
use Switch;
my $host=`hostname -f`;
my $svc=”check_passive_disk”;
my $state=0;
my $tempfile=”df_check.tmp”;
my $check_disk_cmd=`/opt/nagios/libexec/check_disk -w 10% -c 5% -p /boot -p / -p /usr -p /var -p /var/spool -p /tmp -p /opt -l -e`;
my @check_disk_cmd;

open(OLDFILE, “<$tempfile”);
$old_file = <OLDFILE>;

open FH, “> $tempfile” or die $!;
my $clean = `sudo /bin/cp /dev/null $tempfile`;
@check_disk_cmd = split( / /, $check_disk_cmd);
$state = $check_disk_cmd[1];
switch ($state){
case “OK|” {$state = 0;}
case “WARNING” {$state = 1;}
case “CRITICAL” {$state = 2;}
else {$state = 3;}
print FH “$host\t$svc\t$state\t$check_disk_cmd\n” or die $!;
if ($old_file != 0 || $state == 1 || $state == 2 || $state == 3){
my $send_to_nagios=`/opt/nagios/bin/send_nsca nagios1 -c /opt/nagios/etc/send_nsca.cfg < $tempfile`;
exit (0);
else {
exit (0);
exit (0);

I am open to suggestions on how to modify the code to work better. Make sure your “$svc” value is whatever your service definition is on the Nagios Host. If they are not the same, Nagios will allow the connection and throw the results into the bit bucket.

For a PDF file with both the command file and client script go to: Mike’s Blog and download the PDF. I hope this brings many of you closer to being able deploy passive checks. Please share your Passive Service check experiences with the community.

Mike Kniaziewicz, MIS

Bookmark and Share

0 Response to “Nagios: Setting up the NSCA addon for passive checks”

Comments are currently closed.