[NCLUG] regex for snmp

mike cullerton michaelc at cullerton.com
Wed Nov 21 11:27:47 MST 2001


hey folks,

a couple of clarifications about all this.

i am using php, not perl. (php allows either perl or posix regex's)

other comments inline...

on 11/21/01 9:59 AM, Mike Loseke at mike at verinet.com wrote:
> Thus spake mike cullerton:

>> so, i would like to break up
>> 
>> system.sysName.0 = gw system.sysLocation.0 = fort collins
> 
> How are you getting all your info on one line? snmpwalk for me dumps one
> entry per line (to STDOUT anyway).

the results are all on one line because i'm a dork and forgot that my web
browser doesn't care about \n's, oops! :)

they are all on separate lines!

i still can't split on the \n though, because stuff 'on the right' can have
any number of \n's. splitting on \n was my original attempt at solving this
problem. oh well, back to the drawing board. atleast now, i can anchor the
beginning of line. maybe it'll all fall in place.

> 
> Ideers: you could (assuming reading one line at a time) dump everything
> into a hash then loop around inside the hash.

this is the idea i was trying to reach.

> 
> You sould also use the SNMP module for perl to do queries on a particular
> string - much faster to grab a few known strings than to do an snmpwalk.
> Dumping the whole MIB can take time on busy routers whereas queries are
> much faster. I have several jobs that query machines and routers (average 2
> queries per machine, up to 200 machines per job, average run is under a
> minute).

dude, give me some credit ;)

i'm not walking the whole MIB. walking parts of the MIB can be useful
though. like 

 snmpwalk router community interfaces.ifTable.ifEntry.ifDescr

instead of something like

 $num_interfaces = `snmpget router community interfaces.ifNumber.0`;

 for ($i=1;$i<= $num_interfaces;$i++) {
  snmpget router community interfaces.ifTable.ifEntry.ifDescr.$i
 }

both of these give me a list of interface descriptions, just in a different
way. ultimately though, one must loop thru the responses some time.

> 
> Whatya doin? huh? huh? :-) Pre-turkey day at work, looking for something
> to do to pass the time.

 pre turkey day at home actually. i'm avoiding my day before turkey day
responsibilities and feeding my hacking jones instead.

 been thinking about snmp a bunch lately, moving some of my home network
monitoring from my linux box to my macosx box and decided to create a couple
functions to help me out. back in the day when my local perl guru was just a
spitwad away, i used perl for all this stuff and now i'm trying to relearn
it...

 besides, i love regexes (and yes evelyn, i have my Mastering Regular
Expressions book handy :)

y'all have a day,
mike

 -- mike cullerton   michaelc at cullerton dot com





More information about the NCLUG mailing list