snmp-open 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed0ba9db497fbb007a69e702a2ed6321cfde3583
4
- data.tar.gz: 9cbd977f12ae09f800fc0b27aa29fbad04bd0cd9
3
+ metadata.gz: 67cb5790febed285507e8f2872aa8dbb3f025a02
4
+ data.tar.gz: d1504724d8f8572a03624bca255d10757636d40f
5
5
  SHA512:
6
- metadata.gz: 74fb9d39823597e02d95f2029e14391d16851e29f0b20006ab595550e56207dc2f20a1bb3404aa118d25cf9e0a8016542c60be327bf43e45683bad890571aa7a
7
- data.tar.gz: 6b29974a7a28fa197acb75647674f036f7ef5fad733de2f0ae7a5c780005717e17d8cb87fb4855f398768665ccf987432906d6ed6131f69546798725ac98f6f0
6
+ metadata.gz: fff2fcd5e4c3a42d921112c4d0f36e96914b037aee168c73b2981796375597e82e7564352030cd0860043c40f24e61a7e44cd8fe3ae7b7f481b7c60e4d973631
7
+ data.tar.gz: 240aebb9fd9938b76a1d0bc37e56c77d70eb8cd5958a73f952b1766df793c8baabf43a437b0a0207c0c391ea5648018c7948c9ad92572f6b2cabb5555fb67492
@@ -13,20 +13,37 @@ module SNMP
13
13
  # be used to generate a needed file, if the file is unavailable. Controlled
14
14
  # by the `warnings` option.
15
15
  class FileReader
16
+ DEFAULT_WARNING_FORMATTER = lambda { |gen, cmd, oid, outfile|
17
+ "#{gen.cli(cmd, oid)} > #{outfile}"
18
+ }
19
+
16
20
  def initialize(directory, options = {})
17
21
  @directory = directory
18
22
  @warnings = options.delete(:warnings)
19
- @command_generator =
20
- SNMP::Open::CommandReader.new(options.merge(host: '$OPTIONS'))
23
+ @make_directories = options.delete(:make_directories)
24
+ if @warnings && !@warnings.respond_to?(:call)
25
+ @warnings = DEFAULT_WARNING_FORMATTER
26
+ end
27
+ options[:host] ||= '$OPTIONS'
28
+ @command_generator = SNMP::Open::CommandReader.new(options)
21
29
  end
22
30
 
23
31
  def capture(cmd, oid, _options = {})
24
- outfile = File.join(cmd.to_s, oid)
25
- File.read(File.join(@directory, outfile))
32
+ mkdir(@directory, cmd.to_s) if @make_directories
33
+ outfile = File.join(@directory, cmd.to_s, oid)
34
+ File.read(outfile)
26
35
  rescue Errno::ENOENT => err
27
- warn "#{@command_generator.cli(cmd, oid)} > #{outfile}" if @warnings
36
+ if @warnings
37
+ warning = @warnings.call(@command_generator, cmd, oid, outfile)
38
+ warn warning
39
+ end
28
40
  raise err
29
41
  end
42
+
43
+ def mkdir(base, cmd)
44
+ Dir.mkdir(base) unless File.exist?(base)
45
+ Dir.mkdir(File.join(base, cmd)) unless File.exist?(File.join(base, cmd))
46
+ end
30
47
  end # class FileReader
31
48
  end # class Open
32
49
  end # module SNMP
@@ -1,5 +1,5 @@
1
1
  module SNMP
2
- module Open
3
- VERSION = '0.4.0'.freeze
2
+ class Open
3
+ VERSION = '0.5.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snmp-open
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Miller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-27 00:00:00.000000000 Z
11
+ date: 2018-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.6.11
117
+ rubygems_version: 2.5.2.2
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Wrapper for command-line SNMP utilities