Class: NetCrawl::SNMP

Inherits:
Object
  • Object
show all
Defined in:
lib/netcrawl/snmp.rb

Defined Under Namespace

Classes: NoResponse, VBHash

Instance Method Summary collapse

Instance Method Details

#bulkwalk(root) ⇒ Array(SNMP::VarBind)

Bulkwalk everything below root oid

Parameters:

  • root (String)

    oid to start from

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

#closevoid

This method returns an undefined value.

Closes the SNMP connection



7
8
9
# File 'lib/netcrawl/snmp.rb', line 7

def close
  @snmp.close
end

#get(oid) ⇒ SNMP::VarBind

Gets one oid, return value

Parameters:

  • oid (String)

    to get

Returns:



14
15
16
# File 'lib/netcrawl/snmp.rb', line 14

def get oid
  mget([oid]).first
end

#hashwalk(oid) {|VBHash| ... } ⇒ Hash

bulkwalks oid and returns hash with oid as key

Parameters:

  • oid (String)

    root oid to walk

Yields:

  • (VBHash)

    hash containing oids found

Returns:

  • (Hash)

    resulting hash



46
47
48
49
50
51
52
53
54
# 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) ⇒ SNMP::VarBindList

Get multiple oids, return array of values

Parameters:

  • oids (Array(String))

    to get

Returns:

  • (SNMP::VarBindList)


21
22
23
# File 'lib/netcrawl/snmp.rb', line 21

def mget oids
  snmp :get, oids
end