check_ssg_nsrp nagios script
Posted: Tue Apr 10, 2012 1:31 pm
Hi All,
Not sure if this is the right forum to post, but I am having issues developing a new nagios script to check our Juniper SSG's NSRP status, which is basically their HA feature for an active/active or active/backup scenario. Currently, the script runs fine manually...but when used with Nagios hosts/services, I get a null response in the nagios console. I'm assuming that I don't have the exit codes setup correctly in the script. Can anyone help me troubleshoot?
Running the script manually I get:
Script itself:
Not sure if this is the right forum to post, but I am having issues developing a new nagios script to check our Juniper SSG's NSRP status, which is basically their HA feature for an active/active or active/backup scenario. Currently, the script runs fine manually...but when used with Nagios hosts/services, I get a null response in the nagios console. I'm assuming that I don't have the exit codes setup correctly in the script. Can anyone help me troubleshoot?
Running the script manually I get:
Code: Select all
root::biznoc {/usr/local/nagios/libexec}-> ./check_ssg_cluster -H FLOATINGIP
OK: Current master is 2284160
(Primary SSG).Script itself:
Code: Select all
#!/usr/bin/perl
my $PROGNAME = "check_ssg_cluster.pl";
my $VERSION = '$Revision: 1.0 $';
use strict;
use vars qw($PROGNAME $VERSION %state_names $state);
use Getopt::Long qw(:config no_ignore_case);
use utils qw($TIMEOUT %ERRORS &print_revision &support);
sub help
{
print "Usage: $PROGNAME <options>\n\n";
print "options:\n";
print "\t-H <host> - hostname(you have to define a ScreenOS Device)\n";
print "\t-C <community> - community(default: private)\n";
print "\t-v <snmp-version> - snmp version(default: 1)\n";
print "\t-w <warning> - warning-level(default: Secondary SSG)\n";
print "\t-m <MiB-file> - path to the mib-file(default: /usr/share/snmp/mibs/JUNIPER-NSRP-MIB.txt)\n";
print "\t-h - prints this help-screen\n";
}
# Nagios exit states
our %states = (
OK => 0,
WARNING => 1,
CRITICAL => 2,
UNKNOWN => 3
);
# Nagios state names
%state_names = (
0 => 'OK',
1 => 'WARNING',
2 => 'CRITICAL',
3 => 'UNKNOWN'
);
$state = 'UNKNOWN';
my ($COMMUNITY, $SNMPWALK, $SNMPVERSION, $MIBFILE, $CRITICAL, $IP, $HELP);
GetOptions
(
"h" => \$HELP, "help" => \$HELP,
"C=s" => \$COMMUNITY, "community=s" => \$COMMUNITY,
"v=i" => \$SNMPVERSION, "snmpversion=i" => \$SNMPVERSION,
"c=s" => \$CRITICAL, "crit=i" => \$CRITICAL,
"H=s" => \$IP, "host=s" => \$IP,
"m=s" => \$MIBFILE, "mib=s" => \$MIBFILE
) or exit $states{$state};
if( defined $HELP)
{
help();
exit $states{$state};
}
unless(defined $IP)
{
print "no host defined!\n";
exit $states{$state};
}
$COMMUNITY = "public" if not defined $COMMUNITY;
$SNMPWALK = "/usr/bin/snmpwalk" if not defined $SNMPWALK;
$SNMPVERSION = 1 if not defined $SNMPVERSION;
$MIBFILE = "/usr/share/snmp/mibs/JUNIPER-NSRP-MIB.txt" if not defined $MIBFILE;
my $PRIMARY_SSG = 2284160;
my $SECONDARY_SSG = 2285824;
my $WARNING = 2285824;
unless(-e $SNMPWALK)
{
print "snmpwalk is not installed!\n";
exit $states{$state};
}
unless(-e $MIBFILE)
{
print "mib-file does not exist!\n";
exit $states{$state};
}
my $master_cluster = `$SNMPWALK -c $COMMUNITY -v $SNMPVERSION -m $MIBFILE $IP netscreenNsrpGeneral.nsrpGeneralLocalUnitId.0 | awk '{print \$4}'`;
if($WARNING == $master_cluster)
{
print "WARNING: Current Master is $master_cluster (Secondary SSG); failover has occurred…\n";
$state = 'WARNING';
exit $states{$state};
}
elsif($PRIMARY_SSG == $master_cluster)
{
print "OK: Current master is $master_cluster (Primary SSG).\n";
$state = 'OK';
exit $states{$state};
}
else
{
print "UNKNOWN: The current HA status is unknown.\n";
$state = 'UNKNOWN';
exit $states{$state};
}