Class: SNMP4EM::NotificationHandler

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/snmp4em/notification_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#callbacksObject

Returns the value of attribute callbacks.



3
4
5
# File 'lib/snmp4em/notification_handler.rb', line 3

def callbacks
  @callbacks
end

Instance Method Details

#post_initObject



5
6
7
# File 'lib/snmp4em/notification_handler.rb', line 5

def post_init
  @callbacks = []
end

#receive_data(data) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/snmp4em/notification_handler.rb', line 9

def receive_data(data)
  source_port, source_ip = Socket.unpack_sockaddr_in(get_peername)

  begin
    message = SNMP::Message.decode(data)
  rescue Exception => err
    return
  end

  trap = message.pdu

  return unless trap.is_a?(SNMP::SNMPv1_Trap) || trap.is_a?(SNMP::SNMPv2_Trap)

  trap.source_ip = source_ip

  @callbacks.each { |callback| callback.yield(message.pdu) }
end