Class: NetCrawl::SNMP::VBHash

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

Overview

Hash with some helper methods to easier work with VarBinds

Instance Method Summary collapse

Instance Method Details

#[](*args) ⇒ SNMP::VarBind

Returns matching element.

Parameters:

  • key (Array[String, Array))

    which you want, multiple arguments compiled into single key

Returns:



105
106
107
# File 'lib/netcrawl/snmp.rb', line 105

def [] *args
  org_bracket arg_to_oid(*args)
end

#by_oid(*oid) ⇒ VBHash

Returns oids which start with param oid.

Parameters:

  • oid (Array(Strin, Array))

    root oid under which you want all oids below it

Returns:

  • (VBHash)

    oids which start with param oid



80
81
82
83
84
85
86
87
# File 'lib/netcrawl/snmp.rb', line 80

def by_oid *oid
  oid = arg_to_oid(*oid)
  hash = select do |key, value|
    key[0..oid.size-1] == oid
  end
  newhash = VBHash.new
  newhash.merge hash
end

#by_partial(*args) ⇒ SNMP::VarBind

Returns matching element.

Parameters:

  • args (Array(String, Array))

    partial match 3.4.6 would match to 1.2.3.4.6.7.8

Returns:



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/netcrawl/snmp.rb', line 91

def by_partial *args
  oid = arg_to_oid(*args)
  got = nil
  keys.each do |key|
    if key.each_cons(oid.size).find{|e|e==oid}
      got = self[key]
      break
    end
  end
  got
end

#org_bracketObject



75
# File 'lib/netcrawl/snmp.rb', line 75

alias :org_bracket :[]