snmpjr 0.1.3-java → 0.1.4-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
- NjVlOTJkNDZhYzNjZGY0Zjk2NDNiYWMzMGUzM2Q0Zjg5NDE0NDRlMA==
4
+ MmUwZDc1YTk1N2M5MzY5ZjAxODgwNTU3ZjgzMjVlZTE5MWM5MWU5Mg==
5
5
  data.tar.gz: !binary |-
6
- YTQ4ODM1YTQ1NDE2NjlkZmMzMGU5OGE1OTEwMGNiNzYwMWU2NjIwZQ==
6
+ ZTRlZmVhNTg0ODEyNDBmYTc4ODE3ZjUwZTNmNDMzY2VmYjY1MDk0ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzZiMzk2ZDJjMWNmNWE2OTg1NjY2YTcwMDAxODE3NGViODJkNzMwMmY0YmJh
10
- MmNhZTllMWQwM2M4OWVhYWRmMTkzMGM2NjcwNTk1ZjljNjYyMWNkMWZmMTIy
11
- YWFmNjIzNzMwN2Q4M2UyNTYxNTZiZWE5Mjg4ZDg2MTAyYTUyZTE=
9
+ YjY5MjZhNWEwZTE4MGJhNTgzZmFhODcwMDRiNTY0MjAzOGE5ODExMDg5Y2Rl
10
+ ZjhlMGZiNjJkYzcxZTQ0OWE2Y2RjMWE5Y2Q1NjhiZDdiMmY1ZTE1YmQ1NjI1
11
+ OTAzYzViMDQ4ZjExNmE5MjY3NDVmZjhlNzRhNGUzZGEwMjZiMjI=
12
12
  data.tar.gz: !binary |-
13
- Y2YyYmVhMzBmNTRmYzUzYjdkZGI3ZmI0MzIyMTQ1NjA1ODZmZjk3Y2NiNThl
14
- ZWQ5YjEzZjVjMjY3MjMxZTQ0NjJjNWNiMzAwZDQ3Y2M2NTUwMmQwM2IzYmUz
15
- ZWU5OWFjM2Y0NzEwMWUwNGU0NDc1NTA2OWRlMjQ3M2U1MzRlNzI=
13
+ MDNiMDE3MWM4NDUxMjIyZjZhZDBkZGQwZjViN2E5NWM4NGFjYWZkYWIyYWYy
14
+ MzgxNjU4MTgyODI1ODQ1YWQ2NWIwZDYwNjZiNGU4N2IwYjg4OTM2NWJlYzIw
15
+ M2EzNmU4MmI0MWZiZGU4OTIxY2E1YTc1MDQxMjA0MDQ2ZTU5NjU=
data/history.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.4 (14 October 2014)
2
+
3
+ * Returns a Response object rather than strings
4
+
1
5
  == 0.1.3 (13 October 2014)
2
6
 
3
7
  * Tweak the wording of the timeouts to show that its an error
@@ -0,0 +1,26 @@
1
+ class Snmpjr
2
+ class Response
3
+ attr_reader :error
4
+
5
+ def initialize response = {}
6
+ @error = response[:error] || ''
7
+ @value = response[:value] || ''
8
+ end
9
+
10
+ def error?
11
+ if @error.empty?
12
+ false
13
+ else
14
+ true
15
+ end
16
+ end
17
+
18
+ def to_s
19
+ @value
20
+ end
21
+
22
+ def ==(other)
23
+ @error == other.error && to_s == other.to_s
24
+ end
25
+ end
26
+ end
@@ -1,4 +1,5 @@
1
1
  require 'snmpjr/wrappers/transport'
2
+ require 'snmpjr/response'
2
3
 
3
4
  class Snmpjr
4
5
  class Session
@@ -15,12 +16,12 @@ class Snmpjr
15
16
  begin
16
17
  result = @snmp.send(pdu, target)
17
18
  if result.response.nil?
18
- "Error: Request timed out"
19
+ Snmpjr::Response.new(:error => 'Request timed out')
19
20
  else
20
- result.response.variable_bindings.first.variable.to_s
21
+ Snmpjr::Response.new(:value => result.response.variable_bindings.first.variable.to_s)
21
22
  end
22
- rescue Exception => e
23
- "Error: #{e.to_s}"
23
+ rescue Exception => error
24
+ Snmpjr::Response.new(:error => error.to_s)
24
25
  end
25
26
  end
26
27
 
@@ -1,3 +1,3 @@
1
1
  class Snmpjr
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'snmpjr'
2
+ require 'snmpjr/response'
2
3
 
3
4
  describe "snmpjr" do
4
5
 
@@ -7,20 +8,22 @@ describe "snmpjr" do
7
8
  subject { Snmpjr.new(:host => 'demo.snmplabs.com', :port => 161, :community => 'public') }
8
9
 
9
10
  it "can perform a simple synchronous get request on an snmp agent" do
10
- expect(subject.get '1.3.6.1.2.1.1.1.0').to eq 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'
11
+ 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')
11
12
  end
12
13
 
13
- let(:expected) { ['SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m', 'zeus.snmplabs.com'] }
14
+ let(:expected) { [Snmpjr::Response.new(:value => 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'),
15
+ Snmpjr::Response.new(:value => 'zeus.snmplabs.com')] }
14
16
  it "can perform a series of gets if passed an array of oids" do
15
17
  expect(subject.get ['1.3.6.1.2.1.1.1.0', '1.3.6.1.2.1.1.5.0']).to eq expected
16
18
  end
17
19
 
18
20
  context "when an invalid oid is requested" do
19
21
 
20
- let(:expected) { ['Error: Invalid first sub-identifier (must be 0, 1, or 2)', 'zeus.snmplabs.com'] }
22
+ let(:expected) { [Snmpjr::Response.new(:error => 'Invalid first sub-identifier (must be 0, 1, or 2)'),
23
+ Snmpjr::Response.new(:value => 'zeus.snmplabs.com')] }
24
+
21
25
  it "returns an error" do
22
26
  expect(subject.get ['6.5.4.3.2.1', '1.3.6.1.2.1.1.5.0']).to eq expected
23
-
24
27
  end
25
28
  end
26
29
  end
@@ -29,9 +32,8 @@ describe "snmpjr" do
29
32
  subject { Snmpjr.new(:host => 'example.com', :port => 161, :community => 'public') }
30
33
 
31
34
  it "the request times out after 5 seconds" do
32
- expect(subject.get '1.3.6.1.2.1.1.1.0').to eq 'Error: Request timed out'
35
+ expect(subject.get '1.3.6.1.2.1.1.1.0').to eq Snmpjr::Response.new(:error => 'Request timed out')
33
36
  end
34
37
  end
35
-
36
38
  end
37
39
  end
@@ -0,0 +1,58 @@
1
+ require production_code
2
+
3
+ describe Snmpjr::Response do
4
+
5
+ describe '.new' do
6
+ context 'when initialized with a value' do
7
+ it 'assigns that value' do
8
+ response = described_class.new(:value => 'Some value')
9
+ expect(response.to_s).to eq 'Some value'
10
+ end
11
+
12
+ it 'sets the error to an empty string' do
13
+ response = described_class.new(:value => 'Some value')
14
+ expect(response.error).to eq ''
15
+ end
16
+ end
17
+
18
+ context 'when initialized with an error' do
19
+ it 'assigns that error' do
20
+ response = described_class.new(:error => 'Some error')
21
+ expect(response.error).to eq 'Some error'
22
+ end
23
+
24
+ it 'sets the value to an empty string' do
25
+ response = described_class.new(:error => 'Some error')
26
+ expect(response.to_s).to eq ''
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#error?' do
32
+ it 'returns true if there is an error' do
33
+ response = described_class.new(:error => 'Some error')
34
+ expect(response.error?).to be_truthy
35
+ end
36
+
37
+ it 'returns false if there isnt an error' do
38
+ response = described_class.new(:value => 'Some value')
39
+ expect(response.error?).to be_falsey
40
+ end
41
+ end
42
+
43
+ describe '#==' do
44
+ context 'when the objects are equal' do
45
+ let(:other) { Snmpjr::Response.new(:value => 'some value') }
46
+ it 'returns true' do
47
+ expect(described_class.new(:value => 'some value')).to eq other
48
+ end
49
+ end
50
+
51
+ context 'when the objects are not equal' do
52
+ let(:other) { Snmpjr::Response.new(:error => 'some value') }
53
+ it 'returns true' do
54
+ expect(described_class.new(:error => 'some error')).to_not eq other
55
+ end
56
+ end
57
+ end
58
+ end
@@ -47,8 +47,9 @@ describe Snmpjr::Session do
47
47
  allow(result).to receive(:response).and_return nil
48
48
  end
49
49
 
50
+ let(:expected_response) { Snmpjr::Response.new(:error => 'Request timed out') }
50
51
  it 'returns a request timeout' do
51
- expect(subject.send(pdu, target)).to eq "Error: Request timed out"
52
+ expect(subject.send(pdu, target)).to eq expected_response
52
53
  end
53
54
  end
54
55
 
@@ -57,8 +58,9 @@ describe Snmpjr::Session do
57
58
  allow(snmp_session).to receive(:send).and_raise(RuntimeError.new('Some error'))
58
59
  end
59
60
 
61
+ let(:expected_response) { Snmpjr::Response.new(:error => 'Some error') }
60
62
  it 'returns the error without blowing up' do
61
- expect(subject.send(pdu, target)).to eq "Error: Some error"
63
+ expect(subject.send(pdu, target)).to eq expected_response
62
64
  end
63
65
  end
64
66
  end
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.1.3
4
+ version: 0.1.4
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-13 00:00:00.000000000 Z
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ! 'Snmpjr aims to provide a clean and simple interface to use SNMP in
14
14
  your ruby code. It will wrap the popular SNMP4J library in Java.
@@ -32,6 +32,7 @@ files:
32
32
  - lib/snmpjr.rb
33
33
  - lib/snmpjr/getter.rb
34
34
  - lib/snmpjr/pdu.rb
35
+ - lib/snmpjr/response.rb
35
36
  - lib/snmpjr/session.rb
36
37
  - lib/snmpjr/target.rb
37
38
  - lib/snmpjr/version.rb
@@ -43,6 +44,7 @@ files:
43
44
  - spec/integration/snmpjr_spec.rb
44
45
  - spec/snmpjr/getter_spec.rb
45
46
  - spec/snmpjr/pdu_spec.rb
47
+ - spec/snmpjr/response_spec.rb
46
48
  - spec/snmpjr/session_spec.rb
47
49
  - spec/snmpjr/target_spec.rb
48
50
  - spec/snmpjr_spec.rb
@@ -75,6 +77,7 @@ test_files:
75
77
  - spec/integration/snmpjr_spec.rb
76
78
  - spec/snmpjr/getter_spec.rb
77
79
  - spec/snmpjr/pdu_spec.rb
80
+ - spec/snmpjr/response_spec.rb
78
81
  - spec/snmpjr/session_spec.rb
79
82
  - spec/snmpjr/target_spec.rb
80
83
  - spec/snmpjr_spec.rb