Home Directory Plugins Hardware Network Gear Cisco check_snmp_cisco_port_channel.pl

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_snmp_cisco_port_channel.pl

Rating
2 votes
Favoured:
0
Hits
104193
Files:
FileDescription
check_snmp_cisco_port_channel.plcheck snmp cisco port channel
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
Checks integrity of Cisco 3750 switch port channels. This will check if the port channel is up. It will also inform you if one of the members of that port channel is down.
If the port channel is down it will return critical.
If the speed is 2gb, then it returns ok.
If the speed is 1gb, then it returns warning and informs you one of the port channel members is down.
If it can't find the port channel you specify, it will return unknown.

Usage:
./check_snmp_cisco_port_channel.pl -h (host) -c (community) [-p (portchannel)]

Example:
./check_snmp_cisco_port_channel.pl -h 192.168.0.1 -c public -p po1

Valid port channels:
po1
po2

This was tested on a stack of cisco 3750's. It will always return OK status if you check a single switch. This can be modified if you need it to check port channels on a single switch.
Reviews (1)
byrracosta, April 4, 2012
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: Down\n";
exit $CRITICAL;
}elsif(($poSpeed eq $maxSpeed) && ($kProvided == 0)){
print "OK - $poChannel: All members are up, To improve performance add -k , witch is $snmpPoChannel for $poChannel\n";
exit $OK;
}elsif(($poSpeed eq $maxSpeed) && ($kProvided == 1)){
print "OK - $poChannel: All members are up\n";
exit $OK;
}elsif($poSpeed lt $maxSpeed){
print "WARNING - $poChannel: One of the members of this channel is down\n";
exit $WARNING;
}else{
print "UNKNOWN - $poChannel: Can't find specified port channel\n";
exit $UNKNOWN;
}
}

sub usage
{
print "\nSyntax:\n";
print "./check_snmp_cisco_portChannel.pl -h -c [-p ] -s [-k ] \n\n";
print "Usage Example:\n";
print "./check_snmp_cisco_portChannel.pl -h 192.168.0.1 -c public -p Po1 -s 2000\n\n";
}

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
#===============================================================