snmp-open 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +24 -0
- data/.rubocop.yml +2 -0
- data/lib/snmp/open/command_reader.rb +26 -2
- data/lib/snmp/open/options.rb +2 -4
- data/lib/snmp/open/parser.rb +15 -8
- data/lib/snmp/open/version.rb +1 -1
- data/snmp-open.gemspec +3 -3
- metadata +13 -13
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1362f32d8e43b509be4884b392c43689b9cba48c2e2d6f63c4912e645ba6fcc9
|
4
|
+
data.tar.gz: d751cce9e00204ae0b0d131120338ce3b7beaf1bbfb2e71f114c60f8c9bfdfa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51603c2ee2b8d5077be2dcc8f26b74ad174d09a31fe6b6879343d98b33bba5f30f6246cf2ac3999f3a3aa46fda3b5cf7f849310016de5725cbdd0574741af99c
|
7
|
+
data.tar.gz: 2670576c9373c22e74e5bc7a118317ffdefb33d685ef654236e1ec5f369f9ac772d619ff7cfba3e8532ba52a5fc3b0d52bc67439cbeb96d84a08d6cc36f40819
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
os: [ubuntu-latest, macos-latest]
|
15
|
+
ruby: [2.4, 2.5, 2.6, 2.7, jruby, truffleruby]
|
16
|
+
runs-on: ${{ matrix.os }}
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v2
|
19
|
+
- uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
bundler-cache: true
|
23
|
+
- name: Run tests
|
24
|
+
run: bundle exec rake
|
data/.rubocop.yml
ADDED
@@ -30,8 +30,7 @@ module SNMP
|
|
30
30
|
else
|
31
31
|
Open3.capture3(cli(cmd, oid, options))
|
32
32
|
end
|
33
|
-
|
34
|
-
raise CommandError, err.chomp unless err.empty?
|
33
|
+
raise_capture_errors(err)
|
35
34
|
out
|
36
35
|
end
|
37
36
|
|
@@ -42,6 +41,7 @@ module SNMP
|
|
42
41
|
[
|
43
42
|
command,
|
44
43
|
*options.map { |k, v| "#{k}#{v}" },
|
44
|
+
*oid_options(id),
|
45
45
|
*@host_options.map { |k, v| "#{k}#{v}" },
|
46
46
|
*@command_options.fetch(command, {}).map { |k, v| "#{k}#{v}" },
|
47
47
|
*id
|
@@ -50,6 +50,19 @@ module SNMP
|
|
50
50
|
|
51
51
|
private
|
52
52
|
|
53
|
+
def raise_capture_errors(err)
|
54
|
+
case err
|
55
|
+
when /^Cannot find module \(([^)]+)\)/
|
56
|
+
raise UnknownMIBError, "Unknown MIB: #{Regexp.last_match(1)}"
|
57
|
+
when /^(\S+): Unknown Object Identifier$/
|
58
|
+
raise UnknownOIDError, "Unknown OID: #{Regexp.last_match(1)}"
|
59
|
+
when /^timeout/i
|
60
|
+
raise CommandTimeoutError, err.chomp
|
61
|
+
when /./
|
62
|
+
raise CommandError, err.chomp
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
53
66
|
def merge_options(options = {})
|
54
67
|
options.each_pair.with_object({}) do |(key, value), opts|
|
55
68
|
if Options::MAP.key?(key)
|
@@ -63,6 +76,15 @@ module SNMP
|
|
63
76
|
end
|
64
77
|
end
|
65
78
|
|
79
|
+
# if the request OID is all-numeric, force numeric OID in the output
|
80
|
+
def oid_options(id)
|
81
|
+
if id =~ /[^0-9.]/
|
82
|
+
[]
|
83
|
+
else
|
84
|
+
['-On']
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
66
88
|
def normalize_command(command)
|
67
89
|
case command
|
68
90
|
when Symbol then "snmp#{command}"
|
@@ -100,5 +122,7 @@ module SNMP
|
|
100
122
|
|
101
123
|
class CommandError < RuntimeError; end
|
102
124
|
class CommandTimeoutError < CommandError; end
|
125
|
+
class UnknownMIBError < CommandError; end
|
126
|
+
class UnknownOIDError < CommandError; end
|
103
127
|
end # class Open
|
104
128
|
end # module SNMP
|
data/lib/snmp/open/options.rb
CHANGED
@@ -24,12 +24,10 @@ module SNMP
|
|
24
24
|
host: nil
|
25
25
|
}.freeze
|
26
26
|
|
27
|
-
# On some systems, SNMP command outputs will include symbolic
|
28
|
-
#
|
29
|
-
# so disable them.
|
27
|
+
# On some systems, SNMP command outputs will include symbolic values
|
28
|
+
# and/or value units. The parser doesn't support these, so disable them.
|
30
29
|
REQUIRED_BY_PARSER = {
|
31
30
|
'-Oe' => nil,
|
32
|
-
'-On' => nil,
|
33
31
|
'-OU' => nil
|
34
32
|
}.freeze
|
35
33
|
|
data/lib/snmp/open/parser.rb
CHANGED
@@ -14,6 +14,7 @@ module SNMP
|
|
14
14
|
# convert SNMP command output into arrays
|
15
15
|
class Parser
|
16
16
|
include SNMP::Open::Parser::Constants
|
17
|
+
OID_RE = Regexp.union(/\S+-MIB::\S+/, /[0-9\.]+/)
|
17
18
|
|
18
19
|
def initialize(oids)
|
19
20
|
@oids = oids
|
@@ -21,12 +22,8 @@ module SNMP
|
|
21
22
|
|
22
23
|
def parse(texts)
|
23
24
|
columns = texts.map do |text|
|
24
|
-
|
25
|
-
|
26
|
-
.gsub(/^([0-9\.]+) = (Opaque|STRING): ((?!")[^\n]*)\n/,
|
27
|
-
%(\\1 = \\2: "\\3"\n))
|
28
|
-
.gsub(Static::ANY_MESSAGE, Static::QUOTED_MESSAGES)
|
29
|
-
.shellsplit
|
25
|
+
clean = clean_input_text(text)
|
26
|
+
tokenized = clean.shellsplit
|
30
27
|
parse_tokens(tokenized)
|
31
28
|
end
|
32
29
|
|
@@ -47,6 +44,16 @@ module SNMP
|
|
47
44
|
end
|
48
45
|
end
|
49
46
|
|
47
|
+
def clean_input_text(text)
|
48
|
+
text
|
49
|
+
.gsub(/\r\n|\n\r|\r/, "\n")
|
50
|
+
.gsub(/^(#{OID_RE})\s*=\s*(Opaque|STRING):\s*\n/,
|
51
|
+
%(\\1 = \\2: ""\n))
|
52
|
+
.gsub(/^(#{OID_RE}) = (Opaque|STRING): ((?!")[^\n]*)\n/,
|
53
|
+
%(\\1 = \\2: "\\3"\n))
|
54
|
+
.gsub(Static::ANY_MESSAGE, Static::QUOTED_MESSAGES)
|
55
|
+
end
|
56
|
+
|
50
57
|
def index_using_first_oid(value)
|
51
58
|
base = @oids.first
|
52
59
|
|
@@ -69,12 +76,12 @@ module SNMP
|
|
69
76
|
|
70
77
|
objects
|
71
78
|
rescue StopIteration
|
72
|
-
|
79
|
+
objects
|
73
80
|
end
|
74
81
|
|
75
82
|
def parse_next_object(tokens)
|
76
83
|
oid = tokens.next.sub(/\A\./, '')
|
77
|
-
raise "Parse error at #{oid}" unless oid =~
|
84
|
+
raise "Parse error at #{oid}" unless oid =~ OID_RE
|
78
85
|
equals = tokens.next
|
79
86
|
raise "Parse error after #{oid}" unless equals == '='
|
80
87
|
type, value = parse_type(tokens)
|
data/lib/snmp/open/version.rb
CHANGED
data/snmp-open.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib = File.expand_path('
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require 'snmp/open/version'
|
4
4
|
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency 'bundler', '~>
|
22
|
-
spec.add_development_dependency 'rake', '~>
|
21
|
+
spec.add_development_dependency 'bundler', '~> 2.2'
|
22
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
24
|
spec.add_development_dependency 'snmp'
|
25
25
|
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
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Miller
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,16 +66,17 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description:
|
70
70
|
email:
|
71
71
|
- bmiller@rackspace.com
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ".github/workflows/ruby.yml"
|
76
77
|
- ".gitignore"
|
77
78
|
- ".rspec"
|
78
|
-
- ".
|
79
|
+
- ".rubocop.yml"
|
79
80
|
- CODE_OF_CONDUCT.md
|
80
81
|
- Gemfile
|
81
82
|
- Guardfile
|
@@ -98,7 +99,7 @@ files:
|
|
98
99
|
homepage: https://github.com/bjmllr/snmp-open
|
99
100
|
licenses: []
|
100
101
|
metadata: {}
|
101
|
-
post_install_message:
|
102
|
+
post_install_message:
|
102
103
|
rdoc_options: []
|
103
104
|
require_paths:
|
104
105
|
- lib
|
@@ -113,9 +114,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
114
|
- !ruby/object:Gem::Version
|
114
115
|
version: '0'
|
115
116
|
requirements: []
|
116
|
-
|
117
|
-
|
118
|
-
signing_key:
|
117
|
+
rubygems_version: 3.1.2
|
118
|
+
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Wrapper for command-line SNMP utilities
|
121
121
|
test_files: []
|