snmp-open 0.7.0 → 0.7.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: b13230f5561531372236208bfe42c5a0d44ef032d8075316fd02bf78ec7e78b3
4
- data.tar.gz: 2fc93d9967c5fc37918b7f371147e14f9942d356699a02e4ce46b06763bfceb0
3
+ metadata.gz: 0c647ac12c0055f8f71908c27d5460e3b220d2c265751987d7a08ac1b1179efa
4
+ data.tar.gz: 74dfcf665582e2d23f093a6e67b83e9def03c1b8939d9772b7a645e884f95dbe
5
5
  SHA512:
6
- metadata.gz: b3678f4b2e04b9f5a3a45edd3273d8ecfecb8a7a2bc4d92568b9644c6192e8e5fbeb8b902f0bf53d5c42b184f1402359a6daf8ea9f9923c1331b22b914fc0a54
7
- data.tar.gz: 19a0f2e47cb585f3a1aaab331c3a97bbec05d3e57ce8ec76e17f5c1dc48f96a5b68cbb0b9d8b7b648490cbfbeed0dd1f2810381574286bd5135bddc9eac2d5bc
6
+ metadata.gz: d8bd115d0a86d384dc860191bbb045e4903ab739ef1581041b6e030134345a60a3481a4f75554ddaf527587db8e72d0b544949590638606fabe0ea2ada23a77d
7
+ data.tar.gz: d505743d70310b076a783e1cdad8ab95a1a5776c6e8f5caf467c827791216896d76db3baf5fc9c4ca25519de6bf6336a7c6e27c3bff308e8eb65235c68ecf597
@@ -12,7 +12,7 @@ jobs:
12
12
  fail-fast: false
13
13
  matrix:
14
14
  os: [ubuntu-latest, macos-latest]
15
- ruby: [2.4, 2.5, 2.6, 2.7, jruby, truffleruby]
15
+ ruby: [2.4, 2.5, 2.6, 2.7, jruby]
16
16
  runs-on: ${{ matrix.os }}
17
17
  steps:
18
18
  - uses: actions/checkout@v2
@@ -63,17 +63,24 @@ module SNMP
63
63
  private
64
64
 
65
65
  def align(columns)
66
- indexes = columns.first.map { |value| index_using_first_oid(value) }
66
+ indexes = indexes_from_columns(columns)
67
+ bases = bases_from_columns(columns)
67
68
  hash = columns.flat_map { |row| row.map { |v| [v.oid, v] } }.to_h
68
69
 
69
70
  indexes.map do |index|
70
- @oids.map do |base|
71
+ bases.map do |base, _|
71
72
  oid = [base, *index].join('.')
72
73
  hash.fetch(oid) { Value.new(oid, 'absent', nil) }
73
74
  end
74
75
  end
75
76
  end
76
77
 
78
+ def bases_from_columns(columns)
79
+ @oids
80
+ .zip(columns.map { |c| c&.first&.oid })
81
+ .map { |base, oid| base && oid && split_oid(base, oid) }
82
+ end
83
+
77
84
  def clean_input_text(text)
78
85
  text
79
86
  .gsub(/\r\n|\n\r|\r/, "\n")
@@ -82,16 +89,8 @@ module SNMP
82
89
  .gsub(Static::ANY_MESSAGE, Static::QUOTED_MESSAGES)
83
90
  end
84
91
 
85
- def index_using_first_oid(value)
86
- base = @oids.first
87
-
88
- if base == value.oid
89
- nil
90
- elsif value.oid.start_with?(base)
91
- value.oid.gsub(/\A#{base}\.?/, '')
92
- else
93
- raise "Received ID doesn't start with the given ID"
94
- end
92
+ def indexes_from_columns(columns)
93
+ columns.first.map { |value| split_oid(@oids.first, value.oid)[1] }
95
94
  end
96
95
 
97
96
  def parse_tokens(tokens)
@@ -124,6 +123,21 @@ module SNMP
124
123
  ValueParser.find(type, token).parse(tokens)
125
124
  end
126
125
 
126
+ # split a complete OID into a base and index, given an expected base
127
+ # raises if the base isn't present
128
+ def split_oid(base, oid)
129
+ if base == oid
130
+ [base, nil]
131
+ elsif oid.start_with?(base)
132
+ [base, oid.sub(/\A#{base}\.?/, '')]
133
+ elsif base.include?('::') && !oid.include?('::')
134
+ alternate_base = base.sub(/\A[^:]+::/, '')
135
+ split_oid(alternate_base, oid)
136
+ else
137
+ raise "Received ID doesn't start with the given ID"
138
+ end
139
+ end
140
+
127
141
  def table(columns)
128
142
  if columns.size == 1 && columns.all? { |column| column.size == 1 }
129
143
  columns
@@ -1,5 +1,5 @@
1
1
  module SNMP
2
2
  class Open
3
- VERSION = '0.7.0'.freeze
3
+ VERSION = '0.7.1'.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.7.0
4
+ version: 0.7.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: 2022-03-15 00:00:00.000000000 Z
11
+ date: 2022-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler