Question

I would like to do the following, but I'm not sure I'm using the best method:

A perl script, running on a Sparc/Solaris 10 machine, should wait for incoming SNMP trap packets (on port 162 for instance). When it receives a trap, it should decode it and do some processing on it, and then resume waiting for the next trap.

I've looked into Net::SNMP by David M. Town, but I think it only allows sending requests and receiving responses. I can't find a method to wait for spontaneous trap messages in this documentation: http://search.cpan.org/dist/Net-SNMP/lib/Net/SNMP.pm

The Net-SNMP package, on the other hand, seems like a very robust and well-used library, but even there the documentation does not provide me with a clear path. SNMP::TrapSession allows me to send traps, but not receive them (?).

Some googling leads me to suggestiongs that I should use the "snmptrapd" binary and use the embedded perl functions of it, to call my script when snmptrapd receives a message. This could work, but would be impractical since the embedded perl option requires a perl binary compiled without large file support. I do not own the target system and hence cannot replace the compiler/interpreter. I could ship my software with a specially-compiled perl, but that would give me cross-platform issues I was hoping to avoid.

The reason I'm using Perl and not Java with SNMP4J or similar, is that I have legacy perl code which has previously depended on HP NNM's perl API, and I need to move to a free software back-end to eliminate the license cost.

Was it helpful?

Solution

A simple example of using Perl library SNMP_Session.pm for parsing SNMP traps: Essential SNMP - page 194.

OTHER TIPS

Are you looking for a library routine to receive and parse the packet? Can you listen for UDP packets yourself and then pass any packets you receive to the snmp library to parse them? That's what I'm doing, though I am using python rather than perl.

If you get the SNMP_Session library (which is entirely Perl btw) you can do things like this:

my $trap_session = SNMPv1_Session->open_trap_session ();
my ($trap, $sender_addr, $sender_port) = $trap_session->receive_trap ();
my @blah = $trap_session->decode_trap_request ($trap)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top