#!/usr/bin/perl -w # -*- perl -*- # Cricket: a configuration, polling and data display wrapper for RRD files # # Copyright (C) 1998 Jeff R. Allen and WebTV Networks, Inc. # # 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. # Modifications to original listInterfaces script as distributed in # Cricket 0.72 (by Jeff R. Allen): # Jon Snyder , April 2000 # -use ifXTable.ifXEntry.ifName instead of ifDescr to get & map port name # -*NOTE* that this will fail miserably if your device doesn't support # the ifXEntry.ifName in its MIB. # -detect cisco Catalyst 550x switches and use the VLAN info # -make multi-targets for aggregate VLAN traffic (mtargets) and one page # to graph every port on the switch ("all" target) # -use port-name tag to set the name of the switch port, and map() on it BEGIN { $gInstallRoot = (($0 =~ m:^(.*/):)[0] || "./") . ".."; } use lib "$gInstallRoot/lib"; use strict; use snmpUtils; use Common::Log; if ($#ARGV+1 < 1 || $#ARGV+1 > 2) { print STDERR "usage: $0 hostname [community]\n"; print STDERR "\tcommunity will default to public if you don't give it.\n"; exit 1; } my($router) = $ARGV[0]; my($community) = "public"; $community = $ARGV[1] unless (! defined($ARGV[1])); my($snmp) = "$community\@$router"; print "target --default--\n"; print "\tswitch = $router\n"; print "\ttarget-type = switch-port\n"; print "\n"; my($ifDescr) = '.1.3.6.1.2.1.2.2.1.2'; my($ifName) = '.1.3.6.1.2.1.31.1.1.1.1'; my($row, @tgts, $sysDescr); ($sysDescr) = snmpUtils::get($snmp, "1.3.6.1.2.1.1.1.0"); if (!defined($sysDescr)) { die "Unable to retrieve sysDescr. Something appears to be wrong...\n"; } my (%iftomp, %iftovlan, %vlantomtargets, $cat5000); $cat5000 = 0; if ( $sysDescr =~ /WS-C55\d\d/ ) { $cat5000 = 1; my $portGroup = "1.3.6.1.4.1.9.5.1.4.1.1.11"; foreach $row (snmpUtils::walk($snmp, $portGroup)) { my($oid, $value) = split(/:/, $row, 2); $oid =~ s/$portGroup//; $iftomp{$value} = $oid; } my $vlanPortVlan = "1.3.6.1.4.1.9.5.1.9.3.1.3"; foreach $row (snmpUtils::walk($snmp, $vlanPortVlan)) { my($oid, $value) = split(/:/, $row, 2); $oid =~ s/$vlanPortVlan//; my ($key, $ifindex); $ifindex = 0; foreach $key (keys %iftomp) { if ($iftomp{$key} eq $oid) { $ifindex = $key; } } if ($ifindex) { $iftovlan{$ifindex} = $value; } } } foreach $row (snmpUtils::walk($snmp, $ifName)) { my($oid, $value) = split(/:/, $row, 2); $oid =~ s/$ifName//; # print STDERR "oid: $oid\n"; # my($stat) = snmpUtils::get($snmp, "1.3.6.1.2.1.2.2.1.7.$oid"); # my($connector) = snmpUtils::get($snmp, "1.3.6.1.2.1.31.1.1.1.17.$oid"); # my($desc) = snmpUtils::get($snmp, "1.3.6.1.2.1.31.1.1.1.18.$oid"); my($iftype) = snmpUtils::get($snmp, "1.3.6.1.2.1.2.2.1.3.$oid"); #odds are we want to get inOctets for our targets. If they don't #return them, we skip them as a potential target. my($inOctets) = snmpUtils::get($snmp, "1.3.6.1.2.1.2.2.1.10.$oid"); if (defined($inOctets)) { my $short_desc = $value; if ($cat5000) { my ($intname, $vlan_no) = split('-', $value, 2); #up to you if you want to see these or not # if ( ($intname eq "sc0") || ($intname eq "sl0") ) { next; } if ($intname eq "VLAN") { #VLANs >= 1000 are used for translational bridging if ($vlan_no >= 1000) { next; } } my $target = lc $value; #variously used ethernet ifTypes if ( ($iftype == 6) || ($iftype == 7) || ($iftype == 11) || ($iftype == 62) || ($iftype == 69) || ($iftype == 117) ) { $target = lc $value; $target =~ s/[\/\s:]/\_/g; print "target $target\n"; my $portnum = $iftomp{$oid}; if (defined $portnum) { #we have module.port notation from SNMP. Change it to module/port $portnum =~ s/\./\//g; $short_desc .= ", VLAN $iftovlan{$oid}"; $vlantomtargets{$iftovlan{$oid}} .= "$target;"; } push @tgts, $target; output("port-name", $value); output("short-desc", $short_desc); } else { next; } } else { my($target) = lc $value; $target =~ s/[\/\s:]/\_/g; print "target $target\n"; push @tgts, $target; output("port-name", $value); output("short-desc", $short_desc); } # experience shows that subinterfaces (like those # representing the endpoints of PVCs riding on a # frame relay link) need a special config. # if (defined($connector) && $connector == 2) { # output("target-type", "sub-interface"); # } print "\n"; } else { print STDERR "OID $oid (ifname $value) excluded.\n"; } } my($tmp); foreach $tmp (keys %vlantomtargets) { print "target vlan-$tmp\n"; output("short-desc", "VLAN-$tmp, VLAN Interface (Aggregate traffic)"); output("mtargets", "\"$vlantomtargets{$tmp}\""); output("mtargets-ops", "\"sum()\""); output("order ", "5"); print "\n"; } print "target All\n"; output("short-desc", "All targets"); print "\ttargets \t=\t\""; foreach $tmp (sort {$a <=> $b} keys %vlantomtargets) { print "vlan-$tmp;"; } foreach $tmp (@tgts) { print "$tmp;"; } print "\"\n"; output("order ", "10"); sub output { my($name, $value) = @_; my($quote) = ''; if (defined($value)) { # quote empty (or white-space only) lines, or lines which # will have embedded spaces. $quote = '"' if ($value =~ /^\s*$/ || $value =~ /\s/); print "\t$name = $quote$value$quote\n"; } }