the sender code looks like this (just copied from Essential SNMP Book):
use SNMP_util "0.54"; # This will load the BER and SNMP_Session for u +s snmptrap("public\@172.20.50.13:162", ".1.3.6.1.4.1.2789", "sunserver1" +, 6, 1247,".1.3.6.1.4.1.2789.1247.1", "int", "2448816");
the reciever code I got from Mr. Leinen's site:
my $trap_session = SNMPv1_Session->open_trap_session () or die "cannot open trap session"; my ($trap, $sender_addr, $sender_port) = $trap_session->receive_trap ( +) or die "cannot receive trap"; my ($community, $enterprise, $agent, $generic, $specific, $sysUptime, $bindings) = $session->decode_trap_request ($trap) or die "cannot decode trap received" ... my ($binding, $oid, $value); while ($bindings ne '') { ($binding,$bindings) = &decode_sequence ($bindings); ($oid, $value) = decode_by_template ($binding, "%O%@"); print BER::pretty_oid ($oid)," => ",pretty_print ($value),"\n"; }
Mr. Leinen has already replied to my inquiry. he pointed out the errors in those codes, though I'm not sure what the second argument is for the decode_by_template:
Now to the three errors in "recivtrap.pl":
* You test for defined($trap) before decoding the trap. This is good. But shouldn't the decoding of the bindings in the trap be within the scope of the "if" as well?
* Check for consistent use of $trap_session (vs. $session)
* decode_by_template takes at least two arguments.
The first two errors would have generated warnings or errors with
"perl -w" and "use strict;". The third one unfortunately not, because I failed to declare the argument list in the prototype definition for "decode_by_template" in BER.pm. I will add that to the next release of BER.pm.3

In reply to Re^2: Question about Decoding Traps using SNMP_Session.pm by jamjam
in thread Question about Decoding Traps using SNMP_Session.pm by jamjam

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.