penguin has asked for the wisdom of the Perl Monks concerning the following question:

Hey all, I'm looking for an elegant way to trap and process SNMP traps from a simple perl script. I've noticed that SNMP_Session.pm has the capability. However, this module isn't listed on CPAN, and that concerns me. Any suggestions or wisdom with regards to any segment of the above question would be greatly appreciated. Thanks.

Replies are listed 'Best First'.
Re: SNMP Trap Receiver
by RMGir (Prior) on Aug 15, 2002 at 01:27 UTC
    Check out Net::SNMP, which is descended from SNMP_Session.pm.

    I'm afraid my knowledge of SNMP is pretty shaky, but it looks like it will let you send requests and traps.
    --
    Mike

      Thanks for your help Mike. Unfortunately, Net::SNMP seems to do everything except receive traps ;) The low-down is as follows. If you are a SNMP agent running on some device on a network, SNMP allows you to do the following: "Some one's asking me for some info that she knows I have. That's cool, I'll give her said info." That's a SNMP get request followed by the agent's reponse (put, I think). Also, "Damn man! There's something wrong with me!! I'd better send a message out to everyone in my community in case they care. (And I'm likely going to do it on port 162 incidentally.)" That's sending a trap. Net::SNMP is cool with these things.

      I'm more interested in making a network management tool. These means I'd be making snmp requests (no problems here) and watching port 162 for traps to come in. Problem is, Net::SNMP doesn't seem to have any way to "sit and look for traps". I guess I could just bite the bullet and do it myself; but it seems like something that should be done by someone on CPAN ;)

      Anyways, thanks for reading this long, and likely very inaccurate description of SNMP. It was fun ;)
        Great description, thanks!

        Check out SNMP-4.2.0. It has both SNMP::Session and SNMP::TrapSession, so maybe there's some hope there :)

        If not, check out the other SNMP packages http://search.cpan.org turns up. There's enough of them, ONE of them has to do it...
        --
        Mike

Re: SNMP Trap Receiver
by zengargoyle (Deacon) on Aug 15, 2002 at 19:01 UTC

    penguin is correct, there aren't any modules that do the Agent side of SNMP. Neither Net::SNMP or SNMP have the needed functions.

    Your best bet will be using Net::Server::Proto::UDP and possibly Mon::SNMP and/or Convert::BER/Convert::ASN1 to decode the traps.

    I recently spent long and hard looking for a perl based SNMP Agent to no avail. I ended up using the ucd-snmp agent's pass-through capabilities to hand off portions of the MIB tree to perl scripts.

    Start with the Net::SNMP module since it's pure perl it shouldn't be to hard to reverse engineer the trap construction.