Class: Boris::SNMPConnector

Inherits:
Connector show all
Defined in:
lib/boris/connectors/snmp.rb

Instance Attribute Summary

Attributes inherited from Connector

#connected, #host, #options, #reconnectable

Attributes included from Lumberjack

#logger

Instance Method Summary (collapse)

Methods inherited from Connector

#connected?

Methods included from Lumberjack

#debug, #error, #fatal, #info, #warn

Constructor Details

- (SNMPConnector) initialize(host, cred, options, logger = nil)

A new instance of SNMPConnector



5
6
7
8
9
10
11
# File 'lib/boris/connectors/snmp.rb', line 5

def initialize(host, cred, options, logger=nil)
  super(host, cred, options, logger)
  @snmp_options = options[:snmp_options].merge(:host=>@host, :version=>:SNMPv1, :community=>@user)

  #snmp connections are always reconnectable
  @reconnectable = true
end

Instance Method Details

- (Object) disconnect



13
14
15
16
17
# File 'lib/boris/connectors/snmp.rb', line 13

def disconnect
  super
  @transport = nil
  debug 'connections closed'
end

- (Object) establish_connection



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/boris/connectors/snmp.rb', line 19

def establish_connection
  super

  begin
    @transport = SNMP::Manager.new(@snmp_options)
    value_at('sysDescr')
    debug 'connection established'
    @connected = true
  rescue SNMP::RequestTimeout
    warn 'connection failed (connection timeout)'
  rescue => error
    warn "connection failed (#{error.message})"
  end

  return self
end

- (Object) value_at(request)



36
37
38
# File 'lib/boris/connectors/snmp.rb', line 36

def value_at(request)
  values_at(request, 1)[0]
end

- (Object) values_at(request, limit = nil)



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/boris/connectors/snmp.rb', line 40

def values_at(request, limit=nil)
  super(request, limit)

  return_data = []

  @transport.walk(request) do |row|
    row.each {|item| return_data << {:name=>item.name.to_s, :value=>item.value}}
  end

  info "#{return_data.size} row(s) returned"

  limit = return_data.size if limit.nil?

  return_data[0..limit]
end