Class: Genesis::Snmp::Server

Inherits:
EM::Connection
  • Object
show all
Includes:
Protocol, Genesis::Server
Defined in:
lib/genesis/protocol/snmp/server.rb

Overview

Implement an SNMP trap handling server

Instance Attribute Summary collapse

Attributes included from Genesis::Server

#channel, #handle_routes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Protocol

included

Methods included from Genesis::Server

included

Instance Attribute Details

#communityObject

Returns the value of attribute community.



13
14
15
# File 'lib/genesis/protocol/snmp/server.rb', line 13

def community
  @community
end

#mibObject

Returns the value of attribute mib.



13
14
15
# File 'lib/genesis/protocol/snmp/server.rb', line 13

def mib
  @mib
end

Class Method Details

.load_modules(module_list, mib_dir) ⇒ Object



28
29
30
31
32
# File 'lib/genesis/protocol/snmp/server.rb', line 28

def self.load_modules(module_list, mib_dir)
  mib = SNMP::MIB.new
  module_list.each { |m| mib.load_module(m, mib_dir) }
  mib
end

.start_serverObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/genesis/protocol/snmp/server.rb', line 15

def self.start_server
  commstr = @args[:community] || ''
  mib_dir = @args[:mib_dir] || SNMP::MIB::DEFAULT_MIB_PATH
  mib_mods = @args[:mib_mods] || SNMP::Options.default_modules
  mib = load_modules(mib_mods, mib_dir)
  EM.open_datagram_socket('0.0.0.0', @port, self) do |conn|
    conn.mib = mib
    conn.community = commstr
    conn.channel = @channel
    conn.handle_routes = @handle_routes
  end
end

Instance Method Details

#receive_data(data) ⇒ Object



34
35
36
37
38
# File 'lib/genesis/protocol/snmp/server.rb', line 34

def receive_data(data)
  snmp_trap = handle_trap(data)
  @channel << snmp_trap
  route_trap(snmp_trap)
end