net-snmp2 0.3.0 → 0.3.1

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -1
  3. data/examples/agent.rb +1 -0
  4. data/examples/inform.rb +23 -0
  5. data/examples/trap_handler.rb +15 -0
  6. data/examples/{v1_trap_session.rb → v1_trap.rb} +2 -7
  7. data/examples/{v2_trap_session.rb → v2_trap.rb} +2 -7
  8. data/history.md +17 -0
  9. data/lib/net-snmp2.rb +1 -1
  10. data/lib/net/snmp/agent/agent.rb +44 -13
  11. data/lib/net/snmp/agent/provider.rb +56 -1
  12. data/lib/net/snmp/agent/provider_dsl.rb +11 -0
  13. data/lib/net/snmp/debug.rb +10 -19
  14. data/lib/net/snmp/error.rb +13 -6
  15. data/lib/net/snmp/listener.rb +2 -4
  16. data/lib/net/snmp/message.rb +52 -25
  17. data/lib/net/snmp/mib/mib.rb +2 -1
  18. data/lib/net/snmp/mib/node.rb +1 -1
  19. data/lib/net/snmp/oid.rb +5 -2
  20. data/lib/net/snmp/pdu.rb +15 -10
  21. data/lib/net/snmp/repl/manager_repl.rb +20 -7
  22. data/lib/net/snmp/session.rb +78 -45
  23. data/lib/net/snmp/trap_handler/trap_handler.rb +13 -9
  24. data/lib/net/snmp/trap_handler/v2_inform_dsl.rb +16 -0
  25. data/lib/net/snmp/trap_session.rb +64 -42
  26. data/lib/net/snmp/version.rb +1 -1
  27. data/lib/net/snmp/wrapper.rb +2 -8
  28. data/net-snmp2.gemspec +1 -1
  29. data/spec/README.md +36 -40
  30. data/spec/async_spec.rb +92 -87
  31. data/spec/em_spec.rb +3 -3
  32. data/spec/error_spec.rb +2 -2
  33. data/spec/fiber_spec.rb +8 -7
  34. data/spec/mib_spec.rb +8 -8
  35. data/spec/net-snmp_spec.rb +3 -3
  36. data/spec/oid_spec.rb +5 -5
  37. data/spec/spec_helper.rb +5 -0
  38. data/spec/sync_spec.rb +50 -56
  39. data/spec/test_agent.rb +150 -0
  40. data/spec/test_mib.rb +6 -0
  41. data/spec/thread_spec.rb +4 -4
  42. data/spec/trap_spec.rb +3 -12
  43. data/spec/utility_spec.rb +4 -4
  44. data/spec/wrapper_spec.rb +6 -6
  45. metadata +11 -6
  46. data/lib/net/snmp/agent/request_dispatcher.rb +0 -38
@@ -3,13 +3,9 @@ module Net::SNMP
3
3
  include Net::SNMP::Debug
4
4
  extend Forwardable
5
5
 
6
- attr_accessor :listener, :v1_handler, :v2_handler, :message, :pdu
6
+ attr_accessor :listener, :v1_handler, :v2_handler, :inform_handler, :message, :pdu
7
7
  def_delegators :listener, :start, :run, :listen, :stop, :kill
8
8
 
9
- def self.listen(port = 162, interval = 2, max_packet_size = 65_000, &block)
10
- self.new
11
- end
12
-
13
9
  def initialize(&block)
14
10
  @listener = Net::SNMP::Listener.new
15
11
  @listener.on_message(&method(:process_trap))
@@ -18,15 +14,19 @@ module Net::SNMP
18
14
 
19
15
  private
20
16
 
21
- def process_trap(message, from_address, from_port)
22
- if message.pdu.command == Net::SNMP::Constants::SNMP_MSG_TRAP
17
+ def process_trap(message)
18
+ case message.pdu.command
19
+ when Constants::SNMP_MSG_TRAP
23
20
  handler = V1TrapDsl.new(message)
24
21
  handler.instance_eval(&v1_handler)
25
- elsif message.pdu.command == Net::SNMP::Constants::SNMP_MSG_TRAP2
22
+ when Constants::SNMP_MSG_TRAP2
26
23
  handler = V2TrapDsl.new(message)
27
24
  handler.instance_eval(&v2_handler)
25
+ when Constants::SNMP_MSG_INFORM
26
+ handler = V2InformDsl.new(message)
27
+ handler.instance_eval(&inform_handler)
28
28
  else
29
- warn "Trap handler receive invalid command: #{message.pdu.command}"
29
+ warn "Trap handler received non-trap PDU. Command type was: #{message.pdu.command}"
30
30
  end
31
31
  message.pdu.free
32
32
  end
@@ -38,5 +38,9 @@ module Net::SNMP
38
38
  def v2(&handler)
39
39
  @v2_handler = handler
40
40
  end
41
+
42
+ def inform(&handler)
43
+ @inform_handler = handler
44
+ end
41
45
  end
42
46
  end
@@ -0,0 +1,16 @@
1
+ module Net::SNMP
2
+ class V2InformDsl < V2TrapDsl
3
+ include Debug
4
+
5
+ attr_accessor :response
6
+
7
+ def initialize(message)
8
+ super
9
+ end
10
+
11
+ def ok
12
+ message.echo
13
+ end
14
+
15
+ end
16
+ end
@@ -3,9 +3,10 @@ module Net
3
3
  class TrapSession < Session
4
4
  # == Represents a session for sending SNMP traps
5
5
 
6
- # +options+
7
- # * :peername The address where the trap will be sent
8
- # * :port The port where the trap will be sent (default = 162)
6
+ # Options
7
+ #
8
+ # - peername: The address where the trap will be sent
9
+ # - port: The port where the trap will be sent (default = 162)
9
10
  def initialize(options = {})
10
11
  # Unless the port was supplied in the peername...
11
12
  unless options[:peername][":"]
@@ -20,11 +21,62 @@ module Net
20
21
  #
21
22
  # Options
22
23
  #
23
- # - enterprise: The Oid of the enterprise
24
- # - trap_type: The generic trap type.
24
+ # - enterprise: The Oid of the enterprise
25
+ # - trap_type: The generic trap type.
25
26
  # - specific_type: The specific trap type
26
- # - uptime: The uptime for this agent
27
+ # - uptime: The uptime for this agent
27
28
  def trap(options = {})
29
+ pdu = build_v1_trap_pdu(options)
30
+ send_pdu(pdu)
31
+ end
32
+
33
+ # Send an SNMPv2 trap
34
+ #
35
+ # Options
36
+ #
37
+ # - oid: The OID of the inform
38
+ # - uptime: Integer indicating the uptime of this agent
39
+ #
40
+ # TODO: You can only send v1 traps on a v1 session, and same for v2.
41
+ # So, we could always have the client call `trap` and just do the right
42
+ # thing based on the session.
43
+ def trap_v2(options = {})
44
+ pdu = build_v2_trap_pdu(Constants::SNMP_MSG_TRAP2, options)
45
+ send_pdu(pdu)
46
+ end
47
+
48
+ # Send an SNMPv2 inform
49
+ #
50
+ # Options
51
+ #
52
+ # - oid: The OID of the inform
53
+ # - uptime: Integer indicating the uptime of this agent
54
+ # - varbinds: An array of hashes, like those used for PDU#add_varbind
55
+ def inform(options = {})
56
+ pdu = build_v2_trap_pdu(Constants::SNMP_MSG_INFORM, options)
57
+ response = send_pdu(pdu)
58
+ if response.kind_of?(PDU)
59
+ response.free # Always free the response PDU
60
+ :success # If Session#send_pdu didn't raise, we succeeded
61
+ else
62
+ # If the result was other than a PDU, that's a problem
63
+ raise "Unexpected response type for inform: #{response.class}"
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def send_pdu(pdu)
70
+ result = super(pdu)
71
+ if pdu.command == Constants::SNMP_MSG_INFORM
72
+ pdu.free_own_memory
73
+ else
74
+ pdu.free
75
+ end
76
+ result
77
+ end
78
+
79
+ def build_v1_trap_pdu(options = {})
28
80
  pdu = PDU.new(Constants::SNMP_MSG_TRAP)
29
81
  options[:enterprise] ||= '1.3.6.1.4.1.3.1.1'
30
82
  pdu.enterprise = OID.new(options[:enterprise].to_s)
@@ -37,48 +89,16 @@ module Net
37
89
  pdu.add_varbind(vb)
38
90
  end
39
91
  end
40
- result = send_pdu(pdu)
41
- pdu.free
42
- result
92
+ pdu
43
93
  end
44
94
 
45
- # Send an SNMPv2 trap
46
- # +options
47
- # * :oid The Oid of the trap
48
- # * :varbinds A list of Varbind objects to send with the trap
49
- #
50
- # TODO: You can only send v1 traps on a v1 session, and same for v2.
51
- # So, we could always have the client call `trap` and just do the right
52
- # thing based on the session.
53
- def trap_v2(options = {})
95
+ def build_v2_trap_pdu(pdu_type, options = {})
54
96
  if options[:oid].kind_of?(String)
55
97
  options[:oid] = Net::SNMP::OID.new(options[:oid])
56
98
  end
57
- pdu = PDU.new(Constants::SNMP_MSG_TRAP2)
58
- build_trap_pdu(pdu, options)
59
- result = send_pdu(pdu)
60
- pdu.free
61
- result
62
- end
63
-
64
- # Send an SNMPv2 inform. Can accept a callback to execute on confirmation of the inform
65
- # +options
66
- # * :oid The OID of the inform
67
- # * :varbinds A list of Varbind objects to send with the inform
68
- def inform(options = {}, &callback)
69
- if options[:oid].kind_of?(String)
70
- options[:oid] = Net::SNMP::OID.new(options[:oid])
71
- end
72
- pdu = PDU.new(Constants::SNMP_MSG_INFORM)
73
- build_trap_pdu(pdu, options)
74
- result = send_pdu(pdu, &callback)
75
- pdu.free
76
- result
77
- end
78
-
79
- private
80
- def build_trap_pdu(pdu, options = {})
81
99
  options[:uptime] ||= 1
100
+
101
+ pdu = PDU.new(pdu_type)
82
102
  pdu.add_varbind(:oid => OID.new('sysUpTime.0'), :type => Constants::ASN_TIMETICKS, :value => options[:uptime].to_i)
83
103
  pdu.add_varbind(:oid => OID.new('snmpTrapOID.0'), :type => Constants::ASN_OBJECT_ID, :value => options[:oid])
84
104
  if options[:varbinds]
@@ -86,7 +106,9 @@ module Net
86
106
  pdu.add_varbind(vb)
87
107
  end
88
108
  end
109
+ pdu
89
110
  end
111
+
90
112
  end
91
113
  end
92
114
  end
@@ -1,5 +1,5 @@
1
1
  module Net
2
2
  module SNMP
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -282,7 +282,7 @@ module Wrapper
282
282
  attach_function :snmp_oidsubtree_compare, [ :pointer, :uint, :pointer, :uint ], :int
283
283
  attach_function :netsnmp_oid_compare_ll, [ :pointer, :uint, :pointer, :uint, :pointer ], :int
284
284
  attach_function :netsnmp_oid_equals, [ :pointer, :uint, :pointer, :uint ], :int
285
- attach_function :netsnmp_oid_tree_equals, [ :pointer, :uint, :pointer, :uint ], :int
285
+ attach_function :netsnmp_oid_tree_equals, [ :pointer, :size_t, :pointer, :size_t ], :int
286
286
  attach_function :netsnmp_oid_is_subtree, [ :pointer, :uint, :pointer, :uint ], :int
287
287
  attach_function :netsnmp_oid_find_prefix, [ :pointer, :uint, :pointer, :uint ], :int
288
288
  attach_function :netsnmp_transport_open_client, [:string, :pointer], :pointer
@@ -290,7 +290,7 @@ module Wrapper
290
290
  attach_function :snmp_pdu_build, [ :pointer, :pointer, :pointer ], :pointer
291
291
  attach_function :snmpv3_parse, [ :pointer, :pointer, :pointer, :pointer, :pointer ], :int
292
292
  attach_function :snmpv3_packet_build, [ :pointer, :pointer, :pointer, :pointer, :pointer, :uint ], :int
293
- attach_function :snmpv3_packet_rbuild, [ :pointer, :pointer, :pointer, :pointer, :pointer, :uint ], :int
293
+ attach_function :snmpv3_packet_rbuild, [ :pointer, :pointer, :pointer, :pointer, :pointer, :size_t ], :int
294
294
  attach_function :snmpv3_make_report, [ :pointer, :int ], :int
295
295
  attach_function :snmpv3_get_report_type, [ :pointer ], :int
296
296
  attach_function :snmp_pdu_parse, [ :pointer, :pointer, :pointer ], :int
@@ -306,7 +306,6 @@ module Wrapper
306
306
  attach_function :snmp_get_statistic, [ :int ], :u_int
307
307
  attach_function :snmp_init_statistics, [ ], :void
308
308
  attach_function :create_user_from_session, [ :pointer ], :int
309
- attach_function :snmp_get_fd_for_session, [ :pointer ], :int
310
309
  attach_function :snmp_open_ex, [ :pointer, callback([ :pointer, :pointer, :pointer, :int ], :int), callback([ :pointer, :pointer, :pointer, :uint ], :int), callback([ :pointer, :pointer, :int ], :int), callback([ :pointer, :pointer, :pointer, :pointer ], :int), callback([ :pointer, :pointer, :pointer, :pointer, :pointer ], :int), callback([ :pointer, :uint ], :int) ], :pointer
311
310
  attach_function :snmp_set_do_debugging, [ :int ], :void
312
311
  attach_function :snmp_get_do_debugging, [ ], :int
@@ -389,11 +388,6 @@ module Wrapper
389
388
  # struct module *find_module(int modid);
390
389
  attach_function :find_module, [:int], Module.typed_pointer
391
390
 
392
- # Trap functions
393
- attach_function :send_easy_trap, [:int, :int], :void
394
- attach_function :send_trap_vars, [:int, :int, :pointer], :void
395
- attach_function :send_v2trap, [:pointer], :void
396
-
397
391
  def self.get_fd_set
398
392
  FFI::MemoryPointer.new(:pointer, 128)
399
393
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  # Documentation options
22
22
  s.has_rdoc = true
23
23
  s.extra_rdoc_files = %w{ README.md }
24
- s.rdoc_options = ["--main=README.md", "--line-numbers", "--inline-source", "--title=#{s.name}-#{s.version} Documentation"]
24
+ s.rdoc_options = ["--main=README.md", "--markup=markdown", "--line-numbers", "--inline-source", "--title=#{s.name}-#{s.version} Documentation"]
25
25
 
26
26
  s.add_dependency 'nice-ffi'
27
27
  s.add_dependency 'pry'
@@ -1,10 +1,9 @@
1
1
  Notes
2
2
  -----
3
3
 
4
- - To test sets, you have to have a local snmpd running with write permissions
5
- - For your local agent, use read community "public" & write community "private"
6
- - A free simulator can be downloaded from [veraxsystems](http://www.veraxsystems.com/en/products/free-snmp-agent-simulator)
7
- + TODO: This simulator could be used to replace the dependency on test.net-snmp.org
4
+ - For the tests to run, you must first run `ruby spec/test_agent.r`
5
+ - You also need to run an external trap receiver
6
+ + I'm currently using MIBBrowser's builtin receiver
8
7
 
9
8
  Latest Results
10
9
  --------------
@@ -14,16 +13,14 @@ Generated with `rspec -f d -o spec/spec.txt --no-color`
14
13
  ```
15
14
  async
16
15
  version 1
17
- get should work
18
- get should return an error
19
16
  getnext should work
17
+ get
18
+ retrieves scalar values
19
+ when a timeout occurrs
20
+ calls back with :timeout when a timeout occurrs
20
21
  version 2
21
22
  get should work
22
23
  getnext should work
23
- version 3
24
- should get async using snmpv3
25
- get should work
26
- getnext should work
27
24
 
28
25
  em
29
26
  should work in event_machine
@@ -35,16 +32,28 @@ snmp errors
35
32
  in fiber
36
33
  get should work in a fiber with synchronous calling style
37
34
  getnext
38
- should get using snmpv3
35
+ should get using snmpv3 (PENDING: No reason given)
36
+
37
+ Net::SNMP::MIB
38
+ ::translate
39
+ translates OIDs to variable names including instance indexes
40
+ translates variable names to OIDs including instance indexes
41
+ ::[]
42
+ can retrieve MIB nodes by variable name
43
+ can retrieve MIB nodes by numeric oid
39
44
 
40
45
  Net::SNMP::MIB::Node
41
- should get info for sysDescr
42
- should get parent
43
- should get node children
44
- should get siblings
45
- should get oid
46
- should get by oid
47
- should do stuff
46
+ ::get_node
47
+ retrieves MIB nodes by variable name
48
+ retrieves MIB nodes by numeric oid
49
+ #parent
50
+ links to the parent node
51
+ #children
52
+ contains Node objects for all child nodes
53
+ #siblings
54
+ contains an array of sibling nodes
55
+ #oid
56
+ is an OID object for the node
48
57
 
49
58
  Net::SNMP::OID
50
59
  should instantiate valid oid with numeric
@@ -60,24 +69,20 @@ synchronous calls
60
69
  getnext should succeed
61
70
  getbulk should succeed
62
71
  getbulk should succeed with multiple oids
63
- get should return error with invalid oid
72
+ rasises an when a non-existant MIB variable is requested
64
73
  get_table should work
65
74
  walk should work
66
75
  walk should work with multiple oids
67
76
  get_columns should work
68
77
  get a value with oid type should work
69
- version 3
70
- should get using snmpv3
71
- should set using snmpv3 (PENDING: No reason given)
72
- should get using authpriv (PENDING: No reason given)
73
78
 
74
79
  in a thread
75
80
  should get an oid asynchronously in a thread
76
81
 
77
- snmp traps
82
+ Net::SNMP::TrapSession
78
83
  should send a v1 trap
79
- should send a v2 inform (PENDING: still working on it)
80
- should send v2 trap (PENDING: still working on it)
84
+ should send v2 trap
85
+ should send a v2 inform
81
86
 
82
87
  Net::SNMP::Utility
83
88
  should compare oids
@@ -87,19 +92,10 @@ Net::SNMP::Wrapper
87
92
  wrapper should snmpget asynchronously
88
93
 
89
94
  Pending:
90
- synchronous calls version 3 should set using snmpv3
91
- # No reason given
92
- # ./spec/sync_spec.rb:117
93
- synchronous calls version 3 should get using authpriv
95
+ in fiber should get using snmpv3
94
96
  # No reason given
95
- # ./spec/sync_spec.rb:125
96
- snmp traps should send a v2 inform
97
- # still working on it
98
- # ./spec/trap_spec.rb:14
99
- snmp traps should send v2 trap
100
- # still working on it
101
- # ./spec/trap_spec.rb:26
102
-
103
- Finished in 25.41 seconds (files took 0.38735 seconds to load)
104
- 47 examples, 0 failures, 4 pending
97
+ # ./spec/fiber_spec.rb:32
98
+
99
+ Finished in 29.01 seconds (files took 0.34884 seconds to load)
100
+ 44 examples, 0 failures, 1 pending
105
101
  ```
@@ -1,123 +1,128 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require_relative './spec_helper'
2
2
 
3
3
  describe "async" do
4
4
  context "version 1" do
5
- it "get should work" do
6
- did_callback = false
7
- sess = Net::SNMP::Session.open(:peername => 'test.net-snmp.org', :community => 'demopublic') do |s|
8
- s.get(["sysDescr.0", "sysContact.0"]) do |op, pdu|
9
- did_callback = true
10
- pdu.varbinds[0].value.should eql("test.net-snmp.org")
11
- pdu.varbinds[1].value.should match(/Coders/)
5
+
6
+ describe 'get' do
7
+ it "retrieves scalar values" do
8
+ did_callback = false
9
+ sess = Net::SNMP::Session.open(:peername => 'localhost', port: 161, :community => 'public', version: '2c') do |s|
10
+ s.get(["sysDescr.0", "sysContact.0"]) do |op, pdu|
11
+ did_callback = true
12
+ expect(pdu.varbinds[0].value).to eq($test_mib['sysDescr.0'])
13
+ expect(pdu.varbinds[1].value).to eq($test_mib['sysContact.0'])
14
+ end
12
15
  end
16
+ Net::SNMP::Dispatcher.select(false)
17
+ expect(did_callback).to be(true)
13
18
  end
14
- Net::SNMP::Dispatcher.select(false)
15
- did_callback.should be(true)
16
- end
17
19
 
18
- it "get should return an error" do
19
- did_callback = false
20
- sess = Net::SNMP::Session.open(:peername => 'www.yahoo.com', :timeout => 1, :retries => 0) do |sess|
21
- sess.get("sysDescr.0") do |op, pdu|
22
- did_callback = true
23
- op.should eql(:timeout)
20
+ context "when a timeout occurrs" do
21
+ it "calls back with :timeout when a timeout occurrs" do
22
+ did_callback = false
23
+ sess = Net::SNMP::Session.open(:peername => 'www.yahoo.com', :timeout => 1, :retries => 0) do |sess|
24
+ sess.get("sysDescr.0") do |op, pdu|
25
+ did_callback = true
26
+ expect(op).to eql(:timeout)
27
+ end
28
+ end
29
+ sleep 2
30
+ num_ready = sess.select(10)
31
+ expect(num_ready).to eql(0)
32
+ expect(did_callback).to eq(true)
24
33
  end
25
34
  end
26
- sleep 2
27
- pdu = sess.select(10)
28
-
29
- pdu.should eql(0)
30
- did_callback.should eq(true)
31
35
  end
32
36
 
33
- it "getnext should work" do
34
- did_callback = false
35
- Net::SNMP::Session.open(:peername => 'test.net-snmp.org', :community => 'demopublic') do |s|
36
- s.get_next(["sysDescr", "sysContact"]) do |op, pdu|
37
- did_callback = true
38
- pdu.varbinds[0].value.should eql("test.net-snmp.org")
39
- pdu.varbinds[1].value.should match(/Coders/)
37
+ describe 'get_next'
38
+ it "getnext should work" do
39
+ did_callback = false
40
+ Net::SNMP::Session.open(:peername => 'localhost', :community => 'public', version: '2c') do |s|
41
+ s.get_next(["sysDescr", "sysContact"]) do |op, pdu|
42
+ did_callback = true
43
+ expect(pdu.varbinds[0].value).to eq $test_mib['sysDescr.0']
44
+ expect(pdu.varbinds[1].value).to eq $test_mib['sysContact.0']
45
+ end
40
46
  end
47
+ Net::SNMP::Dispatcher.select(false)
48
+ expect(did_callback).to be(true)
41
49
  end
42
- Net::SNMP::Dispatcher.select(false)
43
- did_callback.should be(true)
44
50
  end
45
- end
46
51
 
47
52
  context "version 2" do
48
53
  it "get should work" do
49
54
  did_callback = false
50
- Net::SNMP::Session.open(:peername => 'test.net-snmp.org', :community => 'demopublic', :version => '2c') do |s|
55
+ Net::SNMP::Session.open(:peername => 'localhost', :community => 'public', :version => '2c') do |s|
51
56
  s.get(["sysDescr.0", "sysContact.0"]) do |op, pdu|
52
57
  did_callback = true
53
- pdu.varbinds[0].value.should eql("test.net-snmp.org")
54
- pdu.varbinds[1].value.should match(/Coders/)
58
+ expect(pdu.varbinds[0].value).to eq $test_mib['sysDescr.0']
59
+ expect(pdu.varbinds[1].value).to eq $test_mib['sysContact.0']
55
60
  end
56
61
  end
57
62
  Net::SNMP::Dispatcher.select(false)
58
- did_callback.should be(true)
63
+ expect(did_callback).to be(true)
59
64
  end
60
65
 
61
66
  it "getnext should work" do
62
67
  did_callback = false
63
- Net::SNMP::Session.open(:peername => 'test.net-snmp.org', :community => 'demopublic', :version => '2c') do |s|
68
+ Net::SNMP::Session.open(:peername => 'localhost', :community => 'public', :version => '2c') do |s|
64
69
  s.get_next(["sysDescr", "sysContact"]) do |op, pdu|
65
70
  did_callback = true
66
- pdu.varbinds[0].value.should eql("test.net-snmp.org")
67
- pdu.varbinds[1].value.should match(/Coders/)
71
+ expect(pdu.varbinds[0].value).to eq $test_mib['sysDescr.0']
72
+ expect(pdu.varbinds[1].value).to eq $test_mib['sysContact.0']
68
73
  end
69
74
  end
70
75
  Net::SNMP::Dispatcher.select(false)
71
- did_callback.should be(true)
76
+ expect(did_callback).to be(true)
72
77
  end
73
78
 
74
79
  end
75
80
 
76
- context "version 3" do
77
- #failing intermittently
78
- it "should get async using snmpv3" do
79
- did_callback = false
80
- Net::SNMP::Session.open(:peername => 'test.net-snmp.org', :version => 3, :username => 'MD5User',:security_level => Net::SNMP::Constants::SNMP_SEC_LEVEL_AUTHNOPRIV, :auth_protocol => :md5, :password => 'The Net-SNMP Demo Password') do |sess|
81
- sess.get(["sysDescr.0"]) do |op, pdu|
82
- did_callback = true
83
- pdu.varbinds[0].value.should eql('test.net-snmp.org')
84
- end
85
- sleep(0.5)
86
- Net::SNMP::Dispatcher.select(false)
87
- #Net::SNMP::Dispatcher.select(false)
88
- #puts "done select"
89
- did_callback.should be(true)
90
- end
91
- end
92
-
93
- it "get should work" do
94
- did_callback = false
95
- sess = Net::SNMP::Session.open(:peername => 'test.net-snmp.org', :version => 3, :username => 'MD5User',:security_level => Net::SNMP::Constants::SNMP_SEC_LEVEL_AUTHNOPRIV, :auth_protocol => :md5, :password => 'The Net-SNMP Demo Password') do |sess|
96
- sess.get(["sysDescr.0", "sysContact.0"]) do |op,pdu|
97
- did_callback = true
98
- pdu.varbinds[0].value.should eql("test.net-snmp.org")
99
- pdu.varbinds[1].value.should match(/Coders/)
100
- end
101
- end
102
- Net::SNMP::Dispatcher.select(false)
103
- sess.close
104
- did_callback.should be(true)
105
- end
106
-
107
- # XXX occasionally segfaulting
108
- it "getnext should work" do
109
- did_callback = false
110
-
111
- sess = Net::SNMP::Session.open(:peername => 'test.net-snmp.org', :version => 3, :username => 'MD5User',:security_level => Net::SNMP::Constants::SNMP_SEC_LEVEL_AUTHNOPRIV, :auth_protocol => :md5, :password => 'The Net-SNMP Demo Password') do |sess|
112
- sess.get_next(["sysDescr", "sysContact"]) do |op, pdu|
113
- did_callback = true
114
- pdu.varbinds[0].value.should eql("test.net-snmp.org")
115
- pdu.varbinds[1].value.should match(/Coders/)
116
- end
117
- end
118
- Net::SNMP::Dispatcher.select(false)
119
- sess.close
120
- did_callback.should be(true)
121
- end
122
- end
81
+ # context "version 3" do
82
+ # #failing intermittently
83
+ # it "should get async using snmpv3" do
84
+ # did_callback = false
85
+ # Net::SNMP::Session.open(:peername => 'localhost', :version => 3, :username => 'MD5User',:security_level => Net::SNMP::Constants::SNMP_SEC_LEVEL_AUTHNOPRIV, :auth_protocol => :md5, :password => 'The Net-SNMP Demo Password') do |sess|
86
+ # sess.get(["sysDescr.0"]) do |op, pdu|
87
+ # did_callback = true
88
+ # expect(pdu.varbinds[0].value).to eql("Linux nmsworker-devel 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64")
89
+ # end
90
+ # sleep(0.5)
91
+ # Net::SNMP::Dispatcher.select(false)
92
+ # #Net::SNMP::Dispatcher.select(false)
93
+ # #puts "done select"
94
+ # expect(did_callback).to be(true)
95
+ # end
96
+ # end
97
+ #
98
+ # it "get should work" do
99
+ # did_callback = false
100
+ # sess = Net::SNMP::Session.open(:peername => 'localhost', :version => 3, :username => 'MD5User',:security_level => Net::SNMP::Constants::SNMP_SEC_LEVEL_AUTHNOPRIV, :auth_protocol => :md5, :password => 'The Net-SNMP Demo Password') do |sess|
101
+ # sess.get(["sysDescr.0", "sysContact.0"]) do |op,pdu|
102
+ # did_callback = true
103
+ # expect(pdu.varbinds[0].value).to eql("Linux nmsworker-devel 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64")
104
+ # expect(pdu.varbinds[1].value).to eql("Root <root@localhost> (configure /etc/snmp/snmp.local.conf)")
105
+ # end
106
+ # end
107
+ # Net::SNMP::Dispatcher.select(false)
108
+ # sess.close
109
+ # expect(did_callback).to be(true)
110
+ # end
111
+ #
112
+ # # XXX occasionally segfaulting
113
+ # it "getnext should work" do
114
+ # did_callback = false
115
+ #
116
+ # sess = Net::SNMP::Session.open(:peername => 'localhost', :version => 3, :username => 'MD5User',:security_level => Net::SNMP::Constants::SNMP_SEC_LEVEL_AUTHNOPRIV, :auth_protocol => :md5, :password => 'The Net-SNMP Demo Password') do |sess|
117
+ # sess.get_next(["sysDescr", "sysContact"]) do |op, pdu|
118
+ # did_callback = true
119
+ # expect(pdu.varbinds[0].value).to eql("Linux nmsworker-devel 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64")
120
+ # expect(pdu.varbinds[1].value).to eql("Root <root@localhost> (configure /etc/snmp/snmp.local.conf)")
121
+ # end
122
+ # end
123
+ # Net::SNMP::Dispatcher.select(false)
124
+ # sess.close
125
+ # expect(did_callback).to be(true)
126
+ # end
127
+ #end
123
128
  end