lib/snmp/open.rb in snmp-open-0.6.0 vs lib/snmp/open.rb in snmp-open-0.6.1

- old
+ new

@@ -25,19 +25,21 @@ def initialize(options = {}) @reader = options[:reader] || CommandReader.new(options) end # Perform an SNMP get using the "snmpget" command and parse the output - def get(oids) + def get(oids, &block) return enum_for(:get, oids) unless block_given? + texts = oids.map { |oid| reader.capture(:get, oid) } - Parser.new(oids).parse(texts).fetch(0, []).each { |arg| yield(arg) } + Parser.new(oids).parse(texts).fetch(0, []).each(&block) end # Perform an SNMP walk using the "snmpwalk" or "snmpbulkwalk" commands and # parse the output def walk(oids, **kwargs) return enum_for(:walk, oids, **kwargs) unless block_given? + bulk = kwargs.fetch(:bulk, true) options = walk_options(bulk, **kwargs) cmd = bulk ? :bulkwalk : :walk texts = oids.map { |oid| reader.capture(cmd, oid, options) } Parser.new(oids).parse(texts).each { |*args| yield(*args) }