Method: Net::SNMP::Session#get_table

Defined in:
lib/net/snmp/session.rb

#get_table(table_name, options = {}) ⇒ Object

XXX This needs work. Need to use getbulk for speed, guess maxrepeaters, etc.. Also need to figure out how we can tell column names from something like ifTable instead of ifEntry. Needs to handle errors, there are probably offset problems in cases of bad data, and various other problems. Also need to add async support. Maybe return a hash with index as key?



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/net/snmp/session.rb', line 395

def get_table(table_name, options = {})
  column_names = options[:columns] || MIB::Node.get_node(table_name).children.collect {|c| c.label }
  results = []

#        repeat_count = if @version.to_s == '1' || options[:no_getbulk]
#            1
#          elsif options[:repeat_count]
#            options[:repeat_count]
#          else
#            (1000 / 36 / (column_names.size + 1)).to_i
#        end
#
#        res = if @version.to_s != '1' && !options[:no_getbulk]
#          get_bulk(column_names, :max_repetitions => repeat_count)
#        else
#          get_next(column_names)
#        end


  first_result = get_next(column_names)
  oidlist = []
  good_column_names = []
  row = {}

  first_result.varbinds.each_with_index do |vb, idx|
    oid = vb.oid
    if oid.label[0..column_names[idx].length - 1] == column_names[idx]
      oidlist << oid.label
      good_column_names << column_names[idx]
      row[column_names[idx]] = vb.value
    end
  end
  results << row

  catch :break_main_loop do
    while(result = get_next(oidlist))
      oidlist = []
      row = {}
      result.varbinds.each_with_index do |vb, idx|
        #puts "got #{vb.oid.label} #{vb.value.inspect}, type = #{vb.object_type}"
        row[good_column_names[idx]] = vb.value
        oidlist << vb.oid.label
        if vb.oid.label[0..good_column_names[idx].length - 1] != good_column_names[idx]
          throw :break_main_loop
        end
      end
      results << row
    end
  end
  results
end