#!/usr/local/bin/perl ############################################################################### # # walkL2SE - Get layer 2 switch engine stats from a Catalyst 5000/6000. # See genCatConfig docs for details. # # Takes the Cricket style snmp spec as the first arg. If the path # to the rrd file is given as the second arg, the current L2 # instance will be logged to the appropriate .meta file. If an # email address is given as the third arg, notification will be # sent when the instance changes. (indicating supervisor failover) # # Copyright (C) 2000 Mike Fisher and Tech Data Corporation # # 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; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # Created: 11/01/00 - Mike Fisher # ############################################################################### ### Change this to reflect your local mail program. It's expected to take a ### -s flag and a subject. If not, see the code. $MAIL = "mail"; ############################################################################### BEGIN { $gInstallRoot = (($0 =~ m:^(.*/):)[0] || "./") . ".."; } use lib "$gInstallRoot/lib"; use snmpUtils; $snmp = shift; $path = shift; $addr = shift; $oid = '1.3.6.1.4.1.9.9.97.1.1.1.1'; %r = map((split(/:/,$_)), snmpUtils::walk($snmp,$oid)); @k = sort {$a <=> $b} keys %r; foreach (@k) { print "$r{$_}\n"; } if ($path) { $path =~ s/.rrd$/.meta/; open(META, $path); $last = ; close(META); $last =~ s/^last-inst//; chomp($last); if ($last != $k[0]) { if ($addr) { $switch = $snmp; $switch =~ s/^[^\@]*\@//; $switch =~ s/:.*$//; open(MAIL, "|$MAIL -s '$switch sup change detected' $addr") || warn "$!"; print MAIL "\n"; close(MAIL); } open(META, ">$path"); print META "last-inst$k[0]\n"; close(META); } }