Class: SNMP::Open::FileReader
- Inherits:
-
Object
- Object
- SNMP::Open::FileReader
- Defined in:
- lib/snmp/open/file_reader.rb
Overview
Test data source for SNMP::Open that reads from the filesystem instead of running SNMP commands. Expects a ‘walk’ directory to be present if #walk will be used, and a ‘get’ directory if #get will be used. Within each directory, files named according to the numeric OIDs to be used are expected to be present, containing the output of an snmpwalk or snmpget run over the given OID.
Produces warnings describing an snmpbulkwalk or snmpget command that could be used to generate a needed file, if the file is unavailable. Controlled by the ‘warnings` option.
Instance Method Summary collapse
- #capture(cmd, oid, _options = {}) ⇒ Object
-
#initialize(directory, options = {}) ⇒ FileReader
constructor
A new instance of FileReader.
Constructor Details
#initialize(directory, options = {}) ⇒ FileReader
Returns a new instance of FileReader.
16 17 18 19 20 21 |
# File 'lib/snmp/open/file_reader.rb', line 16 def initialize(directory, = {}) @directory = directory @warnings = .delete(:warnings) @command_generator = SNMP::Open::CommandReader.new(.merge(host: '$OPTIONS')) end |
Instance Method Details
#capture(cmd, oid, _options = {}) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/snmp/open/file_reader.rb', line 23 def capture(cmd, oid, = {}) outfile = File.join(cmd.to_s, oid) File.read(File.join(@directory, outfile)) rescue Errno::ENOENT => err warn "#{@command_generator.cli(cmd, oid)} > #{outfile}" if @warnings raise err end |