in reply to Formatting snmpget output and OIDs

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 :)

Replies are listed 'Best First'.
Re^2: Formatting snmpget output and OIDs
by just dave (Acolyte) on Apr 05, 2006 at 11:07 UTC
    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!
        Thanks to both of you Jason, you are almost correct, I want to change the output format that someone who runs 'snmpWALK' on my servers sees, and I understud that it IS possible since the 'walk' does work with names, no ??