snmp4em 1.0.1 → 1.0.2

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.
data/README.rdoc CHANGED
@@ -7,7 +7,7 @@ This gem extends Ruby-SNMP[http://snmplib.rubyforge.org] to use the asynchronous
7
7
 
8
8
  == Features
9
9
 
10
- Version 1.0.0 supports:
10
+ The library currently supports:
11
11
 
12
12
  * SNMP v1 and v2
13
13
  * SNMP Get, GetNext, Set, and Walk requests. For SNMPv2 clients, GetBulk and WalkBulk
@@ -17,7 +17,29 @@ Future revisions of this library may support:
17
17
 
18
18
  * Ability to act as an SNMP agent, responding to external queries.
19
19
 
20
- There are no plans to support SNMP v3.
20
+ There are no plans to support SNMP v3 or the parsing of MIB files.
21
+
22
+
23
+ == Options
24
+
25
+ You may set the following options:
26
+
27
+ SNMP4EM::Manager.new(
28
+ :version => :SNMPv2c,
29
+ :host => "127.0.0.1",
30
+ :port => 161,
31
+ :community => "public", # Shorthand for setting both :community_ro and :community_rw
32
+ :community_ro => "public",
33
+ :community_rw => "public",
34
+ :timeout => 1,
35
+ :retries => 3 # Can also be specified as an array of individual timeouts
36
+ # For instance, [0.5, 1, 2.5] would send three requests with increasing timeout values
37
+ )
38
+
39
+ These options may also be passed to an individual query method, for instance:
40
+
41
+ snmp = SNMP4EM::Manager.new(...)
42
+ snmp.get(OID, :retries => 2, :timeout => 1)
21
43
 
22
44
 
23
45
  == Backwards compatibility
@@ -162,6 +184,10 @@ A simple SNMP-GET-BULK:
162
184
 
163
185
  == Change Log
164
186
 
187
+ Version 1.0.2:
188
+
189
+ * Ability to specify timeouts as an array of timeout values. Inspired by https://github.com/calmh/node-snmp-native.
190
+
165
191
  Version 1.0.1:
166
192
 
167
193
  * Requests resulting in an error now return nil unless return_raw is enabled
@@ -71,7 +71,7 @@ module SNMP4EM
71
71
  self.class.init_socket
72
72
  end
73
73
 
74
- def send(message) # @private
74
+ def send_msg(message) # @private
75
75
  self.class.socket.send_datagram message.encode, @host, @port
76
76
  end
77
77
 
@@ -64,12 +64,12 @@ module SNMP4EM
64
64
  return
65
65
  end
66
66
 
67
- send
67
+ send_msg
68
68
  end
69
69
 
70
70
  private
71
71
 
72
- def send
72
+ def send_msg
73
73
  Manager.track_request(self)
74
74
 
75
75
  vb_list = SNMP::VarBindList.new(pending_oids.collect{|oid| oid[:next_oid]})
@@ -42,12 +42,12 @@ module SNMP4EM
42
42
  return
43
43
  end
44
44
 
45
- send
45
+ send_msg
46
46
  end
47
47
 
48
48
  private
49
49
 
50
- def send
50
+ def send_msg
51
51
  Manager.track_request(self)
52
52
 
53
53
  query_oids = @oids.select{|oid| oid[:state] == :pending}.collect{|oid| oid[:requested_oid]}
@@ -67,12 +67,12 @@ module SNMP4EM
67
67
  return
68
68
  end
69
69
 
70
- send
70
+ send_msg
71
71
  end
72
72
 
73
73
  private
74
74
 
75
- def send
75
+ def send_msg
76
76
  Manager.track_request(self)
77
77
 
78
78
  vb_list = SNMP::VarBindList.new(pending_oids.collect{|oid| oid[:requested_oid]})
@@ -49,12 +49,12 @@ module SNMP4EM
49
49
  return
50
50
  end
51
51
 
52
- send
52
+ send_msg
53
53
  end
54
54
 
55
55
  private
56
56
 
57
- def send
57
+ def send_msg
58
58
  Manager.track_request(self)
59
59
 
60
60
  query_oids = @oids.select{|oid| oid[:state] == :pending}.collect{|oid| oid[:requested_oid]}
@@ -47,12 +47,12 @@ module SNMP4EM
47
47
  return
48
48
  end
49
49
 
50
- send
50
+ send_msg
51
51
  end
52
52
 
53
53
  private
54
54
 
55
- def send
55
+ def send_msg
56
56
  Manager.track_request(self)
57
57
 
58
58
  pending_varbinds = pending_oids.collect{|oid| SNMP::VarBind.new(oid[:requested_oid], oid[:value])}
@@ -60,12 +60,12 @@ module SNMP4EM
60
60
  return
61
61
  end
62
62
 
63
- send
63
+ send_msg
64
64
  end
65
65
 
66
66
  private
67
67
 
68
- def send
68
+ def send_msg
69
69
  Manager.track_request(self)
70
70
 
71
71
  vb_list = SNMP::VarBindList.new(pending_oids.collect{|oid| oid[:next_oid]})
@@ -9,15 +9,21 @@ module SNMP4EM
9
9
 
10
10
  @oids ||= [*oids].collect { |oid_str| { :requested_string => oid_str, :requested_oid => SNMP::ObjectId.new(oid_str), :state => :pending }}
11
11
 
12
- @timeout_timer = nil
13
- @timeout_retries = args[:retries] || @sender.retries
12
+ retries = args[:retries] || @sender.retries
13
+ timeout = args[:timeout] || @sender.timeout
14
+
15
+ if retries.is_a?(Array)
16
+ @timeouts = retries.clone
17
+ else
18
+ @timeouts = (retries + 1).times.collect { timeout }
19
+ end
14
20
 
15
21
  @return_raw = args[:return_raw] || false
16
22
  @max_results = args[:max_results] || nil
17
23
 
18
24
  init_callbacks
19
25
  on_init(args) if respond_to?(:on_init)
20
- send
26
+ send_msg
21
27
  end
22
28
 
23
29
  def pending_oids # @private
@@ -55,17 +61,16 @@ module SNMP4EM
55
61
  end
56
62
  end
57
63
 
58
- def send(msg) # @private
59
- @sender.send msg
64
+ def send_msg(msg) # @private
65
+ @sender.send_msg msg
60
66
 
61
67
  @timeout_timer.cancel if @timeout_timer.is_a?(EM::Timer)
62
68
 
63
- @timeout_timer = EM::Timer.new(@sender.timeout) do
64
- if @timeout_retries > 0
65
- send
66
- @timeout_retries -= 1
67
- else
69
+ @timeout_timer = EM::Timer.new(@timeouts.shift) do
70
+ if @timeouts.empty?
68
71
  fail "exhausted all timeout retries"
72
+ else
73
+ send_msg
69
74
  end
70
75
  end
71
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snmp4em
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: