Class: SNMP4EM::NotificationManager

Inherits:
Object
  • Object
show all
Defined in:
lib/snmp4em/notification_manager.rb

Overview

Provides access to receive SNMP traps (SNMPv1) and notifications (SNMPv2)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ NotificationManager

Creates a new object to communicate with SNMP agents. Optionally pass in the following parameters:

  • host - IP/hostname of local interface on which to listen (default: 127.0.0.1)

  • port - UDP port on which to listen (default: 162)



9
10
11
12
13
14
# File 'lib/snmp4em/notification_manager.rb', line 9

def initialize(args = {})
  @host    = args[:host]      || "127.0.0.1"
  @port    = args[:port]      || 162

  @socket = EM::open_datagram_socket(@host, @port, NotificationHandler)
end

Instance Attribute Details

#community_roObject (readonly)

Returns the value of attribute community_ro.



4
5
6
# File 'lib/snmp4em/notification_manager.rb', line 4

def community_ro
  @community_ro
end

#community_rwObject (readonly)

Returns the value of attribute community_rw.



4
5
6
# File 'lib/snmp4em/notification_manager.rb', line 4

def community_rw
  @community_rw
end

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/snmp4em/notification_manager.rb', line 4

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



4
5
6
# File 'lib/snmp4em/notification_manager.rb', line 4

def port
  @port
end

#retriesObject (readonly)

Returns the value of attribute retries.



4
5
6
# File 'lib/snmp4em/notification_manager.rb', line 4

def retries
  @retries
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



4
5
6
# File 'lib/snmp4em/notification_manager.rb', line 4

def timeout
  @timeout
end

#versionObject (readonly)

Returns the value of attribute version.



4
5
6
# File 'lib/snmp4em/notification_manager.rb', line 4

def version
  @version
end

Instance Method Details

#on_trap(&block) ⇒ Object

Register a callback that is upon reception of a trap/notification. Multiple callbacks can be registered. Each will be passed the trap/notification object. It is important to determine whether it is a SNMP::SNMPv1_Trap or SNMP::SNMPv2_Trap, as each behaves slightly differently.



19
20
21
# File 'lib/snmp4em/notification_manager.rb', line 19

def on_trap &block
  @socket.callbacks << block
end