Class: Net::SNMP::Listener
- Inherits:
-
Object
- Object
- Net::SNMP::Listener
- Includes:
- Debug
- Defined in:
- lib/net/snmp/listener.rb
Overview
Implements a generic listener for incoming SNMP packets
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#packet ⇒ Object
Returns the value of attribute packet.
-
#port ⇒ Object
Returns the value of attribute port.
-
#socket ⇒ Object
Returns the value of attribute socket.
Instance Method Summary collapse
-
#initialize ⇒ Listener
constructor
A new instance of Listener.
-
#on_message(&block) ⇒ Object
Sets the handler for all incoming messages.
-
#start(port = 161, interval = 2, max_packet_size = 65_000) ⇒ Object
(also: #listen, #run)
Starts the listener’s run loop.
-
#stop ⇒ Object
(also: #kill)
Stops the listener’s run loop.
Methods included from Debug
Constructor Details
#initialize ⇒ Listener
Returns a new instance of Listener.
12 13 14 15 16 |
# File 'lib/net/snmp/listener.rb', line 12 def initialize # Set by `stop` (probably in an INT signal handler) to # indicate that the agent should stop @killed = false end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
10 11 12 |
# File 'lib/net/snmp/listener.rb', line 10 def callback @callback end |
#packet ⇒ Object
Returns the value of attribute packet.
10 11 12 |
# File 'lib/net/snmp/listener.rb', line 10 def packet @packet end |
#port ⇒ Object
Returns the value of attribute port.
10 11 12 |
# File 'lib/net/snmp/listener.rb', line 10 def port @port end |
#socket ⇒ Object
Returns the value of attribute socket.
10 11 12 |
# File 'lib/net/snmp/listener.rb', line 10 def socket @socket end |
Instance Method Details
#on_message(&block) ⇒ Object
Sets the handler for all incoming messages.
The block provided will be called back for each message as follows:
block[]
Where
-
‘message` is the parsed Net::SNMP::Message object
45 46 47 |
# File 'lib/net/snmp/listener.rb', line 45 def (&block) @callback = block end |
#start(port = 161, interval = 2, max_packet_size = 65_000) ⇒ Object Also known as: listen, run
Starts the listener’s run loop
19 20 21 22 23 24 25 26 |
# File 'lib/net/snmp/listener.rb', line 19 def start(port = 161, interval = 2, max_packet_size = 65_000) @interval = interval @socket = UDPSocket.new @socket.bind("127.0.0.1", port) @max_packet_size = max_packet_size info "Listening on port #{port}" run_loop end |
#stop ⇒ Object Also known as: kill
Stops the listener’s run loop
31 32 33 |
# File 'lib/net/snmp/listener.rb', line 31 def stop @killed = true end |