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 +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/lib/snmp/open/parser.rb +26 -12
- data/lib/snmp/open/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c647ac12c0055f8f71908c27d5460e3b220d2c265751987d7a08ac1b1179efa
|
4
|
+
data.tar.gz: 74dfcf665582e2d23f093a6e67b83e9def03c1b8939d9772b7a645e884f95dbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8bd115d0a86d384dc860191bbb045e4903ab739ef1581041b6e030134345a60a3481a4f75554ddaf527587db8e72d0b544949590638606fabe0ea2ada23a77d
|
7
|
+
data.tar.gz: d505743d70310b076a783e1cdad8ab95a1a5776c6e8f5caf467c827791216896d76db3baf5fc9c4ca25519de6bf6336a7c6e27c3bff308e8eb65235c68ecf597
|
data/.github/workflows/ruby.yml
CHANGED
data/lib/snmp/open/parser.rb
CHANGED
@@ -63,17 +63,24 @@ module SNMP
|
|
63
63
|
private
|
64
64
|
|
65
65
|
def align(columns)
|
66
|
-
indexes = columns
|
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
|
-
|
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
|
86
|
-
|
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
|
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.7.
|
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-
|
11
|
+
date: 2022-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|