#!/usr/bin/perl -w # # (c) 2007 Martin Dag Nilsson # AXIS Communications AB # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # you should have received a copy of the GNU General Public License # along with this program (or with Netsaint); if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA # ####################################################################### # check_pix_failover - script for checking failover status # on Cisco PIX/ASA clusters using SNMP # # Version: 0.1 # Changelog: # 2007-01-02: Initial version created use strict; use Net::SNMP; use Getopt::Long; use lib '/usr/lib/nagios/plugins'; use utils qw (%ERRORS $TIMEOUT); my $hostname; my $community; my $debug; my $timeout; my $retries; my $help; Getopt::Long::Configure('bundling'); GetOptions ( "help" => \$help, "hostname=s" => \$hostname, "community=s" => \$community, "debug" => \$debug, "timeout=i" => \$timeout, "retries=i" => \$retries, "h" => \$help, "H=s" => \$hostname, "C=s" => \$community, "d" => \$debug, "t=i" => \$timeout, "r=i" => \$retries ); unless (defined ($debug)) { $debug = 0; } unless (defined ($timeout)) { $timeout = $TIMEOUT; } unless (defined ($retries)) { $retries = 1; } # Status returned by the SNMP query my %pix_status = ( '4' => 'Error', '9' => 'Active', '10' => 'Standby', ); ########################################### # sub: help # Prints help information sub help () { print < '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.3.6', 'secondary' => '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.3.7', ); my ($primary, $secondary); my ($session, $error) = Net::SNMP->session ( -hostname => $hostname, -community => $community, -retries => $retries, -debug => $debug, -timeout => $timeout); unless ($session) { print "Session error: $error\n"; exit $ERRORS{UNKNOWN}; } my $result = $session->get_request ($snmp_string{primary}, $snmp_string{secondary}); foreach my $key (keys %snmp_string) { $status{$key} = $result->{$snmp_string{$key}}; } unless (defined ($status{primary}) && defined ($status{secondary})) { print "Error: Check timed out\n"; exit ($ERRORS{UNKNOWN}); } $session->close; return ($status{primary}, $status{secondary}); } # Check command line arguments &help () if ($help); &help () unless ($hostname && $community); # Get the status for the active and standby unit my ($primary, $secondary) = &status_request ($hostname, $community, $debug, $timeout, $retries); # Determine status of cluster if ($primary == 9 && $secondary == 10) { print "OK - Primary: $pix_status{$primary}, Secondary: $pix_status{$secondary}\n"; exit ($ERRORS{OK}); } elsif ($primary == 10 && $secondary == 9) { print "Warning - Primary: $pix_status{$primary}, Secondary: $pix_status{$secondary}\n"; exit ($ERRORS{WARNING}); } elsif ($primary == 4 && $secondary == 9) { print "Critical - Primary: $pix_status{$primary}, Secondary: $pix_status{$secondary}\n"; exit ($ERRORS{CRITICAL}); } elsif ($primary == 9 && $secondary == 4) { print "Critical - Primary: $pix_status{$primary}, Secondary: $pix_status{$secondary}\n"; exit ($ERRORS{CRITICAL}); } else { print "Unknown - Primary: $primary, Secondary: $secondary\n"; exit ($ERRORS{UNKNOWN}); }