Sha256: 503f1d039ceb41417d263c10979534779fd2eb7571a843928f15d26f6e191ac7
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 KB
Contents
require 'snmpjr/wrappers/util' require 'snmpjr/wrappers/smi' require 'snmpjr/session' class Snmpjr class Walker def initialize opts = {} @target = opts.fetch(:target) @session = Snmpjr::Session.new @tree_utils = Snmpjr::Wrappers::Util::TreeUtils.new(@session.snmp, pdu_factory) end def walk oid begin @session.start response = @tree_utils.getSubtree(@target, oid) rescue Exception => e raise RuntimeError.new e.to_s ensure @session.close end response.flat_map {|response_event| check_event_for_errors(response_event) extract_variable_bindings(response_event.variable_bindings) } end private def extract_variable_bindings variable_bindings variable_bindings.flat_map {|vb| Snmpjr::Response.new(oid: vb.oid.to_s, value: vb.variable.to_s) } end def check_event_for_errors event if event.is_error? if event.error_message == 'Request timed out.' raise Snmpjr::TargetTimeoutError.new('Request timed out') else raise RuntimeError.new(event.error_message) end end end def pdu_factory Snmpjr::Wrappers::Util::DefaultPDUFactory.new end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
snmpjr-0.2.2-java | lib/snmpjr/walker.rb |