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

I am trying to send a simple SNMP version 1 trap to a Sun box running HP OpenView using an example program I saw on this site as follows:
#!/usr/local/bin/perl # Define local variables here $manager='10.10.20.10'; $host='192.168.65.21'; use Net::SNMP qw(:asn1); $sysedgemgmt='1.3.6.1.4.1.546.9.6'; $sysedgemule='1.3.6.1.4.1.546.9.6.0.2724'; $message="hi there"; @oid=($sysedgemule, OCTET_STRING, $message); ( $session, $error)=Net::SNMP->session( -hostname => shift || $host, -version => 'snmpv1', -community => 'public', -port => shift || 162); if (!defined($session)) { printf("SESSIONERROR: %s.\n", $error); } $procdown=$session->trap( -enterprise => $sysedgemgmt, -agentaddr => $manager, -generictrap => 6, -specifictrap => 2724, -varbindlist => \@oid ); if (!defined($procdown)) { printf("ERROR: %s.\n", $session->error); } $session->close; exit 0;
The above code executes without error, yet does not send a snmp trap. I have used a data scope to see if the trap is acturally being send, and it is not being send from the originating node. Any suggestions?

thanks
Neil

Edit by tye, add formatting

Replies are listed 'Best First'.
Re: SNMP Trap not working with Perl 5.8.3
by geektron (Curate) on Jun 08, 2004 at 23:43 UTC
    you could always use something like snoop, tcpdump, etc to see if the trap is sending out of the socket.

    eliminate one failure possibility at a time.

    1. make sure it's a legit trap (as another poster noted)
    2. make sure the trap is sending (via network sniffers)
    3. make sure the OpenView box is accepting traps for that host
    just an off-the-top list.

    i don't immediately remember the ports that traps use, and i don't have access to the code i maintained for a trap collector at a previous company, so i'm relying on memory.

      Hi Yes it is a legal trap. Problem is that the trap is not being generated by originating node. used snoop and sniffer to verify. Even if is not a legal trap, something should be sent. thanks Neil
        the last part of the dumb questions -- you *do* have all the required SNMP libs on the machine you're trying to send traps from ....
        [meo@host dir]$ ps ax | grep sn 617 ? S 0:34 /usr/sbin/snmpd -s -l /dev/null -P /var/run +/snmpd -a
        i'd hate for it to be something like that. IIRC, Net::SNMP is an *interface* to SNMP, not a replacement *for* SNMP
Re: SNMP Trap not working with Perl 5.8.3
by hsinclai (Deacon) on Jun 08, 2004 at 21:35 UTC
    Try putting a comma after 161..

    So, what is in $error?

    Ensure 6.2724 is real in your MIBS -- that could silently fail..
      tried the comma, did not work. used snoop to see if anything is getting generated and it is not. thanks Neil
Re: SNMP Trap not working with Perl 5.8.3
by hsinclai (Deacon) on Jun 08, 2004 at 23:51 UTC
    GOSH!

    162, not 161.
    162 is the default trap receiver.. could Net::SNMP be failing to construct and send the trap because of this?
      I tried both 161 and 162. Also used snoop to see if packet goes out. It does not. Neil
        I don't think your problem is Perl related. Somehow harder to figure out - may be something up with your systems?

        I changed your code block slightly - just to use strict - and it works perfectly sending to a remote FreeBSD machine receiving traps on 162.

        #!/usr/bin/perl -w use strict; use Net::SNMP qw(:asn1); my $message="hi_there"; my $manager='1.2.3.4'; my $host='1.2.3.5'; my $sysedgemgmt='1.3.6.1.4.1.546.9.6'; my $sysedgemule='1.3.6.1.4.1.546.9.6.0.2724'; my @oid=($sysedgemule, OCTET_STRING, $message); my ($session, $error)=Net::SNMP->session( -hostname => shift || $host, -version => 'snmpv1', -community => 'ellengirl', -port => shift || 162, ); if (!defined($session)) { printf("SESSIONERROR: %s.\n", $error); } my $procdown = $session->trap( -enterprise => $sysedgemgmt, -agentaddr => $manager, -generictrap => 6, -specifictrap => 2724, -varbindlist => \@oid, ); if (!defined($procdown)) { printf("ERROR: %s.\n", $session->error); } $session->close; exit 0;


        and here's the data we received at UDP 162
        Jun 9 14:45:14 remotehost snmptrapd[13197]: 1.2.3.5: Enterprise Speci +fic Trap (2724) Uptime: 0:00:00.00, SNMPv2-SMI::enterprises.546.9.6.0 +.2724 = STRING: "hi_there" Jun 9 14:45:14 remotehost hsinclai: The default snmptrapd traphandler + has just made a mark.

        Note: I've got snmptrapd creating a log event after receiving a trap
        Also note, hm specified v1, but logged in as snmpv2 !!
Re: SNMP Trap not working with Perl 5.8.3
by davidj (Priest) on Jun 08, 2004 at 21:21 UTC
    Questions are much easier to read (and thus, understand) if they are formatted properly.
    Please read Writeup Formatting Tips.
    I have no doubt it will result in more timely replies to your questions.

    davidj
      thanks for the tip. was not aware of the <CR>'s getting ignored. Will reformat next time. thanks again. Neil