Skip to content

Commit

Permalink
Support ASN.1 types for SNMP walk
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Lesser committed Jan 14, 2015
1 parent 64a021a commit 85acd82
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/snmpjr/walker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def walk oid

def extract_variable_bindings variable_bindings
variable_bindings.flat_map {|vb|
Snmpjr::Response.new(oid: vb.oid.to_s, value: vb.variable.to_s)
Snmpjr::Response.new(oid: vb.oid.to_s, value: vb.variable.to_s, type: vb.variable.syntax_string)
}
end

Expand Down
5 changes: 3 additions & 2 deletions spec/integration/snmp_v2c/snmpjr_walk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
it 'can perform a simple synchronous walk request on an snmp agent' do
response = subject.walk '1.3.6.1.2.1.1'
expect(response.count).to eq 11
expect(response.first.to_s).to eq 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'
expect(response.last.to_s).to match(/^\d+\:\d+:\d+\.\d+$/)
expect(response.first.to_h).to eq(
{ oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m', type: 'OCTET STRING' }
)
end

context "when a non existent subtree is walked" do
Expand Down
5 changes: 3 additions & 2 deletions spec/integration/snmp_v3/snmpjr_walk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
it 'can perform a simple synchronous walk request on an snmp agent' do
response = subject.walk '1.3.6.1.2.1.1'
expect(response.count).to eq 11
expect(response.first.to_s).to eq 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'
expect(response.last.to_s).to match(/^\d+\:\d+:\d+\.\d+$/)
expect(response.first.to_h).to eq(
{ oid: '1.3.6.1.2.1.1.1.0', value: 'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m', type: 'OCTET STRING' }
)
end

context "when a non existent subtree is walked" do
Expand Down
7 changes: 5 additions & 2 deletions spec/snmpjr/walker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
before do
allow(tree_util).to receive(:getSubtree).with(target, oid).and_raise Exception.new 'noAccess'
end

it 'raises a runtime error' do
expect{
subject.walk oid
Expand All @@ -49,6 +50,7 @@

context 'when a target times out' do
let(:tree_event_1) { double :tree_event_1 }

before do
allow(tree_event_1).to receive(:is_error?).and_return true
allow(tree_event_1).to receive(:error_message).and_return 'Request timed out.'
Expand All @@ -63,6 +65,7 @@

context 'when a random error occurs' do
let(:tree_event_1) { double :tree_event_1 }

before do
allow(tree_event_1).to receive(:is_error?).and_return true
allow(tree_event_1).to receive(:error_message).and_return 'noAccess'
Expand All @@ -85,8 +88,8 @@
end

it 'performs a synchronous walk' do
expect(subject.walk oid).to match_array [Snmpjr::Response.new(oid: vb1.oid.to_s, value: vb1.variable.to_s),
Snmpjr::Response.new(oid: vb2.oid.to_s, value: vb2.variable.to_s)]
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),
Snmpjr::Response.new(oid: vb2.oid.to_s, value: vb2.variable.to_s, type: vb1.variable.syntax_string)]
end

it 'closes the snmp session' do
Expand Down

0 comments on commit 85acd82

Please sign in to comment.