Module: SNMPUtils

Defined in:
lib/snmputils.rb

Overview

Author:

  • Ted Cok

Class Method Summary collapse

Class Method Details

.get(opts, oids) ⇒ Hash

SNMP get. Return a Hash representation of the values at the input oids

Examples:

snmpvalue = SNMPUtils.get(=> ‘localhost’, ‘SNMPv2-MIB::sysName.0’) # => “1.3.6.1.2.1.1.5.0”=>“medusa”

Parameters:

  • opts (Hash)

    the snmp connection options. Check snmplib for default values

  • oids (Array)

    a list of oids containing the interesting values to retrieve

Returns:



102
103
104
105
106
# File 'lib/snmputils.rb', line 102

def self.get(opts, oids)
  return snmpget(opts,oids).inject({}) do |row, value| 
    row.merge(oid_keyval(value)).merge(name_keyval(value))
  end
end

.walk(opts, oids) ⇒ List

SNMP walk. Return a List representation of the values at the input oids

Examples:

snmpvalues = SNMPUtils.walk(=> ‘localhost’, [‘SNMPv2-MIB::sysORDescr’, ‘SNMPv2-MIB::sysORID’]) # =>

Parameters:

  • opts (Hash)

    the snmp connection options. Check snmplib for default values

  • oids (Array)

    a list of oids containing the interesting snmp columns to retrieve

Returns:

  • (List)

    a List of Hashes describing each row in the table as



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/snmputils.rb', line 115

def self.walk(opts, oids) 
  return snmpwalk(opts, oids).inject([]) do |table, row| 
    rawoids = row.inject({}) do |row_n, value| 
      row_n.merge(oid_keyval(value)).merge(name_keyval(value))
    end
    suffix = rawoids.keys.suffix
    table << rawoids.inject({}) do |row_n, kvpair|
      key, value = kvpair
      row_n.merge(key.sub(/#{suffix}$/, '') => value)
    end
  end
end