Thanks Jeff. Unfortunately I am using the SNMP Perl module supplied with net-snmp. When I run my script it returns nothing - error or no error - it quietly returns. When I run snmptrap with the same parameter from the shell it works a treat. Obviously a syntax error, but I wouldn't mind a little feedback from the script to help debugging!
Thanks Andy -----Original Message----- From: Jeff Saxton [mailto:[EMAIL PROTECTED] Sent: Thursday, April 14, 2005 4:11 PM To: Andy Ford Subject: Re: Are there any examples of SNMP::TrapSession - I'll be darnedIf I can get it to work! #!/usr/bin/perl -w ############################################################### # ultra-simple snmp trap agent # Jeff Saxton <[EMAIL PROTECTED]> # 0.1 Oct 19, 2004 # Assumes that the user actually knows a little about SNMP ;) ############################################################### use Net::SNMP; $hostname = '127.0.0.1'; $port = '162'; # default port for trapd $nonblocking = "0"; $version = '1'; $seconds = "30"; $retries = "3"; $community = "fubar"; # $debug bitmask options # 0x02 - Message or PDU encoding and decoding # 0x04 - Transport Layer # 0x08 - Dispatcher # 0x10 - Message Processing # 0x20 - Security #$debug = "0x00"; $debug = "0x3F"; ($session, $error) = Net::SNMP->session( -hostname => $hostname, -port => $port, -nonblocking => $nonblocking, -version => $version, -timeout => $seconds, -retries => $retries, -debug => $debug, -community => $community, ); unless ( $session ) { print "Error: $error\n"; exit 1; } print "sending trap....."; $timeticks = time; $oid = '1.3.6.1.6.3.1.1.4.1.0'; push @oid_value, ( '1.3.6.1.2.1.1.3.0', TIMETICKS, $timeticks ); # SNMPv2-MIB::sysUpTime.0 push @oid_value, ( '1.3.6.1.6.3.1.1.4.1.0', OBJECT_IDENTIFIER, $oid); # SNMPv2-MIB::snmpTrapOID.0 # my enterprise specific oid push @oid_value, ( '1.3.6.1.4.1.20338.1.2.1', INTEGER, 100); # SNMPv2-SMI::enterprises.28560.1.2.1 $result = $session->trap( -enterprise => "1.3.6.1.4.1", -agentaddr => "127.0.0.1", -generictrap => 6, -specifictrap => 0, #-timestamp => $timeticks, -varbindlist => [EMAIL PROTECTED], ); unless ( $result ) { print "error: $session->error" } $session->close; exit; On Thu, 2005-04-14 at 03:22, Andy Ford wrote: > I am trying to send a trap using the following and failing miserably!! > > Can anyone see where I am going wrong? > > use SNMP; > > my $sess = create_session(); > > my $vars = new SNMP::Varbind( > > ['.1.3.6.1.4.1.776.69.2.1',0,'test'], > > > ['.1.3.6.1.4.1.776.69.1.1',0,'agent_name'], > > ['sysName',0,'test'], > > ['ifIndex',1,1] > > ); > > $sess->trap( > > oid => 'enterprises.776.69.2', > > uptime => '', > > $vars > > ); > > sub create_session { > > my $host = "127.0.0.1"; > > my $community = "public"; > > my $port = 161; > > print "setting up a sesion for $host\n"; > > my $sess = new > SNMP::Session( > > DestHost => $host, > > Community => $community, > > RemotePort => $port, > > Timeout => 300000, > > Retries => 3, > > Version => '2c', > > UseLongNames => 1, # Return full OID tags > > UseNumeric => 1, # Return dotted decimal > OID > > UseEnums => 0, # Don't use enumerated > vals > > UseSprintValue => 0 # Don't pretty-print > values > > ); > > return $sess; > > } > > I am essentially reading in traps output from snmptrapd in the format > > oid value > > oid value > > oid value > > etc > > I'd run the snmptrap command from the shell but I'd need to regexp the > values to determine their type (INTEGER, STRING, OID etc etc), as > snmptrapd doesn't output this level of detail (AFAIK). > > Thanks > > Andy > > This e-mail is private and may be confidential and is for the intended > recipient only. If misdirected, please notify us by telephone and > confirm that it has been deleted from your system and any copies > destroyed. If you are not the intended recipient you are strictly > prohibited from using, printing, copying, distributing or > disseminating this e-mail or any information contained in it. We use > reasonable endeavours to virus scan all e-mails leaving the Company > but no warranty is given that this e-mail and any attachments are > virus free. You should undertake your own virus checking. The right to > monitor e-mail communications through our network is reserved by us. > ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_ide95&alloc_id396&op=click _______________________________________________ Net-snmp-users mailing list Net-snmp-users@lists.sourceforge.net Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users