check_foundry_port-status

#! /usr/bin/perl -w
use strict;
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_w $opt_c $opt_H $opt_C $opt_v $nr $rawstatus $status $warning $critical $PROGNAME);
use lib “/usr/lib/nagios/plugins/” ;
use utils qw(%ERRORS &print_revision &support &usage);

$PROGNAME = “check_foundry_port-status”;

sub print_help ();
sub print_usage ();

$ENV{‘PATH’}=”;
$ENV{‘BASH_ENV’}=”;
$ENV{‘ENV’}=”;

Getopt::Long::Configure(‘bundling’);
GetOptions
(“V” => \$opt_V, “version” => \$opt_V,
“h” => \$opt_h, “help” => \$opt_h,
“H=s” => \$opt_H, “hostname=s” => \$opt_H,
“v=s” => \$opt_v, “ifalias=s” => \$opt_v,
“C=s” => \$opt_C, “community=s” => \$opt_C);

if ($opt_V) {
print_revision($PROGNAME,’$Revision: 0.1 $’);
exit $ERRORS{‘OK’};
}
if ($opt_h) {print_help(); exit $ERRORS{‘OK’};}

($opt_H) || usage(“Host name/address not specified\n”);
my $host = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
($host) || usage(“Invalid host: $opt_H\n”);

($opt_v) || usage(“Volume name/address not specified\n”);
my $ifalias = $1 if ($opt_v =~ /([-.A-Za-z0-9_]+)/);
($ifalias) || usage(“Invalid host: $opt_v\n”);

#($opt_w) || usage(“Warning threshold not specified\n”);
#my $warning = $1 ;
#($warning) || usage(“Invalid warning threshold: $opt_w\n”);

#($opt_c) || usage(“Critical threshold not specified\n”);
#my $critical = $1 ;
#($critical) || usage(“Invalid critical threshold: $opt_c\n”);

$critical=”down”;

($opt_C) || ($opt_C = “public”) ;

my $nr=0;
$nr=`/usr/bin/snmpwalk -v 2c -c $opt_C $host IF-MIB::ifAlias | /bin/grep $ifalias| /bin/awk -F’ ‘ ‘{print \$1}’ | /bin/awk -F. ‘{print \$NF}’ `;
$rawstatus=`/usr/bin/snmpwalk -v 2c -c $opt_C $host IF-MIB::ifOperStatus.$nr`;
$status=`echo “$rawstatus” | /bin/awk -F’ ‘ ‘{print \$4}’ | /bin/awk -F'(‘ ‘{print \$1}’`;

if ($status =~ “up”){
print “OK – $ifalias status: $status \n”; exit $ERRORS{‘OK’};
} elsif ($status =~ “down”){
print “CRITICAL – $ifalias usage: $status \n”; exit $ERRORS{‘CRITICAL’};
}else{
print “CRITICAL – Something went wrong, please check your configuration \n”; exit $ERRORS{‘CRITICAL’};
}

#if ($status=$warning){ print “WARNING – $ifalias usage: $status \n”; exit $ERRORS{‘WARNING’} };

sub print_usage () {
print “Usage: $PROGNAME -H <host> [-C community] -w <warn> -c <crit>\n”;
}

sub print_help () {
print_revision($PROGNAME,’$Revision: 0.2 $’);
print “Copyright (c) 2009 Rob Hassing

This plugin reports the status of a Foundry Interface: IfAlias

“;
print_usage();
print ”
-H, –hostname=HOST
Name or IP address of host to check
-v, –IfAlias=IfAlias
Name of the port to check
-C, –community=community
SNMPv1 community (default public)
-w, –warning=INTEGER
Percentage above which a WARNING status will result
-c, –critical=INTEGER
Percentage above which a CRITICAL status will result

“;
# support();
}