Class: Netdisco::SNMP::VBHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/netdisco/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:



122
123
124
# File 'lib/netdisco/snmp.rb', line 122

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

#by_oid(*oid) ⇒ VBHash

精确查询

Parameters:

  • oid (Array(Strin, Array))

    root oid under which you want all oids below it

Returns:

  • (VBHash)

    oids which start with param oid



95
96
97
98
99
100
101
102
# File 'lib/netdisco/snmp.rb', line 95

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

#by_partial(*args) ⇒ SNMP::VarBind?

模糊匹配

Parameters:

  • args (Array(String, Array))

    partial match 3.4.6 would match to 1.2.3.4.6.7.8

Returns:



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/netdisco/snmp.rb', line 107

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

#org_bracketObject



89
# File 'lib/netdisco/snmp.rb', line 89

alias :org_bracket :[]