#!/usr/bin/perl -w use SNMP_util; #============================================================================= # # gen6500targets.pl # # really crappy script to generate mrtg targets for all sorts of things # on the cisco 6500 platform # # Copyright 2006 The University of Wisconsin Board of Regents # Licensed and distributed under the terms of the Perl Artistic # License, see http://net.doit.wisc.edu/~dwcarder/scripts/ for # details. # # Written by: Dale W. Carder, dwcarder@doit.wisc.edu # Network Services Group # Division of Information Technology # University of Wisconsin at Madison # # For more about this and other tools, see # http://net.doit.wisc.edu/~dwcarder/scripts/ # #============================================================================= my $head=< '.1.3.6.1.2.1.4.3.0', 'ipInHdrErrors' => '.1.3.6.1.2.1.4.4.0', 'ipInAddrErrors' => '.1.3.6.1.2.1.4.5.0', 'ipForwDatagrams' => '.1.3.6.1.2.1.4.6.0', 'ipInUnknownProtos' => '.1.3.6.1.2.1.4.7.0', 'ipInDelivers' => '.1.3.6.1.2.1.4.9.0', 'ipOutRequests' => '.1.3.6.1.2.1.4.10.0', 'ipOutDiscards' => '.1.3.6.1.2.1.4.11.0', 'ipOutNoRoutes' => '.1.3.6.1.2.1.4.12.0', 'ipReasmReqds' => '.1.3.6.1.2.1.4.14.0', 'ipReasmOKs' => '.1.3.6.1.2.1.4.15.0', 'ipFragOKs' => '.1.3.6.1.2.1.4.17.0', 'ipFragFails' => '.1.3.6.1.2.1.4.18.0', 'ipFragCreates' => '.1.3.6.1.2.1.4.19.0', 'icmpInEchos' => '.1.3.6.1.2.1.5.8.0', 'icmpOutDestUnreachs' => '.1.3.6.1.2.1.5.16.0', 'icmpOutTimeExcds' => '.1.3.6.1.2.1.5.17.0', 'icmpOutEchoReps' => '.1.3.6.1.2.1.5.22.0', 'snmpInPkts' => '.1.3.6.1.2.1.11.1.0', 'snmpOutPkts' => '.1.3.6.1.2.1.11.2.0', 'snmpInTotalReqVars' => '.1.3.6.1.2.1.11.13.0', 'snmpInGetRequests' => '.1.3.6.1.2.1.11.15.0', 'snmpInGetNexts' => '.1.3.6.1.2.1.11.16.0', 'snmpOutTraps' => '.1.3.6.1.2.1.11.29.0' ); my $cempMemPoolName = '.1.3.6.1.4.1.9.9.221.1.1.1.1.2'; my $cempMemPoolUsed = '.1.3.6.1.4.1.9.9.221.1.1.1.1.7'; my $cempMemPoolFree = '.1.3.6.1.4.1.9.9.221.1.1.1.1.8'; my $cempMemPoolLargestFree = '.1.3.6.1.4.1.9.9.221.1.1.1.1.9'; my $cempMemPoolLowestFree = '.1.3.6.1.4.1.9.9.221.1.1.1.1.10'; my $cpmCPUTotalPhysicalIndex = '.1.3.6.1.4.1.9.9.109.1.1.1.1.2'; my $cpmCPUTotal1min = '.1.3.6.1.4.1.9.9.109.1.1.1.1.4'; my $cpmCPUTotal5sec = '.1.3.6.1.4.1.9.9.109.1.1.1.1.3'; my $entitymib = '.1.3.6.1.2.1.47.1.1.1.1.7'; my $ifIndex = ".1.3.6.1.2.1.2.2.1.1"; my $ifName = ".1.3.6.1.2.1.31.1.1.1.1"; my $ifAlias = ".1.3.6.1.2.1.31.1.1.1.18"; my $cieIfInputQueueDrops = ".1.3.6.1.4.1.9.9.276.1.1.1.1.10"; my $igmpInterfaceJoins = ".1.3.6.1.3.59.1.1.1.1.11"; # count how many joins an interface has gotten my $igmpInterfaceGroups = ".1.3.6.1.3.59.1.1.1.1.13"; # count how many groups have been subscribed to an interface my $ipMRouteInterfaceInMcastOctets = ".1.3.6.1.3.60.1.1.4.1.5"; my $ipMRouteInterfaceOutMcastOctets = ".1.3.6.1.3.60.1.1.4.1.6"; foreach my $device (@devices) { # walk ifindex my %ifindex =(); my @ret1 = &snmpwalk("$community\@$device", $ifIndex); foreach my $desc (@ret1) { my $oid; ($oid, $desc) = split(':', $desc, 2); $ifindex{$oid} = $desc; #print "$oid = $desc\n"; } # walk ifname my %ifname =(); my @ret2 = &snmpwalk("$community\@$device", $ifName); foreach my $desc (@ret2) { my $oid; ($oid, $desc) = split(':', $desc, 2); $desc =~ s/\//_/g; $ifname{$oid} = $desc; #print "$oid = $desc\n"; } # walk ifAlias my %ifalias =(); my @ret4 = &snmpwalk("$community\@$device", $ifAlias); foreach my $desc (@ret4) { my $oid; ($oid, $desc) = split(':', $desc, 2); $desc =~ s/\//_/g; $ifalias{$oid} = $desc; #print "$oid = $desc\n"; } # generate stuff for real interfaces my @ret5 = &snmpwalk("$community\@$device", $cieIfInputQueueDrops); foreach my $desc (@ret5) { my $oid; ($oid, $desc) = split(':', $desc, 2); my $intname = $ifname{$ifindex{$oid}}; my $targ = lc($device.'_'.$intname); printtarget($device,$targ,"Input Queue Drops for $intname (" . $ifalias{$ifindex{$oid}} .")",'inqdrop',$cieIfInputQueueDrops.".$oid"); } # walk $ipMRouteInterfaceInMcastOctets because not all instances will have a value my @ret3 = &snmpwalk("$community\@$device", $ipMRouteInterfaceInMcastOctets); foreach my $desc (@ret3) { my $oid; ($oid, $desc) = split(':', $desc, 2); my $intname = $ifname{$ifindex{$oid}}; #print "$oid $intname= $desc\n"; my $targ = $device.'_'.$intname; printtarget($device,$targ,"Multicast Byte Rate for $intname (" . $ifalias{$ifindex{$oid}} .')','mcastbytes',$ipMRouteInterfaceInMcastOctets.".$oid",$ipMRouteInterfaceOutMcastOctets.".$oid"); printtarget($device,$targ,"IGMP join Rate for $intname (" . $ifalias{$ifindex{$oid}} .')','igmpjoins',$igmpInterfaceJoins.".$oid"); printtarget($device,$targ,"IGMP groups on $intname (" . $ifalias{$ifindex{$oid}} .')','igmpgroups',$igmpInterfaceGroups.".$oid",'','gauge'); } foreach my $var (keys %basicoids) { printtarget($device,$device,$var,$var,$basicoids{$var}); } # walk the entity mib and store the description for each instance # into a hash my %entity =(); my @ret = &snmpwalk("$community\@$device", $entitymib); foreach my $desc (@ret) { my $oid; ($oid, $desc) = split(':', $desc, 2); $entity{$oid} = $desc; #print "$oid = $desc\n"; } # walk cempMemPoolName and grab the last 2 instances (like 4001.1) and the # type which is an integer (2) is Processor memory (3) is I/O Memory @ret = &snmpwalk("$community\@$device",$cempMemPoolName ); foreach my $desc (@ret) { my $oid; ($oid, $desc) = split(':', $desc, 2); my ($ent, $inst, $shortdesc, $shortnm); ($ent, $inst) = split('\.', $oid, 2); if ($desc eq 2) { $desc = 'Processor Memory'; $shortdesc = 'prmem'; } elsif ($desc eq 3) { $desc = 'IO Memory'; $shortdesc = 'iomem'; } if ($entity{$ent} =~ m/Switching Processor (\d+)/) { $shortnm = "SP$1"; } elsif ($entity{$ent} =~ m/Routing Processor (\d+)/) { $shortnm = "RP$1"; } elsif ($entity{$ent} =~ m/(\d+) CFC/) { $shortnm = "CFC$1"; } elsif ($entity{$ent} =~ m/(\d+) DFC/) { $shortnm = "DFC$1"; } # we could do atm cards and other junk, but there is a bug that # prevents mapping these back into entity-mib else { next; } my $longdesc = $entity{$ent} .', '. $desc; my $target = $device .'_'. $shortnm .'_'. $shortdesc; printtarget($device,$target,$longdesc,"cempMemPoolUsed","$cempMemPoolUsed.$oid",'','gauge'); printtarget($device,$target,$longdesc,"cempMemPoolFree","$cempMemPoolFree.$oid",'','gauge'); printtarget($device,$target,$longdesc,"cempMemPoolLargestFree","$cempMemPoolLargestFree.$oid",'','gauge'); printtarget($device,$target,$longdesc,"cempMemPoolLowestFree","$cempMemPoolLowestFree.$oid",'','gauge'); } # walk cpmCPUTotalPhysicalIndex to map these instances to entity values @ret = &snmpwalk("$community\@$device",$cpmCPUTotalPhysicalIndex); foreach my $desc (@ret) { my $oid; ($oid, $desc) = split(':', $desc, 2); #print "$oid " . $entity{$desc} ." \n"; my $shortnm; if ($entity{$desc} =~ m/Switching Processor (\d+)/) { $shortnm = "SP$1"; } elsif ($entity{$desc} =~ m/Routing Processor (\d+)/) { $shortnm = "RP$1"; } elsif ($entity{$desc} =~ m/(\d+) CFC/) { next; } elsif ($entity{$desc} =~ m/(\d+) DFC/) { $shortnm = "DFC$1"; } elsif ($entity{$desc} =~ m/CPU (\d+) of (\d+)/) { $shortnm = "CPU$1mod$2"; $entity{$desc} = "CPU $1 of module $2";} else { $shortnm = $entity{$desc}; } my $target = $device .'_'. $shortnm; my $longdesc = $entity{$desc}; printtarget($device,$target,$longdesc,"cpmCPUTotal1min","$cpmCPUTotal1min.$oid",'','gauge','fast'); } } sub printtarget { my $device = shift; my $target = shift; my $desc = shift; my $varname = shift; my $inoid = shift; my $outoid = shift; my $options = shift; my $interval = shift; $target = $target .'_'. $varname; if ( (!defined($outoid))||($outoid eq '') ) { $outoid = $inoid; } my $where = $community .'@'. $device; #print "$device $target $desc $inoid \n"; $paragraph=<$descTarget Name:$target EOM print $paragraph; if ($options) { print "Options[$target]: $options\n"; } print "\n"; };