Build precise queries to find exactly what you need
Press ESC to close
@rracosta
Member Since: April 2, 2012
Favorites0
Views
Projects0
Hi, I have used this script for a while and is working fine for a number of cisco models, but I noticed that in devices with a lot of interfaces snmpwalk the full interface table is taking a bit too long and if there is packet loss, Nagios will log a solf alarm; Therefore I have added a small modification in which it is possible to pass ifIndex as an argument with a huge increase in speed, the script also suggest what index to use. #!/usr/bin/perl -w # $Header$ # # ============================================================================ # # # # # # 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, 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; if not, write to the Free Software # # Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. # # # # ============================================================================ # # # # Description: =head1 DESCRIPTION Used to check integrity of port channels on cisco switches; tested on 4500 =cut =head2 VERSION Version 1.0 Stable =cut =head3 USAGE ./check_snmp_cisco_port_channel.pl -h -c -p =cut # ## ============================================================================ # ###################Setting up some parameters######################### use strict; use Getopt::Long; my $OK = 0; my $WARNING = 1; my $CRITICAL = 2; my $UNKNOWN = 3; my $host = "127.0.0.1"; my $community = "public"; my $poChannel="Po1"; my $maxSpeed=1000; my $snmpPoChannel="9999"; my $kProvided = 1; my $snmpIfName = '1.3.6.1.2.1.31.1.1.1.1'; ###################Getting options############################## GetOptions( "host|h=s" => $host, "community|c=s" => $community, "poChannel|p=s" => $poChannel, "maxSpeed|s=i" => $maxSpeed, "ifIndex|k=i" => $snmpPoChannel ); ################################################################# #if ifIndex is not provide, it snmpwalk the interfaces to find it, otherwise snmpget ifName if($snmpPoChannel == "9999"){ $kProvided=0; my @ifIDs = snmpwalk($host, $community, ".1.3.6.1.2.1.31.1.1.1.1","-Oqs"); foreach (@ifIDs) { if ($_ =~ /ifName.(.*)$poChannel$/) { $snmpPoChannel= $1; } } if($snmpPoChannel eq "9999"){ print "Sorry, I don't know that port channel. Check your syntax.n"; usage(); exit $UNKNOWN; } }else{ $poChannel=snmpget($host, $community, "$snmpIfName.$snmpPoChannel","-Oqvn"); } #Get status for port channel my $poSpeed=snmpget($host, $community, ".1.3.6.1.2.1.31.1.1.1.15.$snmpPoChannel","-Oqvn"); my $poStatus=snmpget($host, $community, ".1.3.6.1.2.1.2.2.1.8.$snmpPoChannel"); #change port description in case that index id provied checkPortChannel(); ###################Sub Routines################################## sub checkPortChannel { if($poStatus =~ /down/){ print "$poChannel: Downn"; exit $CRITICAL; }elsif(($poSpeed eq $maxSpeed) && ($kProvided == 0)){ print "OK - $poChannel: All members are up, To improve performance add -k , witch is $snmpPoChannel for $poChanneln"; exit $OK; }elsif(($poSpeed eq $maxSpeed) && ($kProvided == 1)){ print "OK - $poChannel: All members are upn"; exit $OK; }elsif($poSpeed lt $maxSpeed){ print "WARNING - $poChannel: One of the members of this channel is downn"; exit $WARNING; }else{ print "UNKNOWN - $poChannel: Can't find specified port channeln"; exit $UNKNOWN; } } sub usage { print "nSyntax:n"; print "./check_snmp_cisco_portChannel.pl -h -c [-p ] -s [-k ] nn"; print "Usage Example:n"; print "./check_snmp_cisco_portChannel.pl -h 192.168.0.1 -c public -p Po1 -s 2000nn"; } sub snmpwalk { my ($host, $community, $tree, $opts)=@_; my @walk = `snmpwalk -v 2c -c $community $opts $host $tree`; return @walk; } sub snmpget { my ($host, $community, $tree, $opts)=@_; if (! $opts ) { $opts ="" } my $get = `snmpget -v 2c -c $community $opts $host $tree`; chomp($get); return $get; } #=============================================================== =tail1 AUTHORS by Jared DeWitt =cut =tail2 Thanks Thanks to R3dl!GhT for writing snmpwalk and snmpget subs =cut =tail3 COPYWRIGHT Copywrite (C) Jared DeWitt 2008. This module is free software; you can redistribute it and/or modify it under the terms of the GNU Public License. =cut #===============================================================
Reviewed 14 years ago