snmpjr 0.3.2-java → 0.3.3-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/history.rdoc +2 -0
- data/lib/snmpjr/response.rb +7 -2
- data/lib/snmpjr/session_v2c.rb +4 -5
- data/lib/snmpjr/walker.rb +1 -1
- data/snmpjr.gemspec +1 -1
- data/spec/integration/snmp_v2c/snmpjr_get_spec.rb +6 -5
- data/spec/integration/snmp_v2c/snmpjr_walk_spec.rb +3 -2
- data/spec/integration/snmp_v3/snmpjr_get_spec.rb +6 -5
- data/spec/integration/snmp_v3/snmpjr_walk_spec.rb +3 -2
- data/spec/snmpjr/response_spec.rb +14 -19
- data/spec/snmpjr/session_v2c_spec.rb +2 -0
- data/spec/snmpjr/walker_spec.rb +5 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzJkZTkwOTNhZTVlNDNlNmE5NTQ5MWQwNGZkNTdmZGE0ZGU2OGRhNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODk5YjVmMGQwYzU5MGM1OWM5ZmY0ZWFiZjdhNWE0NGYwYzYwOGRiNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTJiN2QwZWM3NTA4ODYzODMzZjk5ZDg5OGI0YWVlZmY1OGI3NzczNTVjNTcy
|
10
|
+
ZDEyOTJlOWViMGRjMzA2YjBjYWUxZDA3OTZmMTExODMwZTljOTM0ZTIwYzE0
|
11
|
+
MmVjMzA4YWMxZjhkN2Q4ODQ3M2E2N2JiNDJhYWFmNjlmOTEyYmE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTBlYmUwNzE0Yjg3NDRiNjUxM2QzMzVjMWZiODFhZTJhNDRhOTZlNDNlNDMw
|
14
|
+
ZGNkNWNkNTk4OGNlOTc4YzZmNTdhODdmZjkxMTI3OTJkMDdjMjMxYjEzM2Mz
|
15
|
+
YTJkMjBjN2RhZmYxY2U4OTRlN2UyMGM1MmNlNWIwNTRmMTYzZDA=
|
data/history.rdoc
CHANGED
data/lib/snmpjr/response.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
class Snmpjr
|
2
2
|
class Response
|
3
|
-
attr_reader :error, :oid
|
3
|
+
attr_reader :error, :oid, :type
|
4
4
|
|
5
5
|
def initialize response = {}
|
6
6
|
@error = response[:error] || ''
|
7
7
|
@value = response[:value] || ''
|
8
8
|
@oid = response[:oid] || ''
|
9
|
+
@type = response[:type] || ''
|
9
10
|
end
|
10
11
|
|
11
12
|
def error?
|
@@ -16,13 +17,17 @@ class Snmpjr
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
20
|
+
def to_h
|
21
|
+
{ oid: @oid, value: @value, type: @type }
|
22
|
+
end
|
23
|
+
|
19
24
|
def to_s
|
20
25
|
@value
|
21
26
|
end
|
22
27
|
|
23
28
|
def ==(other)
|
24
29
|
return false unless other.instance_of?(self.class)
|
25
|
-
@error == other.error &&
|
30
|
+
@error == other.error && to_h == other.to_h
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
data/lib/snmpjr/session_v2c.rb
CHANGED
@@ -28,10 +28,6 @@ class Snmpjr
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def error_information pdu, target
|
32
|
-
"#{target.address}, OIDs: #{pdu.to_array.map {|binding| binding.oid.to_s }.inspect}"
|
33
|
-
end
|
34
|
-
|
35
31
|
def close
|
36
32
|
@snmp.close
|
37
33
|
end
|
@@ -42,10 +38,13 @@ class Snmpjr
|
|
42
38
|
if variable_binding.is_exception
|
43
39
|
Snmpjr::Response.new(oid: variable_binding.oid.to_s, error: variable_binding.variable.to_s)
|
44
40
|
else
|
45
|
-
Snmpjr::Response.new(oid: variable_binding.oid.to_s, value: variable_binding.variable.to_s)
|
41
|
+
Snmpjr::Response.new(oid: variable_binding.oid.to_s, value: variable_binding.variable.to_s, type: variable_binding.variable.syntax_string)
|
46
42
|
end
|
47
43
|
end
|
48
44
|
|
45
|
+
def error_information pdu, target
|
46
|
+
"#{target.address}, OIDs: #{pdu.to_array.map {|binding| binding.oid.to_s }.inspect}"
|
47
|
+
end
|
49
48
|
end
|
50
49
|
|
51
50
|
class TargetTimeoutError < StandardError
|
data/lib/snmpjr/walker.rb
CHANGED
@@ -30,7 +30,7 @@ class Snmpjr
|
|
30
30
|
|
31
31
|
def extract_variable_bindings variable_bindings
|
32
32
|
variable_bindings.flat_map {|vb|
|
33
|
-
Snmpjr::Response.new(oid: vb.oid.to_s, value: vb.variable.to_s)
|
33
|
+
Snmpjr::Response.new(oid: vb.oid.to_s, value: vb.variable.to_s, type: vb.variable.syntax_string)
|
34
34
|
}
|
35
35
|
end
|
36
36
|
|
data/snmpjr.gemspec
CHANGED
@@ -16,19 +16,20 @@ describe "snmpjr for snmp v2c" do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'can perform a simple synchronous get request on an snmp agent' do
|
19
|
-
expect(subject.get '1.3.6.1.2.1.1.1.0').to eq Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m')
|
19
|
+
expect(subject.get '1.3.6.1.2.1.1.1.0').to eq Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m', type: 'OCTET STRING')
|
20
20
|
end
|
21
21
|
|
22
|
-
let(:expected) { [Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'),
|
23
|
-
Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5.0', value: 'zeus.snmplabs.com')
|
22
|
+
let(:expected) { [Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m', type: 'OCTET STRING'),
|
23
|
+
Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5.0', value: 'zeus.snmplabs.com', type: 'OCTET STRING'),
|
24
|
+
Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.7.0', value: '72', type: 'Integer32')] }
|
24
25
|
it 'can perform a series of gets if passed an array of oids' do
|
25
|
-
expect(subject.get ['1.3.6.1.2.1.1.1.0', '1.3.6.1.2.1.1.5.0']).to eq expected
|
26
|
+
expect(subject.get ['1.3.6.1.2.1.1.1.0', '1.3.6.1.2.1.1.5.0', '1.3.6.1.2.1.1.7.0']).to eq expected
|
26
27
|
end
|
27
28
|
|
28
29
|
context "when an invalid oid is requested" do
|
29
30
|
|
30
31
|
let(:expected) { [Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5', error: 'noSuchInstance'),
|
31
|
-
Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5.0', value: 'zeus.snmplabs.com')] }
|
32
|
+
Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5.0', value: 'zeus.snmplabs.com', type: 'OCTET STRING')] }
|
32
33
|
|
33
34
|
it 'returns an error' do
|
34
35
|
expect(subject.get ['1.3.6.1.2.1.1.5', '1.3.6.1.2.1.1.5.0']).to eq expected
|
@@ -19,8 +19,9 @@ describe "snmpjr for snmp v2c" do
|
|
19
19
|
it 'can perform a simple synchronous walk request on an snmp agent' do
|
20
20
|
response = subject.walk '1.3.6.1.2.1.1'
|
21
21
|
expect(response.count).to eq 11
|
22
|
-
expect(response.first.
|
23
|
-
|
22
|
+
expect(response.first.to_h).to eq(
|
23
|
+
{ oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m', type: 'OCTET STRING' }
|
24
|
+
)
|
24
25
|
end
|
25
26
|
|
26
27
|
context "when a non existent subtree is walked" do
|
@@ -18,13 +18,14 @@ describe "snmpjr for snmp v3" do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'can perform a simple synchronous get request on an snmp agent' do
|
21
|
-
expect(subject.get '1.3.6.1.2.1.1.1.0').to eq Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m')
|
21
|
+
expect(subject.get '1.3.6.1.2.1.1.1.0').to eq Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m', type: 'OCTET STRING')
|
22
22
|
end
|
23
23
|
|
24
|
-
let(:expected) { [Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'),
|
25
|
-
Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5.0', value: 'zeus.snmplabs.com')
|
24
|
+
let(:expected) { [Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m', type: 'OCTET STRING'),
|
25
|
+
Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5.0', value: 'zeus.snmplabs.com', type: 'OCTET STRING'),
|
26
|
+
Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.7.0', value: '72', type: 'Integer32')] }
|
26
27
|
it 'can perform a series of gets if passed an array of oids' do
|
27
|
-
expect(subject.get ['1.3.6.1.2.1.1.1.0', '1.3.6.1.2.1.1.5.0']).to eq expected
|
28
|
+
expect(subject.get ['1.3.6.1.2.1.1.1.0', '1.3.6.1.2.1.1.5.0', '1.3.6.1.2.1.1.7.0']).to eq expected
|
28
29
|
end
|
29
30
|
|
30
31
|
context "when an invalid oid is requested" do
|
@@ -38,7 +39,7 @@ describe "snmpjr for snmp v3" do
|
|
38
39
|
end
|
39
40
|
|
40
41
|
let(:expected) { [Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5', error: 'noSuchInstance'),
|
41
|
-
Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5.0', value: 'zeus.snmplabs.com')] }
|
42
|
+
Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5.0', value: 'zeus.snmplabs.com', type: 'OCTET STRING')] }
|
42
43
|
|
43
44
|
it 'returns an error' do
|
44
45
|
expect(subject.get ['1.3.6.1.2.1.1.5', '1.3.6.1.2.1.1.5.0']).to eq expected
|
@@ -20,8 +20,9 @@ describe "snmpjr for snmp v3" do
|
|
20
20
|
it 'can perform a simple synchronous walk request on an snmp agent' do
|
21
21
|
response = subject.walk '1.3.6.1.2.1.1'
|
22
22
|
expect(response.count).to eq 11
|
23
|
-
expect(response.first.
|
24
|
-
|
23
|
+
expect(response.first.to_h).to eq(
|
24
|
+
{ oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m', type: 'OCTET STRING' }
|
25
|
+
)
|
25
26
|
end
|
26
27
|
|
27
28
|
context "when a non existent subtree is walked" do
|
@@ -5,12 +5,12 @@ describe Snmpjr::Response do
|
|
5
5
|
describe '.new' do
|
6
6
|
context 'when initialized with a value' do
|
7
7
|
it 'assigns that value' do
|
8
|
-
response = described_class.new(oid: 'some oid', value: 'Some value')
|
9
|
-
expect(response.
|
8
|
+
response = described_class.new(oid: 'some oid', value: 'Some value', type: 'Some type')
|
9
|
+
expect(response.to_h).to eq({ oid: 'some oid', value: 'Some value', type: 'Some type' })
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'sets the error to an empty string' do
|
13
|
-
response = described_class.new(oid: 'some oid', value: 'Some value')
|
13
|
+
response = described_class.new(oid: 'some oid', value: 'Some value', type: 'Some type')
|
14
14
|
expect(response.error).to eq ''
|
15
15
|
end
|
16
16
|
end
|
@@ -42,30 +42,25 @@ describe Snmpjr::Response do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'returns false if there isnt an error' do
|
45
|
-
response = described_class.new(oid: 'some oid', value: 'Some value')
|
45
|
+
response = described_class.new(oid: 'some oid', value: 'Some value', type: 'Some type')
|
46
46
|
expect(response.error?).to be_falsey
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
describe '#==' do
|
51
51
|
context 'when the objects are equal' do
|
52
|
-
let(:other) { Snmpjr::Response.new(oid: 'some oid', value: 'some value') }
|
52
|
+
let(:other) { Snmpjr::Response.new(oid: 'some oid', value: 'some value', type: 'Some type') }
|
53
53
|
it 'returns true' do
|
54
|
-
expect(described_class.new(oid: 'some oid', value: 'some value')).to eq other
|
54
|
+
expect(described_class.new(oid: 'some oid', value: 'some value', type: 'Some type')).to eq other
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
context 'when the objects are
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
context 'when the oids are different' do
|
66
|
-
let(:other) { Snmpjr::Response.new(oid: 'some oid', error: 'some error') }
|
67
|
-
it 'returns true' do
|
68
|
-
expect(described_class.new(oid: 'another oid', error: 'some error')).to_not eq other
|
58
|
+
context 'when the objects are different' do
|
59
|
+
context 'when the objects are equal' do
|
60
|
+
let(:other) { Snmpjr::Response.new(oid: 'some oid', error: 'some error') }
|
61
|
+
it 'returns false' do
|
62
|
+
expect(described_class.new(oid: 'some oid', error: 'another error')).to_not eq other
|
63
|
+
end
|
69
64
|
end
|
70
65
|
end
|
71
66
|
|
@@ -73,12 +68,12 @@ describe Snmpjr::Response do
|
|
73
68
|
let(:other) { double :response }
|
74
69
|
before do
|
75
70
|
allow(other).to receive(:error).and_return ''
|
76
|
-
allow(other).to receive(:
|
71
|
+
allow(other).to receive(:to_h).and_return({ value: 'some value', type: 'Some type' })
|
77
72
|
allow(other).to receive(:oid).and_return 'some oid'
|
78
73
|
end
|
79
74
|
|
80
75
|
it 'returns false' do
|
81
|
-
expect(described_class.new(oid: 'some oid', value: 'some value')).to_not eq other
|
76
|
+
expect(described_class.new(oid: 'some oid', value: 'some value', type: 'Some type')).to_not eq other
|
82
77
|
end
|
83
78
|
end
|
84
79
|
end
|
@@ -37,9 +37,11 @@ describe Snmpjr::SessionV2C do
|
|
37
37
|
|
38
38
|
before do
|
39
39
|
allow(snmp_session).to receive(:send).and_return response
|
40
|
+
allow(vb1).to receive_message_chain('variable.syntax_string')
|
40
41
|
allow(vb1).to receive_message_chain('variable.to_s')
|
41
42
|
allow(vb1).to receive_message_chain('oid.to_s') { "1.2.3" }
|
42
43
|
allow(vb1).to receive(:is_exception)
|
44
|
+
allow(vb2).to receive_message_chain('variable.syntax_string')
|
43
45
|
allow(vb2).to receive_message_chain('variable.to_s')
|
44
46
|
allow(vb2).to receive_message_chain('oid.to_s') { "4.5.6" }
|
45
47
|
allow(vb2).to receive(:is_exception)
|
data/spec/snmpjr/walker_spec.rb
CHANGED
@@ -40,6 +40,7 @@ describe Snmpjr::Walker do
|
|
40
40
|
before do
|
41
41
|
allow(tree_util).to receive(:getSubtree).with(target, oid).and_raise Exception.new 'noAccess'
|
42
42
|
end
|
43
|
+
|
43
44
|
it 'raises a runtime error' do
|
44
45
|
expect{
|
45
46
|
subject.walk oid
|
@@ -49,6 +50,7 @@ describe Snmpjr::Walker do
|
|
49
50
|
|
50
51
|
context 'when a target times out' do
|
51
52
|
let(:tree_event_1) { double :tree_event_1 }
|
53
|
+
|
52
54
|
before do
|
53
55
|
allow(tree_event_1).to receive(:is_error?).and_return true
|
54
56
|
allow(tree_event_1).to receive(:error_message).and_return 'Request timed out.'
|
@@ -63,6 +65,7 @@ describe Snmpjr::Walker do
|
|
63
65
|
|
64
66
|
context 'when a random error occurs' do
|
65
67
|
let(:tree_event_1) { double :tree_event_1 }
|
68
|
+
|
66
69
|
before do
|
67
70
|
allow(tree_event_1).to receive(:is_error?).and_return true
|
68
71
|
allow(tree_event_1).to receive(:error_message).and_return 'noAccess'
|
@@ -85,8 +88,8 @@ describe Snmpjr::Walker do
|
|
85
88
|
end
|
86
89
|
|
87
90
|
it 'performs a synchronous walk' do
|
88
|
-
expect(subject.walk oid).to match_array [Snmpjr::Response.new(oid: vb1.oid.to_s, value: vb1.variable.to_s),
|
89
|
-
Snmpjr::Response.new(oid: vb2.oid.to_s, value: vb2.variable.to_s)]
|
91
|
+
expect(subject.walk oid).to match_array [Snmpjr::Response.new(oid: vb1.oid.to_s, value: vb1.variable.to_s, type: vb1.variable.syntax_string),
|
92
|
+
Snmpjr::Response.new(oid: vb2.oid.to_s, value: vb2.variable.to_s, type: vb1.variable.syntax_string)]
|
90
93
|
end
|
91
94
|
|
92
95
|
it 'closes the snmp session' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snmpjr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Zen Kyprianou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-n-bake
|