[mrtg] Still need some more help... Please

GUARENO at FORDHAM.EDU GUARENO at FORDHAM.EDU
Wed Jun 26 14:12:39 MEST 2002



Hi:
You've been a great help and I appreciate taking some of your time to
answer my questions.

I obtained a document which contains the Mib Hierarchy for the Ascend Max
6000, and it is starting to make more sense.
And I now also understand about returned values (integer Vs string), but
I'm having a tough time implementing it.... :(
As far as my dilema is concerned, I am using a script called
"cat_internet.pl" ( obtained from the usu.edu website).  This person was
able to obtain user info from their device using this script.  My question
(yes another question) : How do make the script print out the results in
the form of a table.
I know I must change the OID informaion (which I did) but I get some errors
saying that some of the lines do not make sense specially the one starting
with %OID.  Is this supposed to be an arraydeclaration, if so should I use
@OID = (   ?
How would this script be called from within the .cfg file?  (forgive my
stupidity).  Do I need to change anything eslse besides the OIDs?
Thanks  in advanced for your continued help...

#!/usr/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 Portmaster 3.
#
# Written 30-July-1998
#
# USAGE: pmfinger community at portmaster.foo.edu
#
# The output of this script looks like:
# pm1 #2  fred    192.168.2.111   Connect 0:1:06:53 Idle 0:0:00:07
26400/31200
# pm1 #3  joe     192.168.2.87    Connect 0:2:13:47 Idle 0:0:00:07
31200/33600
# pm1 #4  gehri   192.168.2.69    Connect 0:2:23:03 Idle 0:0:00:01
28800/45333
#

# define the SNMP Object ID's we are looking for.  The Object names for
# the "enterprises.livingston..." MIB variables are way too ugly for words,
# so we use ".1.3.6.1.4.1.307..." OIDs instead

%OID = (
    "sysName"           =>    "system.sysName",
    "SerialUser"  =>    ".1.3.6.1.4.1.307.3.2.1.1.1.4",
    "SerialStarted"     =>    ".1.3.6.1.4.1.307.3.2.1.1.1.9",
    "SerialIdle"  =>    ".1.3.6.1.4.1.307.3.2.1.1.1.10",
    "InSpeed"           =>    ".1.3.6.1.4.1.307.3.2.1.1.1.11",
    "OutSpeed"          =>    ".1.3.6.1.4.1.307.3.2.1.1.1.12",
    "SerialIpAddress"   =>    ".1.3.6.1.4.1.307.3.2.1.1.1.14",
);

# get args
($community,$router) = split(/\@/, $ARGV[0]);
#print "$community,$router\n";
die <<USAGE  unless $community && $router;

USAGE: pmfinger 'community'\@'portmaster.foo.edu'

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, "/usr/local/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