In this part:

($type eq 'string') && do { $value = encode_string($value); push @enoid, [$oid,$value]; next; };

You process the oids of type string (e.g. $value = '9A 20 FF 19'). One must assume that encode_string is not encoding as it should.

If you have root access somewhere on the path between the host performing the SNMP gets and the router, run tcpdump with something like:

tcdump -nvv port 161

And do a get with HPOV, and likewise with your perl script. Hopefully it will be obvious what needs to be done. Either you're calling encode_String incorrectly, or you can do the same much more efficiently with pack.

This latter approach was one I adopted when playing around with MRTG. It comes with a module for dealing with the nitty-gritty of speaking SNMP. The perl code for assembling and disassembling SNMP packets is some of the most unnecessarily convoluted and poorly structured code it has been my misfortune to lay my eyes upon.

I just checked: SNMP_Session, the one and same. The code is just abysmal. MRTG is nice, though :)


print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

In reply to Re: SNMP String format by grinder
in thread SNMP String format by mugster

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.