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

Hello I have a fully working NET-SNMP perl program, using
use NetSNMP::OID (':all'); use NetSNMP::agent (':all'); use NetSNMP::ASN (':all');

The problem is that when I send an OID request (e.g - snmpget -c public -v 1 MY_IP .1.3.6.1.4.1.54321.1.2.1 )
I get the answer -
SNMPv2-SMI::enterprises.54321.1.2.1 = INTEGER: 2082447.
Now, the part: 54321.1.2.1 cannot be understood by anyone who does not hold a list of OIDs and their meaning, furthermore, the SNMPv2-SMI::enterprises is not needed or used.
So I'd like to change this.
How do I change this line and delete(or not present) the part I don't want ?? ( I don't actually write it- it is done by the wrapper ) Thanks

2006-04-05 Retitled by Corion, as per Monastery guidelines
Original title: 'SNMP'

Replies are listed 'Best First'.
Re: Formatting snmpget output and OIDs
by McDarren (Abbot) on Apr 05, 2006 at 09:24 UTC
    I'm not quite clear about your question, but I figure that you are probably only really interested in the return value of the SNMP query. That is, everything after the equals sign (=).

    In which case, I'd just do a split like so:

    my $snmp_return = "SNMPv2-SMI::enterprises.54321.1.2.1 = INTEGER: 2082 +447"; my (undef, $wanted) = split /=/, $snmp_return;
    Does that help?

    Update: Probably worth noting that the above approach would break if the data returned actually contained an equals sign, because $wanted would only contain everything between the first and second "=". However, you could overcome this by modifying the split to include a limit - like so:

    my (undef, $wanted) = split /=/, $snmp_return, 2;

    Cheers,
    Darren :)

      Thanks Darren, But I probably didn't explain myself correctly, I'll try and explain again:
      I don't "have" the SNMPv2-SMI::enterprises.54321.1.2.1 = INTEGER: 2082 string.
      This is what is sent as an answer to whom ever sent the querry.
      It is sent by the netsnmpand, the only thing I do is send the appropriate value. e.g
      $request->setValue($fieldtype, $sumValue);
      where $fieldtype is ASN_INTEGER and $sumValue is the value I get from a file.
      the $request is set(as shown above), and used by the handler that is registered to the agent.
      I hope it is clear now (tried my best ... :-) ) Thanks again
        Okay, well I obviously didn't get it the first time - but I'm afraid that I still don't.

        Those modules you are using - are they home-grown?

        I can't find any of them on CPAN, and setValue is not a function that's available via Net::SNMP.

        Perhaps you can show some code that demonstrates your problem a bit clearer?

        Sorry I can't be of more help.

        If I understand the question correctly you are working on an SNMP server in perl (apparently using NetSNMP::agent, although it would help if you specified that) and you want to change the output format that someone who runs 'snmpget' on your servers sees? Do I understand that correctly?

        If so, the answer is "you can't", the server can only return the values, you would have to change the client to control how they are displayed at that end.


        We're not surrounded, we're in a target-rich environment!