class NetCrawl::SNMP
Public Class Methods
new(host, community=CFG.snmp.community, timeout=CFG.snmp.timeout, retries=CFG.snmp.retries)
click to toggle source
# File lib/netcrawl/snmp.rb, line 58 def initialize host, community=CFG.snmp.community, timeout=CFG.snmp.timeout, retries=CFG.snmp.retries @host = host @snmp = ::SNMP::Manager.new :Host=>@host, :Community=>community, :Timeout=>timeout, :Retries=>retries, :MibModules=>[] end
Public Instance Methods
bulkwalk(root)
click to toggle source
Bulkwalk everything below root oid @param [String] root oid to start from @return [Array(SNMP::VarBind
)]
# File lib/netcrawl/snmp.rb, line 28 def bulkwalk root last, oid, results = false, root.dup, [] root = root.split('.').map{|chr|chr.to_i} while not last vbs = snmp(:get_bulk, 0, CFG.snmp.bulkrows, oid).varbind_list vbs.each do |vb| oid = vb.oid (last = true; break) if not oid[0..root.size-1] == root results.push vb end end results end
close()
click to toggle source
Closes the SNMP
connection @return [void]
# File lib/netcrawl/snmp.rb, line 7 def close @snmp.close end
get(oid)
click to toggle source
Gets one oid, return value @param [String] oid to get @return [SNMP::VarBind]
# File lib/netcrawl/snmp.rb, line 14 def get oid mget([oid]).first end
hashwalk(oid, &block)
click to toggle source
bulkwalks oid and returns hash with oid as key @param [String] oid root oid to walk @yield [VBHash] hash containing oids found @return [Hash] resulting hash
# File lib/netcrawl/snmp.rb, line 46 def hashwalk oid, &block hash = VBHash.new bulkwalk(oid).each do |vb| #value, key = block.call(vb) key ||= vb.oid hash[key] = vb end hash end
mget(oids)
click to toggle source
Get multiple oids, return array of values @param [Array(String)] oids to get @return [SNMP::VarBindList]
# File lib/netcrawl/snmp.rb, line 21 def mget oids snmp :get, oids end
Private Instance Methods
snmp(cmd, *args)
click to toggle source
# File lib/netcrawl/snmp.rb, line 65 def snmp cmd, *args @snmp.send cmd, *args rescue ::SNMP::RequestTimeout, Errno::EACCES => error msg = "host '#{@host}' raised '#{error.class}' with message '#{error.message}' for method '#{cmd}' with args '#{args}'" Log.warn msg raise NoResponse, msg end