Class: NetCrawl::SNMP
- Inherits:
-
Object
- Object
- NetCrawl::SNMP
- Defined in:
- lib/netcrawl/snmp.rb
Defined Under Namespace
Classes: NoResponse, VBHash
Instance Method Summary collapse
-
#bulkwalk(root) ⇒ Array(SNMP::VarBind)
Bulkwalk everything below root oid.
-
#close ⇒ void
Closes the SNMP connection.
-
#get(oid) ⇒ SNMP::VarBind
Gets one oid, return value.
-
#hashwalk(oid) {|VBHash| ... } ⇒ Hash
bulkwalks oid and returns hash with oid as key.
-
#mget(oids) ⇒ SNMP::VarBindList
Get multiple oids, return array of values.
Instance Method Details
#bulkwalk(root) ⇒ Array(SNMP::VarBind)
Bulkwalk everything below root oid
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 |
#close ⇒ void
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
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
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
21 22 23 |
# File 'lib/netcrawl/snmp.rb', line 21 def mget oids snmp :get, oids end |