-1

I run snmptrapd and can see incoming trap, when send trap via snmptrap

snmptrap -c public -v 2c localhost "" 1.3.3.3.3.3.3.3 1.2.2.2.2.2.2 s "Aliens here"

But I no have trap, when send via Perl script

use SNMP;

$sess = new SNMP::Session(DestHost => '127.0.0.1', RemotePort => "162" );

$sess->trap(enterprise=>'.1.3.6.1.4.1.2021', # or 'ucdavis' [default]
                agent => '127.0.0.1', # or 'localhost',[dflt 1st intf on host]
                generic => specific,  # can be omitted if 'specific' supplied
                specific => 5,        # can be omitted if 'generic' supplied
                uptime => 1234,       # dflt to localhost uptime (0 on win32)
                [[ifIndex, 1, 1],[sysLocation, 0, "here"]]);

What's wrong?

Jolta
  • 2,620
  • 1
  • 29
  • 42
Igor
  • 11
  • 4
  • I'm not familiar with SNMP trapping, but your `snmptrap` doesn't look the same as your perl equivalent - where's the `RemotePort`, and how does `.1.3.6.1.4.1.2021` relate to `1.3.3.3.3.3.3.3 1.2.2.2.2.2.2`? – Simon MᶜKenzie Mar 06 '15 at 00:29
  • In first one snmptrap's default target port is 162 so don't think that the issue, and questioner says first one ok. Also the different OIDs .1.3.6.1.4.1.2021 vs 1.3.3.3.3.3.3.3 1.2.2.2.2.2.2, shouldn't (!) matter and there looks to be a more fundamental comms problem. – k1eran Mar 06 '15 at 13:56
  • Using a tool like Wireshark or `tcpdump`, check the traffic of the outgoing interface to see if the packet is really sent. If it is, check whether it arrives on the receiving side. – Jolta Feb 19 '17 at 11:45

1 Answers1

1

Your second version i.e. the perl one is not specifying community or version, unlike the first one. Try adding them

$sess = new SNMP::Session(DestHost => '127.0.0.1', 
                                      RemotePort => "162",
                                      Community => "public,
                                      Version => 2);

Also see http://www.remothelast.altervista.org/SNMP_Perl.html and http://www.net-snmp.org/docs/perl-SNMP-README.html for SNMP::Session usage.

k1eran
  • 4,492
  • 8
  • 50
  • 73