http://qs321.pair.com?node_id=1122968

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

Greetings everyone. I am having an issue (basically an inconsistency in its behavior) with a bit of code using the module Net::SNMP to retrieve a value that is encoded as a Hex-string. Using regular snmpget in the shell, without any arguments, this is what I get:

snmpget -v2c -cpublic IP OID OID = STRING: "9;ct"

If I use the -Ox command line argument, the result is

snmpget -v2c -cpublic -Ox IP OID OID = Hex-STRING: 39 3B 63 74

Which is the correct result. Now, however, if I do the same with Net::SNMP...

use warnings; use strict; use Net::SNMP; use Data::Dumper; (Variable declaration omitted) my $var = Net::SNMP->session( '-hostname' => $host, '-version' => $ver +, '-community' => 'public', '-translate' => [-octetstring => 0]); my $response = $var->get_request( '-varbindlist' => [$oid]); print Dumper $response;

I should get the same as the snmpget above, correct? And yet, I am not getting it:

$VAR1 = '9ct';

And if I use unpack ('H*', $response), I get:

$VAR1 = '396374';

Which shows the two bytes that are missing, corresponding to the semi-colon (;) that is present in the original snmpget.

There's basically one character in the hex string (two bytes) missing, and I have no idea why or how to fix it. Several hours of google searches, reading the module's CPAN page, scanning perlmonks and another well known questions and answer sites have been fruitless. I've been using Net::SNMP for a long time, quite intensively even, and had never had such an issue.

I therefore turn to perlmonks, hoping that someone might have ran into this issue, and knows what the problem (and its solution) is.

Thank you very much in advance for your time (and pardon any imprecision, it is my first post here),

Hagalaz

p.s. No, this doesn't just happen with the semicolon, I have ran into other cases with this OID.

Replies are listed 'Best First'.
Re: Net::SNMP ignoring/omitting characters
by jimw54321 (Acolyte) on Apr 09, 2015 at 20:02 UTC
    Not sure if this matters. The code -octetstring appears to be missing single quotes whereas your other parameters have them.