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

"Helmert, Jörg" Joerg.Helmert at EINSTEINet.de
Wed Jun 26 15:29:26 MEST 2002


Hi,

%OID is a hash, @OID an Array.
While Arrays are indexed by an integer value, hashes can be indexed by a
string.

In your case you can access %OID like:
print $OID{sysName}; this will print out: system.sysName

This cannot be done with arrays.

I don't know what you changed. If I enter below definition for %OID in a
small perl script, I can execute it without errors.
Maybe, while changing, you accidentally deleted or changed too much?

Regarding the script:
Remember one of my earlier mails regarding to calling of external programs?
I wrote, that you usually cannot use calls to Unix binaries on windows.

Here you run into that problem.
The script calls snmpwalk:
open(SNMP, "/usr/local/bin/snmpwalk -Oq -v 1 $Router $Community $OID|");

Its in the definition of sub snmpwalk.

In resource kit for NT you find snmputil.exe, which can be used instead.
I prefer to load Perl-SNMP-Libraries into my scripts.
Like snmputil in mrtg or like net-snmp.


bye,

Joerg Helmert

-----Ursprüngliche Nachricht-----
Von: GUARENO at FORDHAM.EDU [mailto:GUARENO at FORDHAM.EDU]
Gesendet: Mittwoch, 26. Juni 2002 14:13
An: Helmert, Jörg
Cc: mrtg at list.ee.ethz.ch
Betreff: Still need some more help... Please



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