snmpjr 0.2.1-java → 0.2.2-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTA2YTdhZGVkOWZhZjgzZDQxMjkwNWFjYjkzMTNiOTFiZWYyMDI2OQ==
4
+ MmUwNWVjOGJkMDViODU2YjZiNGU1NWRjMTg0NmIwZDhjYzgyMmRiOQ==
5
5
  data.tar.gz: !binary |-
6
- ZGI1YTFkNjg4ODAxM2NkOGI3ZTlmZTVlOTE0NTk5ODQ2MGMzMGVmZg==
6
+ MzA2MDZlZmE0NjM1ZjIxMDRjYzMyZDQ0MmY1ZWMwYjhlMjQ3YjYxOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjFjOTJiYmNmMmNiYWI1ZWFjOTc4NGJiNDM1YjJlMjVkZTZhZDY3YzE1OTM0
10
- YjZiZmZiMWEzZWUzYzBhMDJkYjk2M2VlODFkM2M3NGM1Y2MxNmY2Y2Y4N2Jm
11
- ZjliZTNmNmFjN2Y2NmVkOGJhM2U3Mzk0ZGZlNTcyZjdjZGZhZjg=
9
+ MzFlMzlmMjNlY2I4MjlkNWYwN2QxMzZmNWU2NDk0OGUzZmJhZDczMTM3Zjg2
10
+ NGMyMjY3NTJmMDlkNmRhNzM4ZTc3NTZiMTkyZmI0YjQ5OWUxZjg3OGQ1ODY2
11
+ ZjIzNDhkZmZhNDEzYTZlZmIzNWMwMTBiNjI3NTE4NDI5Y2RmMzA=
12
12
  data.tar.gz: !binary |-
13
- NzI2ZThiNWIxYmMwYjgwYjFjMzU0ODg1ZTgzNmYzMWRiYTk5OWRiMTEyY2M5
14
- NTQ1NTM4YWJmYmZjNGZkYTE3NGY0YzJjY2RiNWE0OTBjYWNjNGYzNDQzZWNi
15
- ZGY0YzMyMTExZGRmNGUzYzgxOGQ3NjUyMDlhMGVlYmE4Zjg3MTU=
13
+ MGFkYmI2NTk4ZTBiNjg4YTdiZjdkZTczMjQ5MjBhMjFjZjFlY2U2YTFlZjEx
14
+ YmYzNDNlM2ZlYjcyOGFmOTZmMTBhN2NhZWE0OTMyZjZhMDQ3NDYxMjY2MTg1
15
+ ZWM5ZjlhNjU0MjI2MDY2MmZlMDQxNmM4NTcyNzZkZGZjYzhhMWE=
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ tags
1
2
  *.DS_Store
2
3
  log/*
3
4
  *.swo
data/.semver CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 2
4
- :patch: 1
4
+ :patch: 2
5
5
  :special: ''
6
6
  :metadata: ''
data/README.md CHANGED
@@ -9,7 +9,8 @@ Please note the gem is still in early develpment. Do not use as of yet!
9
9
 
10
10
  ## Features
11
11
 
12
- * Simple Synchronous SNMP v2c Get requests
12
+ * Simple Synchronous SNMP V2 Get requests
13
+ * Synchronous SNMP V2 Walk
13
14
 
14
15
  ## Requirements
15
16
 
@@ -36,8 +37,8 @@ Or install it yourself as:
36
37
 
37
38
  ```ruby
38
39
  # Initialize Snmpjr with host, port and a community
40
+ # Optional Params. (port, retries, timeout)
39
41
  snmp = Snmpjr.new(host: '127.0.0.1', port: 161, community: 'public')
40
- Optional Params. (retries, timeout)
41
42
 
42
43
  # Call get on any single Oid
43
44
  snmp.get '1.3.6.1.2.1.1.1.0'
@@ -47,14 +48,14 @@ snmp.get '1.3.6.1.2.1.1.1.0'
47
48
  snmp.get ['1.3.6.1.2.1.1.1.0', '1.3.6.1.2.1.1.3.0']
48
49
  => [Snmpjr::Response.new(value: 'First result'), Snmpjr::Response.new(value: 'Second result')]
49
50
 
50
- Response objects respond to error?
51
+ # Response objects respond to error?
51
52
 
52
53
  # Call walk on an Oid
53
54
  snmp.walk '1.3.6.1.2.1.1.1'
54
- => [Snmpjr::Response.new(value: 'First response')..Snmpjr::Response.new(value: 'First response')]
55
+ => [Snmpjr::Response.new(value: 'First response')..Snmpjr::Response.new(value: 'Last response')]
55
56
  ```
56
57
 
57
- Snmpjr will catch and raise any exceptions that happen in Java land as RuntimeErrors preserving the message.
58
+ Snmpjr will catch and raise any exceptions that happen in Java land and raise them as RuntimeErrors while preserving the message.
58
59
 
59
60
  When you request an Array of Oids these will be pulled sequentially
60
61
 
data/history.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ == v0.2.2 (03 November 2014)
2
+
3
+ * Add the Oid as part of the response object
4
+
1
5
  == v0.2.1 (27 October 2014)
2
6
 
3
7
  * Try to fix the tag
@@ -1,10 +1,11 @@
1
1
  class Snmpjr
2
2
  class Response
3
- attr_reader :error
3
+ attr_reader :error, :oid
4
4
 
5
5
  def initialize response = {}
6
6
  @error = response[:error] || ''
7
7
  @value = response[:value] || ''
8
+ @oid = response[:oid] || ''
8
9
  end
9
10
 
10
11
  def error?
@@ -20,7 +21,8 @@ class Snmpjr
20
21
  end
21
22
 
22
23
  def ==(other)
23
- @error == other.error && to_s == other.to_s
24
+ return false unless other.instance_of?(self.class)
25
+ @error == other.error && to_s == other.to_s && @oid == other.oid
24
26
  end
25
27
  end
26
28
  end
@@ -37,9 +37,9 @@ class Snmpjr
37
37
 
38
38
  def construct_response variable_binding
39
39
  if variable_binding.is_exception
40
- Snmpjr::Response.new(error: variable_binding.variable.to_s)
40
+ Snmpjr::Response.new(oid: variable_binding.oid.to_s, error: variable_binding.variable.to_s)
41
41
  else
42
- Snmpjr::Response.new(value: variable_binding.variable.to_s)
42
+ Snmpjr::Response.new(oid: variable_binding.oid.to_s, value: variable_binding.variable.to_s)
43
43
  end
44
44
  end
45
45
 
@@ -1,3 +1,3 @@
1
1
  class Snmpjr
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/snmpjr/walker.rb CHANGED
@@ -29,7 +29,7 @@ class Snmpjr
29
29
 
30
30
  def extract_variable_bindings variable_bindings
31
31
  variable_bindings.flat_map {|vb|
32
- Snmpjr::Response.new(value: vb.variable.to_s)
32
+ Snmpjr::Response.new(oid: vb.oid.to_s, value: vb.variable.to_s)
33
33
  }
34
34
  end
35
35
 
@@ -9,19 +9,19 @@ describe "snmpjr" do
9
9
  subject { Snmpjr.new(host: 'demo.snmplabs.com', port: 161, community: 'public') }
10
10
 
11
11
  it 'can perform a simple synchronous get request on an snmp agent' do
12
- expect(subject.get '1.3.6.1.2.1.1.1.0').to eq Snmpjr::Response.new(value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m')
12
+ 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')
13
13
  end
14
14
 
15
- let(:expected) { [Snmpjr::Response.new(value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'),
16
- Snmpjr::Response.new(value: 'zeus.snmplabs.com')] }
15
+ 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'),
16
+ Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5.0', value: 'zeus.snmplabs.com')] }
17
17
  it 'can perform a series of gets if passed an array of oids' do
18
18
  expect(subject.get ['1.3.6.1.2.1.1.1.0', '1.3.6.1.2.1.1.5.0']).to eq expected
19
19
  end
20
20
 
21
21
  context "when an invalid oid is requested" do
22
22
 
23
- let(:expected) { [Snmpjr::Response.new(error: 'noSuchInstance'),
24
- Snmpjr::Response.new(value: 'zeus.snmplabs.com')] }
23
+ let(:expected) { [Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5', error: 'noSuchInstance'),
24
+ Snmpjr::Response.new(oid: '1.3.6.1.2.1.1.5.0', value: 'zeus.snmplabs.com')] }
25
25
 
26
26
  it 'returns an error' do
27
27
  expect(subject.get ['1.3.6.1.2.1.1.5', '1.3.6.1.2.1.1.5.0']).to eq expected
@@ -5,53 +5,80 @@ 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(value: 'Some value')
8
+ response = described_class.new(oid: 'some oid', value: 'Some value')
9
9
  expect(response.to_s).to eq 'Some value'
10
10
  end
11
11
 
12
12
  it 'sets the error to an empty string' do
13
- response = described_class.new(value: 'Some value')
13
+ response = described_class.new(oid: 'some oid', value: 'Some value')
14
14
  expect(response.error).to eq ''
15
15
  end
16
16
  end
17
17
 
18
18
  context 'when initialized with an error' do
19
19
  it 'assigns that error' do
20
- response = described_class.new(error: 'Some error')
20
+ response = described_class.new(oid: 'some oid', error: 'Some error')
21
21
  expect(response.error).to eq 'Some error'
22
22
  end
23
23
 
24
24
  it 'sets the value to an empty string' do
25
- response = described_class.new(error: 'Some error')
25
+ response = described_class.new(oid: 'some oid', error: 'Some error')
26
26
  expect(response.to_s).to eq ''
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
+ describe '#oid' do
32
+ it 'returns the oid' do
33
+ response = described_class.new(oid: 'some oid', error: 'Some error')
34
+ expect(response.oid).to eq 'some oid'
35
+ end
36
+ end
37
+
31
38
  describe '#error?' do
32
39
  it 'returns true if there is an error' do
33
- response = described_class.new(error: 'Some error')
40
+ response = described_class.new(oid: 'some oid', error: 'Some error')
34
41
  expect(response.error?).to be_truthy
35
42
  end
36
43
 
37
44
  it 'returns false if there isnt an error' do
38
- response = described_class.new(value: 'Some value')
45
+ response = described_class.new(oid: 'some oid', value: 'Some value')
39
46
  expect(response.error?).to be_falsey
40
47
  end
41
48
  end
42
49
 
43
50
  describe '#==' do
44
51
  context 'when the objects are equal' do
45
- let(:other) { Snmpjr::Response.new(value: 'some value') }
52
+ let(:other) { Snmpjr::Response.new(oid: 'some oid', value: 'some value') }
46
53
  it 'returns true' do
47
- expect(described_class.new(value: 'some value')).to eq other
54
+ expect(described_class.new(oid: 'some oid', value: 'some value')).to eq other
48
55
  end
49
56
  end
50
57
 
51
58
  context 'when the objects are not equal' do
52
- let(:other) { Snmpjr::Response.new(error: 'some value') }
59
+ let(:other) { Snmpjr::Response.new(oid: 'some oid', error: 'some value') }
60
+ it 'returns true' do
61
+ expect(described_class.new(oid: 'some oid', error: 'some error')).to_not eq other
62
+ end
63
+ end
64
+
65
+ context 'when the oids are different' do
66
+ let(:other) { Snmpjr::Response.new(oid: 'some oid', error: 'some error') }
53
67
  it 'returns true' do
54
- expect(described_class.new(error: 'some error')).to_not eq other
68
+ expect(described_class.new(oid: 'another oid', error: 'some error')).to_not eq other
69
+ end
70
+ end
71
+
72
+ context 'when the objects are not of the same class' do
73
+ let(:other) { double :response }
74
+ before do
75
+ allow(other).to receive(:error).and_return ''
76
+ allow(other).to receive(:to_s).and_return 'some value'
77
+ allow(other).to receive(:oid).and_return 'some oid'
78
+ end
79
+
80
+ it 'returns false' do
81
+ expect(described_class.new(oid: 'some oid', value: 'some value')).to_not eq other
55
82
  end
56
83
  end
57
84
  end
@@ -24,7 +24,6 @@ describe Snmpjr::Session do
24
24
  subject.start
25
25
  expect(snmp_session).to have_received(:listen)
26
26
  end
27
-
28
27
  end
29
28
 
30
29
  describe '#send' do
@@ -38,8 +37,10 @@ describe Snmpjr::Session do
38
37
  before do
39
38
  allow(snmp_session).to receive(:send).and_return response
40
39
  allow(vb1).to receive_message_chain('variable.to_s')
40
+ allow(vb1).to receive_message_chain('oid.to_s')
41
41
  allow(vb1).to receive(:is_exception)
42
42
  allow(vb2).to receive_message_chain('variable.to_s')
43
+ allow(vb2).to receive_message_chain('oid.to_s')
43
44
  allow(vb2).to receive(:is_exception)
44
45
  allow(response).to receive_message_chain('response.variable_bindings').and_return(results)
45
46
  end
@@ -86,8 +86,8 @@ describe Snmpjr::Walker do
86
86
  end
87
87
 
88
88
  it 'performs a synchronous walk' do
89
- expect(subject.walk oid).to match_array [Snmpjr::Response.new(value: vb1.variable.to_s),
90
- Snmpjr::Response.new(value: vb2.variable.to_s)]
89
+ expect(subject.walk oid).to match_array [Snmpjr::Response.new(oid: vb1.oid.to_s, value: vb1.variable.to_s),
90
+ Snmpjr::Response.new(oid: vb2.oid.to_s, value: vb2.variable.to_s)]
91
91
  end
92
92
 
93
93
  it 'closes the snmp session' do
data/spec/snmpjr_spec.rb CHANGED
@@ -19,7 +19,6 @@ describe Snmpjr do
19
19
  allow(Snmpjr::Getter).to receive(:new).with(target: community_target, max_oids_per_request: 20).and_return getter
20
20
  end
21
21
 
22
-
23
22
  subject { described_class.new(agent_details.merge({max_oids_per_request: 20})) }
24
23
 
25
24
  context 'when passed a single oid' 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.2.1
4
+ version: 0.2.2
5
5
  platform: java
6
6
  authors:
7
7
  - Zen Kyprianou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-27 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-n-bake