Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Send SNMP trap

by LazerRed (Pilgrim)
on Sep 23, 2003 at 20:49 UTC ( #293674=note: print w/ replies, xml ) Need Help??


in reply to Send SNMP trap

I've a couple quick thoughts/questions on this...

Check where your building your Net::SNMP session, and verify what version of SNMP you are using. The docs for Net::SNMP, at the end of the traps section, states:

NOTE: This method can only be used when the version of the object is set to SNMPv1.

One other thing that poped into my head, is networks. I hope that your two machines are on the same subnet as your manager... Most routers drop snmp by default, just a thought. Should have read your comment more carefully, Doah!

Update:Have you tried changing:
my @oids = ($svSvcName, OCTET_STRING, $message);

To:
my @oids = ($svSvcName, 0x01, $message);

A longshot, but I'm rather inexperienced with sending traps.

LR

Whip me, Beat me, Make me use Y-ModemG.


Comment on Re: Send SNMP trap
Select or Download Code
Re: Re: Send SNMP trap
by tertullian01 (Acolyte) on Sep 23, 2003 at 22:04 UTC
    The session is using SNMPv1. I tried changing OCTET_STRING to 0x01 and it ended in the same result.
    Unknown ASN.1 type [0x01]
    I am including the full code so anyone can take a look at what is going on:
    use strict; use Net::SNMP qw(:snmp); my ($session, $error) = Net::SNMP->session( -hostname => shift || '$ +host', -community => 'public', -version => 'snmpv1', -port => shift || 16 +2 ); if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; } my $svSvcName = '1.3.6.1.4.1.77.1.2.3.1.1'; my $message = "THIS IS AN SNMP TEST"; my @oids = ($svSvcName, "OCTET_STRING", $message); #my @oids; my $result = $session->trap( -agentaddr => '$monitor', -varbindlist => \@oids #-varbindlist => [$svSvcName, OCTET_STRIN +G, "$message"] ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } $session->close;
    Also I don't know if this is of importance but the script is running on a Windows 2000 machine with perl 5.8
      use Net::SNMP qw(:asn1); # missing $monitor? my $monitor = '192.168.254.1'; # remove quotes from OCTET_STRING, it's a constant. my @oids = ($svSvcName, OCTET_STRING, $message);

      the above changes make it work for me.

      # snmptrapd -f -P 2003-09-23 15:20:06 NET-SNMP version 5.0.6 Started. 2003-09-23 15:20:25 192.168.254.1(via 192.168.254.1) TRAP, SNMP v1, co +mmunity public SNMPv2-SMI::enterprises Enterprise Specific Trap (0) Uptime: 0 +:00:01.00 SNMPv2-SMI::enterprises.77.1.2.3.1.1 = STRING: "THIS IS AN SNM +P TEST" 2003-09-23 15:20:48 192.168.254.1(via 192.168.254.1) TRAP, SNMP v1, co +mmunity public SNMPv2-SMI::enterprises Enterprise Specific Trap (0) Uptime: 0 +:00:01.00 SNMPv2-SMI::enterprises.77.1.2.3.1.1 = STRING: "THIS IS AN SNM +P TEST" 2003-09-23 15:21:08 192.168.254.1(via 192.168.254.1) TRAP, SNMP v1, co +mmunity public SNMPv2-SMI::enterprises Enterprise Specific Trap (0) Uptime: 0 +:00:00.00 SNMPv2-SMI::enterprises.77.1.2.3.1.1 = STRING: "THIS IS AN SNM +P TEST"
        That worked perfectly. I don't remember when I added the quotes to OCTET_STRING but that ridded me of the error. However what fixed the true proble was changing THIS: use Net::SNMP qw(:snmp); TO: use Net::SNMP qw(:asn1); Thanks for your help.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://293674]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-12-19 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (83 votes), past polls