Class: SNMP::Manager
- Inherits:
-
Object
- Object
- SNMP::Manager
- Defined in:
- rlib/snmp_override.rb
Overview
Manager class from snmplib
Class Method Summary (collapse)
-
+ (Object) snmp_walk(hostname, community, ifTable_columns)
Run an SNMP query to retrieve the OID or OIDS passed in.
Instance Method Summary (collapse)
-
- (Object) walk(object_list, index_column = 0)
Overrides walk in the standard SNMP snmp.rb library.
Class Method Details
+ (Object) snmp_walk(hostname, community, ifTable_columns)
Run an SNMP query to retrieve the OID or OIDS passed in.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'rlib/snmp_override.rb', line 42 def self.snmp_walk(hostname, community, ifTable_columns) begin SNMP::Manager.open(:Host => hostname, :Community => "#{community}", :Version => :SNMPv1) do |manager| manager.walk(ifTable_columns) do |row| row.each do |vb| oid = vb.name.to_s.split('.') yield [oid, vb.value.to_s] end end end rescue SignalException => #We might get an OS level signal. If so, we need to stop $stderr.print "#{Signal} #{}\n" exit -1 rescue Exception => #Should be a more refined Exception list! $stderr.print "(#{hostname}, #{community}, #{ifTable_columns}) Error: #{@name}: #{}\n" end end |
Instance Method Details
- (Object) walk(object_list, index_column = 0)
Overrides walk in the standard SNMP snmp.rb library. Walks a list of ObjectId or VarBind objects using get_next until the response to the first OID in the list reaches the end of its MIB subtree.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'rlib/snmp_override.rb', line 14 def walk(object_list, index_column=0) raise ArgumentError, "expected a block to be given" unless block_given? vb_list = @mib.varbind_list(object_list, :NullValue) raise ArgumentError, "index_column is past end of varbind list" if index_column >= vb_list.length is_single_vb = object_list.respond_to?(:to_str) || object_list.respond_to?(:to_varbind) start_list = vb_list start_oid = vb_list[index_column].name last_oid = start_oid loop do vb_list = get_next(vb_list).vb_list index_vb = vb_list[index_column] break if EndOfMibView == index_vb.value stop_oid = index_vb.name break unless stop_oid.subtree_of?(start_oid) last_oid = stop_oid if is_single_vb yield index_vb else vb_list = validate_row(vb_list, start_list, index_column) yield vb_list end end end |