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 +4 -4
- data/lib/snmp/open/file_reader.rb +22 -5
- data/lib/snmp/open/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67cb5790febed285507e8f2872aa8dbb3f025a02
|
4
|
+
data.tar.gz: d1504724d8f8572a03624bca255d10757636d40f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
@
|
20
|
-
|
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
|
-
|
25
|
-
File.
|
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
|
-
|
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
|
data/lib/snmp/open/version.rb
CHANGED
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
|
+
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:
|
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.
|
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
|