just dave has asked for the wisdom of the Perl Monks concerning the following question:

Hello !
I've already asked a similar question a week ago (or so) and since then there were changes and I'd like to ask now, when I know better what exactly it is that I'm asking..
So,
I'm using the netsnmp libraries, i.e- NetSNMP::agent (found at: http://net-snmp.sourceforge.net/)
When someone runs 'snmpwalk' on my servers, he sees:
SNMPv2-SMI::enterprises.54321.1.1.1 = INTEGER: 0 SNMPv2-SMI::enterprises.54321.1.1.2 = INTEGER: 1 SNMPv2-SMI::enterprises.54321.1.1.3 = INTEGER: 1 SNMPv2-SMI::enterprises.54321.1.1.5 = INTEGER: 1 SNMPv2-SMI::enterprises.54321.1.1.8 = INTEGER: -1 SNMPv2-SMI::enterprises.54321.1.1.9 = INTEGER: 1 SNMPv2-SMI::enterprises.54321.1.1.12 = INTEGER: 0 SNMPv2-SMI::enterprises.54321.1.1.13 = INTEGER: 0 SNMPv2-SMI::enterprises.54321.1.1.16 = INTEGER: 3879900 SNMPv2-SMI::enterprises.54321.1.2.1 = INTEGER: 1060249 SNMPv2-SMI::enterprises.54321.1.2.2 = INTEGER: 1060249 SNMPv2-SMI::enterprises.54321.1.2.3 = INTEGER: 12900 SNMPv2-SMI::enterprises.54321.1.2.4 = INTEGER: 21596 SNMPv2-SMI::enterprises.54321.1.2.5 = INTEGER: 60
Now, this doesn't help anyone that doesn't have a list of these OIDs and their meaning.
So, I'd like it to look like this:
number of udp connections = INTEGER: 0 number of tcp connections = INTEGER: 1 number of users connected = INTEGER: 1 Total connected so far = INTEGER: 1 blah blah blah blah = INTEGER: -1 ...
1. Can this be done?
2. How ??
Thank you, Dave

Replies are listed 'Best First'.
Re: Formating snmpwalk output
by lima1 (Curate) on Apr 09, 2006 at 13:54 UTC
    You have such a list and snmpwalk is a command line tool? then write a wrapper for that tool that loads this list in a hash and parses the output like this:
    use strict; use warnings; my %lookup = ( 'SNMPv2-SMI::enterprises.54321.1.1.1' => 'number of udp + connections'); # data can be a filehandle with the output generated # by File::Temp while (my $line = <DATA>) { chomp $line; my ($oid, $cnt) = $line =~ m{ \A (.*) \s = \s INTEGER: \s ([+- +]?\d+) \z}xms; $oid = $lookup{$oid} if defined $lookup{$oid}; print "$oid, $cnt\n"; } __DATA__ SNMPv2-SMI::enterprises.54321.1.1.1 = INTEGER: 0 SNMPv2-SMI::enterprises.54321.1.1.2 = INTEGER: 1 SNMPv2-SMI::enterprises.54321.1.1.3 = INTEGER: 1 SNMPv2-SMI::enterprises.54321.1.1.5 = INTEGER: 1 SNMPv2-SMI::enterprises.54321.1.1.8 = INTEGER: -1 SNMPv2-SMI::enterprises.54321.1.1.9 = INTEGER: 1 SNMPv2-SMI::enterprises.54321.1.1.12 = INTEGER: 0 SNMPv2-SMI::enterprises.54321.1.1.13 = INTEGER: 0
      Thanks, this is a good solution, but I hoped I could avoid it.
      I hoped that there might be a way to "tell" the netsnmp library that I want to send another string or something like this.
      You see, using these libraries , I merely give the integer value and "tell" it that it's an integer that I'm sending, all the rest is done for me (using : $request->setValue($type, $value), where type is INTEGER and value is my value;).
      I hoped that maybe I could add another var or something that will hold the info I want to send (thinking about it, aesthetics don't matter so I don't really mind keeping the message and adding the info I want)
      maybe somebody knows the netsnmp library and can help here ?
Re: Formating snmpwalk output
by traveler (Parson) on Apr 09, 2006 at 16:33 UTC
    Both your apps and snmpwalk can use names if the mibs are properly installed. You do not get to choose the names, though: it will use the canonical names for the OIDs as listed in the MIBs. (How would it know you wanted "number of udp connections" instead of "number of UDP Connections" for example?)

    Check the README.mibs file for more info on the MIBS. Since 54321 is not officially allocated, I'm guessing that it is an example. If the MIB is for xyz.com, contact them to get a mib file with the appropriate names.

    --traveler

Re: Formating snmpwalk output
by Mr. Muskrat (Canon) on Apr 10, 2006 at 02:08 UTC

    In the Net-SNMP Perl documentation, you'll find some configuration variables that change the default behavior. The one you are interested in modifying is $SNMP::use_long_names.

      THANK YOU ALL !
      You were great help, I think I'm now on the right track to solving this problem, as I'm a newbe to perl and snmp(...)
      I'll look for an example, for extra help.
      Thanks again,
      Dave