netsnmp 0.1.5 → 0.1.6
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 +4 -4
- data/.rubocop_todo.yml +2 -2
- data/.travis.yml +2 -1
- data/README.md +2 -0
- data/lib/netsnmp/varbind.rb +14 -3
- data/lib/netsnmp/version.rb +1 -1
- data/spec/varbind_spec.rb +37 -2
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6e597be5bb67ffec6821029f1f7f8dc94532c4a9c1398bfef974922c3f0f6cf
|
4
|
+
data.tar.gz: 3ddbf95ad3c480e8960e7501511c7ddd3c43b38386226783e8bb110811041a9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bff2dc9d8641545bebce2fafc68ded21f282ca5fe68eb07fbeb0aac66333a25c50f871468b6a442a90777c0eacccd3145426bc2c1c7c4cd23ff8f409e80f6135
|
7
|
+
data.tar.gz: 6643a5b5c3275ad9db55cad071b42b7cd423b5896786718ad4cfc8ac224e3c1b56e8c8c36b803db7b60e906d3981502e92256d8b63ba692d60333f026147754b
|
data/.rubocop_todo.yml
CHANGED
@@ -11,7 +11,7 @@ Metrics/BlockLength:
|
|
11
11
|
|
12
12
|
# Offense count: 17
|
13
13
|
Metrics/AbcSize:
|
14
|
-
Max:
|
14
|
+
Max: 100
|
15
15
|
|
16
16
|
# Offense count: 2
|
17
17
|
# Configuration parameters: CountComments.
|
@@ -25,7 +25,7 @@ Metrics/CyclomaticComplexity:
|
|
25
25
|
# Offense count: 22
|
26
26
|
# Configuration parameters: CountComments.
|
27
27
|
Metrics/MethodLength:
|
28
|
-
Max:
|
28
|
+
Max: 50
|
29
29
|
|
30
30
|
# Offense count: 2
|
31
31
|
# Configuration parameters: CountKeywordArgs.
|
data/.travis.yml
CHANGED
@@ -8,7 +8,7 @@ before_install:
|
|
8
8
|
- sudo apt-get install -o Dpkg::Options::="--force-confold" --force-yes -y docker-ce
|
9
9
|
|
10
10
|
install:
|
11
|
-
- gem update
|
11
|
+
- gem i rubygems-update -v '<3' && update_rubygems
|
12
12
|
- bundle install --path .bundle
|
13
13
|
|
14
14
|
script:
|
@@ -21,6 +21,7 @@ rvm:
|
|
21
21
|
- 2.3
|
22
22
|
- 2.4
|
23
23
|
- 2.5
|
24
|
+
- 2.6
|
24
25
|
- ruby-head
|
25
26
|
- jruby-head
|
26
27
|
- rbx-2
|
data/README.md
CHANGED
@@ -123,6 +123,8 @@ If you create an `IPAddr` object (ruby standard library `ipaddr`) and pass it to
|
|
123
123
|
The `NETSNMP::Timeticks` type is internal to this library, but it is a ruby `Numeric` type. You are safe to use it "as a numeric", that is, perform calculations.
|
124
124
|
|
125
125
|
|
126
|
+
Counter32 and Counter64 types will map to plain integers.
|
127
|
+
|
126
128
|
You can find usage examples [here](https://github.com/swisscom/ruby-netsnmp/blob/master/spec/varbind_spec.rb). If you need support to a missing type, you have the following options:
|
127
129
|
|
128
130
|
* Use the `:type` parameter in `#set` calls:
|
data/lib/netsnmp/varbind.rb
CHANGED
@@ -91,7 +91,15 @@ module NETSNMP
|
|
91
91
|
return Timetick.new(value).to_asn
|
92
92
|
when :opaque then 4
|
93
93
|
when :nsap then 5
|
94
|
-
when :counter64
|
94
|
+
when :counter64
|
95
|
+
asn_val = [
|
96
|
+
(value >> 96) & 0xFFFFFFFF,
|
97
|
+
(value >> 64) & 0xFFFFFFFF,
|
98
|
+
(value >> 32) & 0xFFFFFFFF,
|
99
|
+
value & 0xFFFFFFFF
|
100
|
+
].pack("NNNN")
|
101
|
+
asn_val = asn_val[1..-1] while asn_val.start_with?("\x00")
|
102
|
+
6
|
95
103
|
when :uinteger then 7
|
96
104
|
else
|
97
105
|
raise Error, "#{typ}: unsupported application type"
|
@@ -108,12 +116,15 @@ module NETSNMP
|
|
108
116
|
2 # gauge
|
109
117
|
val = asn.value
|
110
118
|
val.prepend("\x00") while val.bytesize < 4
|
111
|
-
|
119
|
+
val.unpack("N*")[0] || 0
|
112
120
|
when 3 # timeticks
|
113
121
|
Timetick.new(asn.value.unpack("N*")[0] || 0)
|
114
122
|
# when 4 # opaque
|
115
123
|
# when 5 # NSAP
|
116
|
-
|
124
|
+
when 6 # ASN Counter 64
|
125
|
+
val = asn.value
|
126
|
+
val.prepend("\x00") while val.bytesize % 16 != 0
|
127
|
+
val.unpack("NNNN").reduce(0) { |sum, elem| (sum << 32) + elem }
|
117
128
|
# when 7 # ASN UInteger
|
118
129
|
end
|
119
130
|
end
|
data/lib/netsnmp/version.rb
CHANGED
data/spec/varbind_spec.rb
CHANGED
@@ -9,27 +9,62 @@ RSpec.describe NETSNMP::Varbind do
|
|
9
9
|
ipaddr = IPAddr.new("10.11.104.2")
|
10
10
|
varbind = described_class.new(".1.3.6.1.4.1.2011.6.3.1.1.0", value: ipaddr)
|
11
11
|
expect(varbind.to_der).to end_with("@\x04\n\vh\x02".b)
|
12
|
+
asn = varbind.to_asn.value.last
|
13
|
+
expect(varbind.convert_application_asn(asn)).to eq(ipaddr)
|
12
14
|
end
|
13
15
|
it "converts custom timeticks" do
|
14
16
|
timetick = NETSNMP::Timetick.new(1) # yes, one timetick
|
15
17
|
varbind = described_class.new(".1.3.6.1.2.1.1.3.0", value: timetick)
|
16
18
|
expect(varbind.to_der).to end_with("\x04\x00\x00\x00\x01".b) # ends with an octet string rep of 1 timetick
|
19
|
+
asn = varbind.to_asn.value.last
|
20
|
+
expect(varbind.convert_application_asn(asn)).to eq(timetick)
|
17
21
|
end
|
18
22
|
context "when passed a type" do
|
19
23
|
it "converts gauge32" do
|
20
24
|
gauge = 805
|
21
25
|
varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :gauge, value: gauge)
|
22
26
|
expect(varbind.to_der).to end_with("B\x02\x03%".b)
|
27
|
+
asn = varbind.to_asn.value.last
|
28
|
+
expect(varbind.convert_application_asn(asn)).to eq(gauge)
|
23
29
|
end
|
24
30
|
it "converts counter32" do
|
25
|
-
|
26
|
-
varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :counter32, value:
|
31
|
+
counter = 998932
|
32
|
+
varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :counter32, value: counter)
|
27
33
|
expect(varbind.to_der).to end_with("\x0F>\x14".b)
|
34
|
+
asn = varbind.to_asn.value.last
|
35
|
+
expect(varbind.convert_application_asn(asn)).to eq(counter)
|
36
|
+
end
|
37
|
+
it "converts counter64" do
|
38
|
+
counter = 998932
|
39
|
+
varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :counter64, value: counter)
|
40
|
+
expect(varbind.to_der).to end_with("\x0F>\x14".b)
|
41
|
+
asn = varbind.to_asn.value.last
|
42
|
+
expect(varbind.convert_application_asn(asn)).to eq(counter)
|
43
|
+
|
44
|
+
counter = 4294967296
|
45
|
+
varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :counter64, value: counter)
|
46
|
+
expect(varbind.to_der).to end_with("\x01\x00\x00\x00\x00".b)
|
47
|
+
asn = varbind.to_asn.value.last
|
48
|
+
expect(varbind.convert_application_asn(asn)).to eq(counter)
|
49
|
+
|
50
|
+
counter = 309084502
|
51
|
+
varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :counter64, value: counter)
|
52
|
+
expect(varbind.to_der).to include("F\x04".b)
|
53
|
+
asn = varbind.to_asn.value.last
|
54
|
+
expect(varbind.convert_application_asn(asn)).to eq(counter)
|
55
|
+
|
56
|
+
counter = 2_613_579_752_238
|
57
|
+
varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :counter64, value: counter)
|
58
|
+
expect(varbind.to_der).to include("F\x06".b)
|
59
|
+
asn = varbind.to_asn.value.last
|
60
|
+
expect(varbind.convert_application_asn(asn)).to eq(counter)
|
28
61
|
end
|
29
62
|
it "converts integer ticks" do
|
30
63
|
timetick = 1
|
31
64
|
varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :timetick, value: timetick)
|
32
65
|
expect(varbind.to_der).to end_with("\x04\x00\x00\x00\x01".b)
|
66
|
+
asn = varbind.to_asn.value.last
|
67
|
+
expect(varbind.convert_application_asn(asn)).to eq(timetick)
|
33
68
|
end
|
34
69
|
end
|
35
70
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netsnmp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Cardoso
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '10.1'
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: 10.1.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '10.1'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '10.1'
|
30
27
|
- - ">="
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: 10.1.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '10.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rspec
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '3.5'
|
40
37
|
- - ">="
|
41
38
|
- !ruby/object:Gem::Version
|
42
39
|
version: 3.5.0
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '3.5'
|
43
43
|
type: :development
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - "~>"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '3.5'
|
50
47
|
- - ">="
|
51
48
|
- !ruby/object:Gem::Version
|
52
49
|
version: 3.5.0
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '3.5'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: celluloid-io
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
requirements:
|
144
144
|
- net-snmp
|
145
145
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.7.
|
146
|
+
rubygems_version: 2.7.8
|
147
147
|
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: SNMP Client library
|