Addon - Nagios Passive Checks with NSCA

Using Nagios with NSCA, you can configure some complex scripts / tasks to output status codes and messages to be sent to your Nagios server for collection / reporting.  To start, you will need to install NSCA package on your Nagios server and configure the listening server as outlined in the documenation.

NOTE: You will need libmcrypt and libmcrypt-devel packages installed to compile successfully.

You will most likely want to create a template or two to use with your passive checks.  Below is the example template I created for testing passive checks...

define service{
        name                    passive-service
        use                     generic-service
        check_freshness         1
        passive_checks_enabled  1
        active_checks_enabled   0
        is_volatile             0
        flap_detection_enabled  0
        notification_options    w,u,c,s
        freshness_threshold     57600     ;12hr
}

Then configure a service like so...

define service{
     use                     passive-service   
     host_name               localhost
     service_description     test
     check_command           check_dummy!3!"No Data Received"
}

On the remote server, you will need to do the same to compile the components.  You will only need the send_nsca binary and the send_nsca.cfg file.  You will need to tweak your send_nsca config file to match the information you configured on your NSCA server.

Now the fun begins where you can create/modify scripts to send these passive check results to Nagios via the NSCA server.  I used a simple perl script below for my testing.

#!/usr/bin/perl
#############################################################
# RETURN CODES:
# 0-OK, 1-WARNING, 2-CRITICAL, 3-UNKNOWN
#############################################################
#CONFIG FILES
#$debug=1;
$config="/usr/local/nagios/etc/send_nsca.cfg";
# LOCAL SYSTEM CONFIG OPTIONS
$nsca_host="nagios.hubteam.com";
$host="host_name";
$service="service_name";
# DEFAULT RETURNS
$code=3;
$result="WHAT THE HECK?";
# COMMAND LINE
$send_nsca="/usr/local/nagios/bin/send_nsca -c $config -H $nsca_host";
# Start
# INSERT YOUR FUN CODE HERE, Setting a $code and $result value
# End
if ($debug) {print "SENDING:  $host\t$service\t$code\t$result\n";}
open(SEND,"|$send_nsca") || die "Could not run $send_nsca: $!\n";
print SEND "$host\t$service\t$code\t$result\n";
close SEND;

There are several points to consider.

  • If the script takes  < 10 seconds, you may also consider running checks via NRPE and custom command defintions. 
  • You can have multiple checks report passive checks back to the SAME host/service combo.  Eg, running various nightly jobs and direct any errors go to a single "nightly-jobs" monitor.
  • Read the Nagios documenation on passive checks and freshness.