Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Net::SNMP ignoring/omitting characters

by Hagalaz (Initiate)
on Apr 09, 2015 at 16:18 UTC ( #1122968=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1122968]
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2020-11-24 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?