1
votes

I'm attempting to use Ruby SNMP to capture SNMP traps from various devices. In order to test them I'm attempting to send them from my laptop using the 'snmptrap' command. I can see that the traps are being sent and arriving at my server (the server is the manager) in packet captures, as well as in the 'snmptrapd' utility when I run it. I'm using the following example code exactly as it is, in the demo from the documentation to set up a TrapListener.

require 'snmp'
require 'logger'

log = Logger.new(STDOUT)
m = SNMP::TrapListener.new do |manager|
    manager.on_trap_default do |trap|
      log.info trap.inspect
    end
end
m.join

I'm sending an SNMPv2c trap, and nothing ever appears on the screen...

Here is the command I'm using to send a test SMTP trap, in the even that it's useful:

snmptrap -v 2c -c public hostname_goes_here  SNMP-NOTIFICATION-MIB::snmpNotifyType SNMPv2-MIB::sysLocation

Any suggestions appreciated! Thanks!

1

1 Answers

0
votes

I was stuck on this for a long time as well. It turns out that by default, Traplistener only opens ports on 127.0.0.1. To make it listen on ALL interfaces on the port you specified (or default port 162), specify a :Host option. '0' makes it listen on ALL interfaces, or you can provide an IP address.

log = Logger.new(STDOUT)
m = SNMP::TrapListener.new(:Host => 0) do |manager|
  manager.on_trap_default do |trap|
    log.info trap.inspect
  end
end
m.join