[mrtg] One last question
GUARENO at FORDHAM.EDU
GUARENO at FORDHAM.EDU
Fri Jun 28 23:48:55 MEST 2002
Hello again.... This is my last question, I promise.
I think I worked out the kinks out of the script (cat_internet2.pl) but now
I only get one error. The script runs fine through almost every single OID
specified in it. I get the error is (for every OID -5 times-):
SNMP walk problem for 1.3.6.1.4.1.529.x.x.x.x on X.X.X.X
Unknown SNMP variable "mycommunity" (where "mycommunity" is the snmp
comnunity I type at the command
perl cat_internet2.pl community at 150.x.x.x)
I now understand about binaries and using SNMP_util instead.
Am I missing something here. Many thanks in advance...
#!/perl/bin/perl
#
# Copyright (C) Gehri Grimaud Email: gehri at thingy.usu.edu
# Office of Computer Services
# Utah State University
# Logan, Utah 84322-4410
#
# May be freely distributed
#
# Script to do a "finger" on a Lucent Ascend MAX 6000.
#
# Written 30-July-1998
#
# USAGE: pmfinger community\@router
#
# The output of this script looks like:
# box1 #2 fred 192.168.2.111 Connect 0:1:06:53 Idle 0:0:00:07
26400/31200
# box2 #3 joe 192.168.2.87 Connect 0:2:13:47 Idle 0:0:00:07
31200/33600
#
# define the SNMP Object ID's we are looking for. The Object names for
# the "Enterprise.Ascend...." MIB variables are way too ugly for words,
# so we use ".1.3.6.1.4.1.529...." OIDs instead
use SNMP_util "0.92";
%OID = (
"sysName" => ".1.3.6.1.4.1.529.2.6.1.0",
"SerialUser" => ".1.3.6.1.4.1.529.12.3.1.4",
"SerialStarted" => ".1.3.6.1.4.1.529.12.3.1.5",
"SerialIdle" => ".1.3.6.1.4.1.529.11.16.1.5",
"InSpeed" => ".1.3.6.1.4.1.529.11.16.1.14",
"OutSpeed" => ".1.3.6.1.4.1.529.11.16.1.4",
);
# get the args
($community, $router) = split(/\@/, $ARGV[0]);
#print "$community,$router\n";
die <<USAGE unless $community && $router;
USAGE: pmfinger 'community'\@'router'
USAGE
# get the system name
#snmpwalk( sysName ) returns _stuff_.0 "pm1"
$sysName = ( &snmpwalk( $router, $community, $OID{"sysName"} ))[0];
print "sysName=$sysName\n";
$sysName =~ /"(.*?)"/;
$sysName = $1;
# get the usernames
# snmpwalk( SerialUser) returned values look like:
# _mib_stuff_.1 ""
# _mib_stuff_.2 "fred"
# _mib_stuff_.3 "miles"
# _mib_stuff_.4 "gehri"
# _mib_stuff_.5 ""
foreach $z ( &snmpwalk( $router, $community, $OID{"SerialUser"} )){
if( $z =~ /\.(\d+) "(.+?)"/ ){
$users{$1} = $2;
}
}
# Get associated connect and idle times
# snmpwalk( SerialStarted ) returns _mib_stuff_.2 0:0:29:19
# snmpwalk( SerialIdle ) returns _mib_stuff_.6 0:0:00:04
foreach $z ( &snmpwalk( $router, $community, $OID{"SerialStarted"} )){
if( $z =~ /\.(\d+) (.+?)\n/ ){
$started{$1} = $2;
}
}
#foreach $z ( &snmpwalk( $router, $community, $OID{"SerialIdle"} )){
# if( $z =~ /\.(\d+) ([^\n]+)\n/ ){
# $idle{$1} = $2;
# }
#}
# Get IP address for each port
# snmpwalk( SerialIpAddress ) returns _mib_stuff_.3 192.168.13.12
foreach $z ( &snmpwalk( $router, $community, $OID{"SerialIpAddress"} )){
if( $z =~ /\.(\d+) ([\d\.]+)/ ){
$ip{$1} = $2;
}
}
# Get connect speeds
# snmpwalk( InSpeed ) returns _mib_stuff_.2 33600
# snmpwalk( OutSpeed ) returns _mib_stuff_.2 50666
foreach $z ( &snmpwalk( $router, $community, $OID{"InSpeed"} )){
if( $z =~ /\.(\d+) (\d+)/ ){
$speed{$1} = $2;
}
}
foreach $z ( &snmpwalk( $router, $community, $OID{"OutSpeed"} )){
if( $z =~ /\.(\d+) (\d+)/ ){
$speed{$1} .= "/" . $2;
}
}
# print out info with some attempt at formatting
foreach $port ( sort { $a <=> $b } keys(%users) ){
printf "$sysName #%-2d %-8s %-15s Connect %s Idle %s %s\n",
$port, $users{$port}, $ip{$port}, $started{$port};
$idle{$port}, $speed{$port};
}
exit 0;
#####################################################
# @return = &snmpwalk( "router", "community", "OID" )
#
# call snmpwalk and return the results. snmpwalk is an external SNMP walk
# program. In my case it is from the ucd-snmp SNMP suite.
# It is available at ftp://ucd-snmp.ucdavis.edu/
#
#sub snmpwalk{
# (my $Router, my $Community, my $OID ) = @_ or return ();
# open(SNMP, "c:/perl/bin/snmpwalk -Oq -v 1 $Router $Community $OID |");
# my @snmp_table = <SNMP>;
# close SNMP;
# return @snmp_table;
#}
--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive http://www.ee.ethz.ch/~slist/mrtg
FAQ http://faq.mrtg.org Homepage http://www.mrtg.org
WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi
More information about the mrtg
mailing list