Class: SNMPTableViewer::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/snmp_table_viewer/fetcher.rb

Overview

Class to fetch the information from an SNMP host.

Class Method Summary collapse

Class Method Details

.from_snmp(base_oid:, **snmp_options) ⇒ Array<Array<#to_s>>

Fetch the data using SNMP.

Parameters:

  • base_oid (String)

    The OID to start the SNMP walk from

  • **snmp_options (Hash)

    The options to pass to NETSNMP::Client.new

Returns:

  • (Array<Array<#to_s>>)

    A two dimensional array containing objects in each cell (at 'address' data[col])


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/snmp_table_viewer/fetcher.rb', line 10

def self.from_snmp(base_oid:, **snmp_options)
  data = Array.new
  NETSNMP::Client.new(snmp_options) do |manager|
    manager.walk(oid: base_oid).each do |oid, value|
      col, row = oid.split('.')[-2..-1].map{ |i| i.to_i - 1}
      data[row] ||= []
      data[row][col] = value
    end
  end
  data
end