From: Joao Pompei on
Hi guys,

I know that isn't the thread to ask this, but this is the closest I got
after reading the forum for several hours.

I am trying to use the trap listener and had no success so far. I have
no clue about what is going on here.

My code so far:

require 'rubygems'
require 'snmp'
require 'logger'

log = Logger.new(STDOUT)
m = SNMP::TrapListener.new(:Port => 1062) do |manager|
manager.on_trap_default do |trap|
trap.each_varbind { |v|
puts v.name
puts v.value
}
end
end
m.join

I tried many others codes from the internet and cannot make any
progress. I get a "while true" script that shows me nothing.

The equipment here is from my company so I am not using any loaded mib
(it has a different mib). I tested it with a java traps_listener made
with "SNMP4J" (plus wireshark) and the traps are there on port 1062.

Jackster or anyone else, do you see the traps coming with this code?

thanks
--
Posted via http://www.ruby-forum.com/.

From: jackster the jackle on
I was able to get my version to work but I have to look back now and
find the exact code.

The first thing I notice is that you are listening on port 1062 and it
should be 162, please try and change that and see if that helps.

jackster
--
Posted via http://www.ruby-forum.com/.

From: Joao Pompei on
jackster the jackle wrote:
> I was able to get my version to work but I have to look back now and
> find the exact code.
>
> The first thing I notice is that you are listening on port 1062 and it
> should be 162, please try and change that and see if that helps.
>
> jackster

Hello!

We got the things going here. Thanks all.

Jackster, I can configure witch port I want to use (default is 162, but
in linux only the root user has access to that port).

The problem was the ip address. I believe that linux by default doesn't
address 'localhost' to eth2 (localhost binds with some line in some
/etc/net/config.blabla) and because of that I wasn't receiving any
messages.

Here is the code that I am using now. Note the exact ip address on it:

m = SNMP::TrapListener.new(:Host => '192.168.31.5', :Port => 2062) do
|manager|
manager.on_trap_default do |trap|
trap.each_varbind { |v|
puts 'OID: ' + v.name.to_s + ' Value: ' + v.value.to_s
}
end
end
m.join

This code give me this answer:

OID: 1.3.6.1.6.3.1.1.4.1.0 Value: 1.3.6.1.4.1.xxxx.6.1.2.2.13.7
OID: 1.3.6.1.2.1.1.5 Value: Equip_name
OID: 1.3.6.1.4.1.xxxx.6.1.2.2.3.3.1.2 Value: 2
OID: 1.3.6.1.4.1.xxxx.6.1.2.2.3.3.1.3 Value: 2
OID: 1.3.6.1.2.1.1.3.0 Value: 5 days, 01:17:22.37
OID: 1.3.6.1.6.3.1.1.4.1.0 Value: 1.3.6.1.4.1.xxxx.6.1.2.2.13.15

Where xxxx is the company register on IANA.

Thanks guys. Ruby forums are a very good source of solutions.

Joao Pompei
--
Posted via http://www.ruby-forum.com/.