snmp-open 0.6.0 → 0.6.1

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
  SHA256:
3
- metadata.gz: 1362f32d8e43b509be4884b392c43689b9cba48c2e2d6f63c4912e645ba6fcc9
4
- data.tar.gz: d751cce9e00204ae0b0d131120338ce3b7beaf1bbfb2e71f114c60f8c9bfdfa8
3
+ metadata.gz: 2778b6bac09136b98ff5bfcdf5313f470d8468d556353f4e5466479624291383
4
+ data.tar.gz: b2f2a13ad5ad75e79116e33e63f2462e768b5850887180e9b94e1ff369c17bac
5
5
  SHA512:
6
- metadata.gz: 51603c2ee2b8d5077be2dcc8f26b74ad174d09a31fe6b6879343d98b33bba5f30f6246cf2ac3999f3a3aa46fda3b5cf7f849310016de5725cbdd0574741af99c
7
- data.tar.gz: 2670576c9373c22e74e5bc7a118317ffdefb33d685ef654236e1ec5f369f9ac772d619ff7cfba3e8532ba52a5fc3b0d52bc67439cbeb96d84a08d6cc36f40819
6
+ metadata.gz: f61f7cbd63437b97d260e8bee251cfe45ca02a706564de5ae293859c5ab8feb80c253fdd67ba0fe93fd78b1df49370adca9a12cecac6b545456efdeccf8f4553
7
+ data.tar.gz: 816aba2a56ded47b4dadbe0fee21e339bfa423bd76bc6a4e1a2e5979dfc2048fa62124c23447e4d7144d6da06f153b48b04ff3374b5647fd05d0d94a9e8d8ba7
@@ -1,2 +1,62 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
1
4
  Style/CommentedKeyword:
2
5
  Enabled: false
6
+
7
+ Lint/MissingSuper:
8
+ Exclude:
9
+ - 'lib/snmp/open/parser/value_parser.rb'
10
+
11
+ Metrics/ClassLength:
12
+ Exclude:
13
+ - 'lib/snmp/open/parser.rb'
14
+
15
+ Style/AccessModifierDeclarations: {Enabled: false}
16
+ Style/IfUnlessModifier: {Enabled: false}
17
+ Style/FrozenStringLiteralComment: {Enabled: false}
18
+
19
+ Layout/SpaceBeforeBrackets: # (new in 1.7)
20
+ Enabled: true
21
+ Lint/AmbiguousAssignment: # (new in 1.7)
22
+ Enabled: true
23
+ Lint/DeprecatedConstants: # (new in 1.8)
24
+ Enabled: true
25
+ Lint/DuplicateBranch: # (new in 1.3)
26
+ Enabled: true
27
+ Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
28
+ Enabled: true
29
+ Lint/EmptyBlock: # (new in 1.1)
30
+ Enabled: true
31
+ Lint/EmptyClass: # (new in 1.3)
32
+ Enabled: true
33
+ Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
34
+ Enabled: true
35
+ Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
36
+ Enabled: true
37
+ Lint/RedundantDirGlobSort: # (new in 1.8)
38
+ Enabled: true
39
+ Lint/ToEnumArguments: # (new in 1.1)
40
+ Enabled: true
41
+ Lint/UnexpectedBlockArity: # (new in 1.5)
42
+ Enabled: true
43
+ Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
44
+ Enabled: true
45
+ Style/ArgumentsForwarding: # (new in 1.1)
46
+ Enabled: true
47
+ Style/CollectionCompact: # (new in 1.2)
48
+ Enabled: true
49
+ Style/DocumentDynamicEvalDefinition: # (new in 1.1)
50
+ Enabled: true
51
+ Style/EndlessMethod: # (new in 1.8)
52
+ Enabled: true
53
+ Style/HashExcept: # (new in 1.7)
54
+ Enabled: true
55
+ Style/NegatedIfElseCondition: # (new in 1.2)
56
+ Enabled: true
57
+ Style/NilLambda: # (new in 1.3)
58
+ Enabled: true
59
+ Style/RedundantArgument: # (new in 1.4)
60
+ Enabled: true
61
+ Style/SwapValues: # (new in 1.1)
62
+ Enabled: true
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ group :guard do
5
5
  gem 'guard'
6
6
  gem 'guard-rspec'
7
7
  gem 'guard-rubocop'
8
+ gem 'rubocop', '~>1.0'
8
9
  end
@@ -27,16 +27,18 @@ module SNMP
27
27
  end
28
28
 
29
29
  # Perform an SNMP get using the "snmpget" command and parse the output
30
- def get(oids)
30
+ def get(oids, &block)
31
31
  return enum_for(:get, oids) unless block_given?
32
+
32
33
  texts = oids.map { |oid| reader.capture(:get, oid) }
33
- Parser.new(oids).parse(texts).fetch(0, []).each { |arg| yield(arg) }
34
+ Parser.new(oids).parse(texts).fetch(0, []).each(&block)
34
35
  end
35
36
 
36
37
  # Perform an SNMP walk using the "snmpwalk" or "snmpbulkwalk" commands and
37
38
  # parse the output
38
39
  def walk(oids, **kwargs)
39
40
  return enum_for(:walk, oids, **kwargs) unless block_given?
41
+
40
42
  bulk = kwargs.fetch(:bulk, true)
41
43
  options = walk_options(bulk, **kwargs)
42
44
  cmd = bulk ? :bulkwalk : :walk
@@ -121,8 +121,11 @@ module SNMP
121
121
  end # class CommandReader
122
122
 
123
123
  class CommandError < RuntimeError; end
124
+
124
125
  class CommandTimeoutError < CommandError; end
126
+
125
127
  class UnknownMIBError < CommandError; end
128
+
126
129
  class UnknownOIDError < CommandError; end
127
130
  end # class Open
128
131
  end # module SNMP
@@ -32,12 +32,12 @@ module SNMP
32
32
  mkdir(@directory, cmd.to_s) if @make_directories
33
33
  outfile = File.join(@directory, cmd.to_s, oid)
34
34
  File.read(outfile)
35
- rescue Errno::ENOENT => err
35
+ rescue Errno::ENOENT => e
36
36
  if @warnings
37
37
  warning = @warnings.call(@command_generator, cmd, oid, outfile)
38
38
  warn warning
39
39
  end
40
- raise err
40
+ raise e
41
41
  end
42
42
 
43
43
  def mkdir(base, cmd)
@@ -14,7 +14,37 @@ 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
+ OID_RE = Regexp.union(/\S+-MIB::\S+/, /[0-9.]+/)
18
+
19
+ EMPTY_STRING_RE =
20
+ /^(#{OID_RE}) # capture group 1: OID
21
+ \s+=\s+
22
+ (Opaque|STRING) # capture group 2: Type
23
+ :\s*\n # value is always empty string
24
+ /x.freeze
25
+
26
+ STRING_RE =
27
+ /^(#{OID_RE}) # capture group 1: OID
28
+ \s+=\s+
29
+ (Opaque|STRING):\s+ # capture group 2: Type
30
+
31
+ ( # capture group 3: Value
32
+
33
+ (?!") # this pattern is for finding strings in need of
34
+ # quoting, so reject any strings that are already
35
+ # quoted
36
+
37
+ [^\n]* # first line of value
38
+
39
+ (\n # newline before each additional line of value
40
+ (?!
41
+ #{OID_RE} # additional lines of value are identified by not
42
+ \s+=\s+ # starting with "<OID> ="
43
+ )
44
+ [^\n]+ # additional lines of value
45
+ )*
46
+ )\n
47
+ /x.freeze
18
48
 
19
49
  def initialize(oids)
20
50
  @oids = oids
@@ -47,10 +77,8 @@ module SNMP
47
77
  def clean_input_text(text)
48
78
  text
49
79
  .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))
80
+ .gsub(EMPTY_STRING_RE, %(\\1 = \\2: ""\n))
81
+ .gsub(STRING_RE, %(\\1 = \\2: "\\3"\n))
54
82
  .gsub(Static::ANY_MESSAGE, Static::QUOTED_MESSAGES)
55
83
  end
56
84
 
@@ -82,8 +110,10 @@ module SNMP
82
110
  def parse_next_object(tokens)
83
111
  oid = tokens.next.sub(/\A\./, '')
84
112
  raise "Parse error at #{oid}" unless oid =~ OID_RE
113
+
85
114
  equals = tokens.next
86
115
  raise "Parse error after #{oid}" unless equals == '='
116
+
87
117
  type, value = parse_type(tokens)
88
118
  Value.new(oid, type, value)
89
119
  end
@@ -23,9 +23,11 @@ module SNMP
23
23
  class Bits < ValueParser
24
24
  def parse(tokens)
25
25
  return @parse if @parse
26
+
26
27
  bytes = []
27
28
  loop do
28
29
  break unless tokens.peek =~ /\A[0-9A-Za-z]{1,2}\z/
30
+
29
31
  bytes << tokens.next.to_i(16)
30
32
  end
31
33
  @parse = [@type, bytes]
@@ -50,9 +52,11 @@ module SNMP
50
52
  class HexString < ValueParser
51
53
  def parse(tokens)
52
54
  return @parse if @parse
55
+
53
56
  bytes = []
54
57
  loop do
55
58
  break unless tokens.peek =~ /\A[0-9A-Za-z]{2}\z/
59
+
56
60
  bytes << tokens.next
57
61
  end
58
62
  string = bytes.map { |b| b.to_i(16).chr }.join
@@ -72,6 +76,7 @@ module SNMP
72
76
  class Timeticks < ValueParser
73
77
  def parse(tokens)
74
78
  return @parse if @parse
79
+
75
80
  ticks = tokens.next.tr('()', '').to_i
76
81
 
77
82
  # consume tokens through one like 23:59:59.99
@@ -106,16 +111,16 @@ module SNMP
106
111
 
107
112
  KNOWN_TOKENS = {
108
113
  NOSUCHINSTANCE_STR => NoSuchInstance,
109
- NOSUCHOBJECT_STR => NoSuchObject,
114
+ NOSUCHOBJECT_STR => NoSuchObject,
110
115
  NOMOREVARIABLES_STR => Stop
111
116
  }.freeze
112
117
 
113
118
  KNOWN_TYPES = {
114
119
  nil => Default,
115
120
  'BITS' => Bits,
116
- 'INTEGER' => ValueParser::Integer,
117
- 'Gauge32' => ValueParser::Integer,
118
- 'Gauge64' => ValueParser::Integer,
121
+ 'INTEGER' => ValueParser::Integer,
122
+ 'Gauge32' => ValueParser::Integer,
123
+ 'Gauge64' => ValueParser::Integer,
119
124
  'Counter32' => ValueParser::Integer,
120
125
  'Counter64' => ValueParser::Integer,
121
126
  'Hex-STRING' => HexString,
@@ -1,5 +1,5 @@
1
1
  module SNMP
2
2
  class Open
3
- VERSION = '0.6.0'.freeze
3
+ VERSION = '0.6.1'.freeze
4
4
  end
5
5
  end
@@ -18,6 +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.required_ruby_version = '~> 2.4'
22
+
21
23
  spec.add_development_dependency 'bundler', '~> 2.2'
22
24
  spec.add_development_dependency 'rake', '~> 13.0'
23
25
  spec.add_development_dependency 'rspec', '~> 3.0'
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.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Miller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-16 00:00:00.000000000 Z
11
+ date: 2021-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,9 +105,9 @@ require_paths:
105
105
  - lib
106
106
  required_ruby_version: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '2.4'
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="