Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Net::SNMP ignoring/omitting characters by Hagalaz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-19 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found