snmp4em 0.3 → 1.0.0
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 +45 -17
- data/lib/snmp4em/extensions/snmp/integer.rb +2 -2
- data/lib/snmp4em/extensions/snmp/ip_address.rb +2 -2
- data/lib/snmp4em/extensions/snmp/null.rb +2 -2
- data/lib/snmp4em/extensions/snmp/object_id.rb +2 -2
- data/lib/snmp4em/extensions/snmp/octet_string.rb +2 -2
- data/lib/snmp4em/extensions/snmp/response_error.rb +9 -4
- data/lib/snmp4em/handler.rb +2 -4
- data/lib/snmp4em/manager.rb +21 -11
- data/lib/snmp4em/notification_handler.rb +27 -0
- data/lib/snmp4em/notification_manager.rb +23 -0
- data/lib/snmp4em/requests/snmp_bulkwalk_request.rb +86 -0
- data/lib/snmp4em/requests/snmp_get_request.rb +33 -24
- data/lib/snmp4em/requests/snmp_getbulk_request.rb +50 -50
- data/lib/snmp4em/requests/snmp_getnext_request.rb +43 -26
- data/lib/snmp4em/requests/snmp_set_request.rb +34 -61
- data/lib/snmp4em/requests/snmp_walk_request.rb +49 -59
- data/lib/snmp4em/{common_requests.rb → snmp_common_requests.rb} +16 -13
- data/lib/snmp4em/snmp_request.rb +37 -11
- data/lib/snmp4em/snmp_v2c_requests.rb +21 -6
- data/lib/snmp4em.rb +5 -5
- metadata +40 -16
- data/Gemfile +0 -7
- data/Manifest +0 -29
- data/Rakefile +0 -17
- data/snmp4em.gemspec +0 -23
- data/spec/models/test_message.rb +0 -7
- data/spec/models/test_request.rb +0 -10
- data/spec/models/test_response.rb +0 -7
- data/spec/spec.opts +0 -3
- data/spec/spec_helper.rb +0 -18
- data/spec/unit/handler_spec.rb +0 -34
- data/spec/unit/manager_spec.rb +0 -82
@@ -1,48 +1,65 @@
|
|
1
1
|
module SNMP4EM
|
2
2
|
|
3
|
-
#
|
3
|
+
# The result of calling {SNMPCommonRequests#getnext}.
|
4
4
|
|
5
5
|
class SnmpGetNextRequest < SnmpRequest
|
6
6
|
attr_accessor :snmp_id
|
7
7
|
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
# Used to register a callback that is triggered when the query result is ready. The resulting object is passed as a parameter to the block.
|
9
|
+
def callback &block
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
# Used to register a callback that is triggered when query fails to complete successfully.
|
14
|
+
def errback &block
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def handle_response(response) # @private
|
19
|
+
super
|
20
|
+
|
14
21
|
if response.error_status == :noError
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
pending_oids.zip(response.varbind_list).each do |oid, response_vb|
|
23
|
+
value = format_value(response_vb)
|
24
|
+
|
25
|
+
if value.is_a? SNMP::ResponseError
|
26
|
+
oid[:response] = value
|
27
|
+
else
|
28
|
+
oid[:response] = [response_vb.name.to_s, format_value(response_vb)]
|
29
|
+
end
|
30
|
+
|
31
|
+
oid[:state] = :complete
|
20
32
|
end
|
33
|
+
|
21
34
|
else
|
22
|
-
|
23
|
-
error_oid =
|
24
|
-
|
35
|
+
error_oid = pending_oids[response.error_index - 1]
|
36
|
+
error_oid[:state] = :error
|
37
|
+
error_oid[:error] = SNMP::ResponseError.new(response.error_status)
|
25
38
|
end
|
26
39
|
|
27
|
-
if
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
40
|
+
if pending_oids.empty?
|
41
|
+
result = {}
|
42
|
+
|
43
|
+
@oids.each do |oid|
|
44
|
+
requested_oid = oid[:requested_string]
|
45
|
+
result[requested_oid] = oid[:error] || oid[:response]
|
46
|
+
end
|
47
|
+
|
48
|
+
succeed result
|
49
|
+
return
|
35
50
|
end
|
51
|
+
|
52
|
+
send
|
36
53
|
end
|
37
54
|
|
38
55
|
private
|
39
56
|
|
40
|
-
def send
|
57
|
+
def send
|
41
58
|
Manager.track_request(self)
|
42
59
|
|
43
|
-
|
60
|
+
query_oids = @oids.select{|oid| oid[:state] == :pending}.collect{|oid| oid[:requested_oid]}
|
44
61
|
|
45
|
-
vb_list = SNMP::VarBindList.new(
|
62
|
+
vb_list = SNMP::VarBindList.new(query_oids)
|
46
63
|
request = SNMP::GetNextRequest.new(@snmp_id, vb_list)
|
47
64
|
message = SNMP::Message.new(@sender.version, @sender.community_ro, request)
|
48
65
|
|
@@ -1,80 +1,53 @@
|
|
1
1
|
module SNMP4EM
|
2
2
|
|
3
|
-
#
|
4
|
-
# or errback() to retrieve the results.
|
3
|
+
# The result of calling {SNMPCommonRequests#set}.
|
5
4
|
|
6
5
|
class SnmpSetRequest < SnmpRequest
|
7
6
|
attr_accessor :snmp_id
|
8
7
|
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# are produced, the @responses object is populated and returned.
|
14
|
-
|
15
|
-
def initialize(sender, oids, args = {}) #:nodoc:
|
16
|
-
_oids = [*oids]
|
8
|
+
# Used to register a callback that is triggered when the query result is ready. The resulting object is passed as a parameter to the block.
|
9
|
+
def callback &block
|
10
|
+
super
|
11
|
+
end
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@error_retries = _oids.size
|
23
|
-
|
24
|
-
@return_raw = args[:return_raw] || false
|
25
|
-
|
26
|
-
@responses = Hash.new
|
27
|
-
@pending_varbinds = SNMP::VarBindList.new()
|
28
|
-
|
29
|
-
_oids.each do |oid,value|
|
30
|
-
if value.is_a? Integer
|
31
|
-
snmp_value = SNMP::Integer.new(value)
|
32
|
-
elsif value.is_a? String
|
33
|
-
snmp_value = SNMP::OctetString.new(value)
|
34
|
-
else
|
35
|
-
snmp_value = value
|
36
|
-
end
|
37
|
-
|
38
|
-
@pending_varbinds << SNMP::VarBind.new(oid,snmp_value)
|
39
|
-
end
|
13
|
+
# Used to register a callback that is triggered when query fails to complete successfully.
|
14
|
+
def errback &block
|
15
|
+
super
|
16
|
+
end
|
40
17
|
|
41
|
-
|
42
|
-
|
18
|
+
def initialize(sender, oids, args = {}) # @private
|
19
|
+
@oids = [*oids].collect { |oid_str, value| { :requested_oid => SNMP::ObjectId.new(oid_str), :requested_string => oid_str, :value => format_outgoing_value(value), :state => :pending, :response => nil }}
|
20
|
+
super
|
43
21
|
end
|
44
22
|
|
45
|
-
def handle_response(response)
|
23
|
+
def handle_response(response) # @private
|
24
|
+
super
|
25
|
+
|
46
26
|
if (response.error_status == :noError)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
@responses[response_vb.name.to_s] = true
|
27
|
+
pending_oids.zip(response.varbind_list).each do |oid, response_vb|
|
28
|
+
oid[:response] = true
|
29
|
+
oid[:state] = :complete
|
51
30
|
end
|
52
31
|
|
53
32
|
else
|
54
|
-
|
55
|
-
|
56
|
-
|
33
|
+
error_oid = pending_oids[response.error_index - 1]
|
34
|
+
error_oid[:state] = :error
|
35
|
+
error_oid[:error] = SNMP::ResponseError.new(response.error_status)
|
57
36
|
end
|
58
37
|
|
59
|
-
if
|
60
|
-
|
61
|
-
error_vb = @pending_varbinds.shift
|
62
|
-
@responses[error_vb.name.to_s] = SNMP::ResponseError.new(:genErr)
|
63
|
-
end
|
38
|
+
if pending_oids.empty?
|
39
|
+
result = {}
|
64
40
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
41
|
+
@oids.each do |oid|
|
42
|
+
requested_oid = oid[:requested_string]
|
43
|
+
result[requested_oid] = oid[:error] || oid[:response]
|
69
44
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
else
|
74
|
-
@error_retries -= 1
|
75
|
-
|
76
|
-
send
|
45
|
+
|
46
|
+
succeed result
|
47
|
+
return
|
77
48
|
end
|
49
|
+
|
50
|
+
send
|
78
51
|
end
|
79
52
|
|
80
53
|
private
|
@@ -82,11 +55,11 @@ module SNMP4EM
|
|
82
55
|
def send
|
83
56
|
Manager.track_request(self)
|
84
57
|
|
85
|
-
|
58
|
+
pending_varbinds = pending_oids.collect{|oid| SNMP::VarBind.new(oid[:requested_oid], oid[:value])}
|
86
59
|
|
87
|
-
vb_list = SNMP::VarBindList.new(
|
60
|
+
vb_list = SNMP::VarBindList.new(pending_varbinds)
|
88
61
|
request = SNMP::SetRequest.new(@snmp_id, vb_list)
|
89
|
-
message = SNMP::Message.new(@sender.version, @sender.
|
62
|
+
message = SNMP::Message.new(@sender.version, @sender.community_rw, request)
|
90
63
|
|
91
64
|
super(message)
|
92
65
|
end
|
@@ -1,52 +1,66 @@
|
|
1
1
|
module SNMP4EM
|
2
2
|
|
3
|
-
#
|
3
|
+
# The result of calling {SNMPCommonRequests#walk}.
|
4
4
|
|
5
5
|
class SnmpWalkRequest < SnmpRequest
|
6
6
|
attr_accessor :snmp_id
|
7
7
|
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def
|
19
|
-
|
8
|
+
# Used to register a callback that is triggered when the query result is ready. The resulting object is passed as a parameter to the block.
|
9
|
+
def callback &block
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
# Used to register a callback that is triggered when query fails to complete successfully.
|
14
|
+
def errback &block
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_init args # @private
|
19
|
+
@oids.each{|oid| oid.merge!({:next_oid => oid[:requested_oid], :responses => {}})}
|
20
|
+
end
|
21
|
+
|
22
|
+
def handle_response(response) # @private
|
23
|
+
super
|
20
24
|
|
21
|
-
|
22
|
-
|
25
|
+
if response.error_status == :noError
|
26
|
+
pending_oids.zip(response.varbind_list).each do |oid, response_vb|
|
23
27
|
response_oid = response_vb.name
|
24
|
-
response_walk_oid = response_oid.dup; response_walk_oid.pop
|
25
28
|
|
26
|
-
if
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
if response_vb.value == SNMP::EndOfMibView
|
30
|
+
# For SNMPv2, this indicates we've reached the end of the MIB
|
31
|
+
oid[:state] = :complete
|
32
|
+
elsif ! response_oid.subtree_of?(oid[:requested_oid])
|
33
|
+
oid[:state] = :complete
|
30
34
|
else
|
31
|
-
|
35
|
+
oid[:responses][response_oid.to_s] = format_value(response_vb)
|
36
|
+
oid[:next_oid] = response_oid
|
32
37
|
end
|
33
38
|
end
|
34
|
-
|
35
|
-
|
39
|
+
|
40
|
+
elsif response.error_status == :noSuchName
|
41
|
+
# For SNMPv1, this indicates we've reached the end of the MIB
|
42
|
+
error_oid = pending_oids[response.error_index - 1]
|
43
|
+
error_oid[:state] = :complete
|
44
|
+
|
36
45
|
else
|
37
|
-
|
38
|
-
error_oid =
|
39
|
-
|
40
|
-
fail @errors if @error_retries < 1
|
41
|
-
@error_retries -= 1
|
46
|
+
error_oid = pending_oids[response.error_index - 1]
|
47
|
+
error_oid[:state] = :error
|
48
|
+
error_oid[:error] = SNMP::ResponseError.new(response.error_status)
|
42
49
|
end
|
43
50
|
|
44
|
-
if
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
51
|
+
if pending_oids.empty? || (@max_results && @oids.collect{|oid| oid[:responses].count}.max >= @max_results)
|
52
|
+
result = {}
|
53
|
+
|
54
|
+
@oids.each do |oid|
|
55
|
+
requested_oid = oid[:requested_string]
|
56
|
+
result[requested_oid] = oid[:error] || oid[:responses]
|
57
|
+
end
|
58
|
+
|
59
|
+
succeed result
|
60
|
+
return
|
49
61
|
end
|
62
|
+
|
63
|
+
send
|
50
64
|
end
|
51
65
|
|
52
66
|
private
|
@@ -54,34 +68,10 @@ module SNMP4EM
|
|
54
68
|
def send
|
55
69
|
Manager.track_request(self)
|
56
70
|
|
57
|
-
|
58
|
-
# @next_oids maps the walk oid to its next getnext oid
|
59
|
-
#
|
60
|
-
unless @next_oids
|
61
|
-
@responses = {}
|
62
|
-
@next_oids = {}
|
63
|
-
@pending_oids.each do |walk_oid|
|
64
|
-
@next_oids[walk_oid] = walk_oid
|
65
|
-
@responses[walk_oid.to_s] = {}
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
#
|
70
|
-
# @query_indexes maps the index of the requested oid to the walk oid
|
71
|
-
#
|
72
|
-
i = 0
|
73
|
-
@query_indexes = {}
|
74
|
-
query_oids = \
|
75
|
-
@next_oids.collect do |walk_oid, next_oid|
|
76
|
-
@query_indexes[i] = walk_oid
|
77
|
-
i += 1
|
78
|
-
next_oid
|
79
|
-
end
|
80
|
-
|
81
|
-
vb_list = SNMP::VarBindList.new(query_oids)
|
71
|
+
vb_list = SNMP::VarBindList.new(pending_oids.collect{|oid| oid[:next_oid]})
|
82
72
|
request = SNMP::GetNextRequest.new(@snmp_id, vb_list)
|
83
73
|
message = SNMP::Message.new(@sender.version, @sender.community_ro, request)
|
84
|
-
|
74
|
+
|
85
75
|
super(message)
|
86
76
|
end
|
87
77
|
end
|
@@ -1,25 +1,27 @@
|
|
1
1
|
# The SNMP4EM library
|
2
2
|
|
3
3
|
module SNMP4EM
|
4
|
-
module
|
5
|
-
# Sends an SNMP-GET request to the remote agent for all OIDs specified in the _oids_ array. Returns a SnmpGetRequest object,
|
4
|
+
module SNMPCommonRequests
|
5
|
+
# Sends an SNMP-GET request to the remote agent for all OIDs specified in the _oids_ array. Returns a {SnmpGetRequest} object,
|
6
6
|
# which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the result will be
|
7
|
-
# a hash, mapping requested OID values to results.
|
7
|
+
# a hash, mapping requested OID values to results. Errors will be returned as a {SNMP::ResponseError}.
|
8
8
|
#
|
9
9
|
# Optional arguments can be passed into _args_, including:
|
10
10
|
# * _return_raw_ - Return objects and errors as their raw SNMP types, such as SNMP::Integer instead of native Ruby integers, SNMP::OctetString instead of native Ruby strings, etc. (default: false)
|
11
|
+
# * _version_ - Override the version provided in the {SNMP4EM::Manager} constructor
|
11
12
|
|
12
13
|
def get(oids, args = {})
|
13
14
|
SnmpGetRequest.new(self, oids, args.merge(:version => @version))
|
14
15
|
end
|
15
16
|
|
16
|
-
# Sends an SNMP-GETNEXT request to the remote agent for all OIDs specified in the _oids_ array. Returns a SnmpGetRequest object,
|
17
|
+
# Sends an SNMP-GETNEXT request to the remote agent for all OIDs specified in the _oids_ array. Returns a {SnmpGetRequest} object,
|
17
18
|
# which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the result will be
|
18
|
-
# a hash, mapping requested OID values to two-element arrays consisting of [_next_oid_ , _next_value_].
|
19
|
-
# error will map to
|
19
|
+
# a hash, mapping requested OID values to two-element arrays consisting of [_next_oid_ , _next_value_]. OIDs resulting in an
|
20
|
+
# error will map to an instance of {SNMP::ResponseError} instead.
|
20
21
|
#
|
21
22
|
# Optional arguments can be passed into _args_, including:
|
22
23
|
# * _return_raw_ - Return objects and errors as their raw SNMP types, such as SNMP::Integer instead of native Ruby integers, SNMP::OctetString instead of native Ruby strings, etc. (default: false)
|
24
|
+
# * _version_ - Override the version provided in the {SNMP4EM::Manager} constructor
|
23
25
|
|
24
26
|
def getnext(oids, args = {})
|
25
27
|
SnmpGetNextRequest.new(self, oids, args.merge(:version => @version))
|
@@ -27,12 +29,12 @@ module SNMP4EM
|
|
27
29
|
|
28
30
|
# Sends an SNMP-SET request to the remote agent for all OIDs specified in the _oids_ hash. The hash must map OID values to requested
|
29
31
|
# values. Values can either be specified as Ruby native strings/integers, or as SNMP-specific classes (SNMP::IpAddress, etc).
|
30
|
-
# Returns a SnmpSetRequest object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result.
|
32
|
+
# Returns a {SnmpSetRequest} object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result.
|
31
33
|
# On success, the result will be a hash, mapping requested OID values to the returned value from the agent. Any values that were stored
|
32
|
-
# successfully will map to _true_, otherwise, the value will map to
|
34
|
+
# successfully will map to _true_, otherwise, the value will map to an instance of {SNMP::ResponseError} instead.
|
33
35
|
#
|
34
36
|
# Optional arguments can be passed into _args_, including:
|
35
|
-
# *
|
37
|
+
# * _version_ - Override the version provided in the {SNMP4EM::Manager} constructor
|
36
38
|
|
37
39
|
def set(oids, args = {})
|
38
40
|
SnmpSetRequest.new(self, oids, args.merge(:version => @version))
|
@@ -41,13 +43,14 @@ module SNMP4EM
|
|
41
43
|
# Sends a series of SNMP-GETNEXT requests to simulate an SNMP "walk" operation. Given an OID prefix, the library will keep requesting the
|
42
44
|
# next OID until that returned OID does not begin with the requested prefix. This gives the ability to retrieve entire portions of the
|
43
45
|
# SNMP tree in one "operation". Multiple OID prefixes can be passed into the _oids_ array, and will be fetched in parallel. The function returns
|
44
|
-
# a SnmpWalkRequest object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the
|
45
|
-
# result will be a hash, mapping requested OID prefixes to the returned value. Successful walks will be mapped to
|
46
|
-
# each
|
47
|
-
|
46
|
+
# a {SnmpWalkRequest} object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the
|
47
|
+
# result will be a hash, mapping requested OID prefixes to the returned value. Successful walks will be mapped to a hash,
|
48
|
+
# where each pair is represented as (oid => value). Unsuccessful walks will be mapped to an instance of {SNMP::ResponseError}.
|
49
|
+
#
|
48
50
|
# Optional arguments can be passed into _args_, including:
|
49
51
|
# * _return_raw_ - Return objects and errors as their raw SNMP types, such as SNMP::Integer instead of native Ruby integers, SNMP::OctetString instead of native Ruby strings, etc. (default: false)
|
50
52
|
# * _max_results_ - Maximum number of results to be returned for any single OID prefix (default: nil = unlimited)
|
53
|
+
# * _version_ - Override the version provided in the {SNMP4EM::Manager} constructor
|
51
54
|
|
52
55
|
def walk(oids, args = {})
|
53
56
|
SnmpWalkRequest.new(self, oids, args.merge(:version => @version))
|
data/lib/snmp4em/snmp_request.rb
CHANGED
@@ -1,28 +1,50 @@
|
|
1
1
|
module SNMP4EM
|
2
|
-
class SnmpRequest
|
2
|
+
class SnmpRequest
|
3
3
|
include EM::Deferrable
|
4
4
|
|
5
5
|
attr_accessor :timeout_timer
|
6
6
|
|
7
|
-
def initialize(sender, oids, args = {})
|
8
|
-
_oids = [*oids]
|
9
|
-
|
7
|
+
def initialize(sender, oids, args = {})
|
10
8
|
@sender = sender
|
11
9
|
|
10
|
+
@oids ||= [*oids].collect { |oid_str| { :requested_string => oid_str, :requested_oid => SNMP::ObjectId.new(oid_str), :state => :pending }}
|
11
|
+
|
12
12
|
@timeout_timer = nil
|
13
|
-
@timeout_retries = @sender.retries
|
14
|
-
@error_retries = _oids.size
|
13
|
+
@timeout_retries = args[:retries] || @sender.retries
|
15
14
|
|
16
15
|
@return_raw = args[:return_raw] || false
|
16
|
+
@max_results = args[:max_results] || nil
|
17
17
|
|
18
|
-
@responses = {}
|
19
|
-
@pending_oids = _oids.collect { |oid_str| SNMP::ObjectId.new(oid_str) }
|
20
|
-
|
21
18
|
init_callbacks
|
19
|
+
on_init(args) if respond_to?(:on_init)
|
22
20
|
send
|
23
21
|
end
|
22
|
+
|
23
|
+
def pending_oids # @private
|
24
|
+
@oids.select{|oid| oid[:state] == :pending}
|
25
|
+
end
|
26
|
+
|
27
|
+
def format_value vb # @private
|
28
|
+
if [SNMP::EndOfMibView, SNMP::NoSuchObject, SNMP::NoSuchInstance].include? vb.value
|
29
|
+
SNMP::ResponseError.new(vb.value)
|
30
|
+
elsif @return_raw || !vb.value.respond_to?(:rubify)
|
31
|
+
vb.value
|
32
|
+
else
|
33
|
+
vb.value.rubify
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def format_outgoing_value value # @private
|
38
|
+
if value.is_a? Integer
|
39
|
+
return SNMP::Integer.new(value)
|
40
|
+
elsif value.is_a? String
|
41
|
+
return SNMP::OctetString.new(value)
|
42
|
+
else
|
43
|
+
return value
|
44
|
+
end
|
45
|
+
end
|
24
46
|
|
25
|
-
def init_callbacks
|
47
|
+
def init_callbacks # @private
|
26
48
|
self.callback do
|
27
49
|
Manager.pending_requests.delete(@snmp_id)
|
28
50
|
end
|
@@ -33,7 +55,7 @@ module SNMP4EM
|
|
33
55
|
end
|
34
56
|
end
|
35
57
|
|
36
|
-
def send(msg)
|
58
|
+
def send(msg) # @private
|
37
59
|
@sender.send msg
|
38
60
|
|
39
61
|
@timeout_timer.cancel if @timeout_timer.is_a?(EM::Timer)
|
@@ -47,5 +69,9 @@ module SNMP4EM
|
|
47
69
|
end
|
48
70
|
end
|
49
71
|
end
|
72
|
+
|
73
|
+
def handle_response response # @private
|
74
|
+
@timeout_timer.cancel
|
75
|
+
end
|
50
76
|
end
|
51
77
|
end
|
@@ -6,20 +6,35 @@ module SNMP4EM
|
|
6
6
|
# request/response transaction (SNMP-WALK is actually an inefficient series of GET-NEXTs). Multiple OIDs can be passed into the _oids_ array. Two
|
7
7
|
# additional parameters control how this list is processed. Setting the parameter _nonrepeaters_ to value _N_ indicates that the first _N_ OIDs will
|
8
8
|
# fetch a single value. This is identical to running a single GET-NEXT for the OID. Any remaining OIDs will fetch multiple values. The number of values
|
9
|
-
# fetched is controlled by the parameter _maxrepetitions_. The function returns a SnmpGetBulkRequest object, which implements EM::Deferrable. From there,
|
9
|
+
# fetched is controlled by the parameter _maxrepetitions_. The function returns a {SnmpGetBulkRequest} object, which implements EM::Deferrable. From there,
|
10
10
|
# implement a callback/errback to fetch the result. On success, the result will be a hash, mapping requested OID prefixes to the returned value.
|
11
|
-
# Successful
|
12
|
-
#
|
13
|
-
|
11
|
+
# Successful walks will be mapped to a hash, where each pair is represented as {oid => value}. Unsuccessful fetches will be mapped to
|
12
|
+
# an instance of {SNMP::ResponseError}
|
13
|
+
#
|
14
14
|
# For more information, see http://tools.ietf.org/html/rfc1905#section-4.2.3
|
15
|
-
|
15
|
+
#
|
16
16
|
# Optional arguments can be passed into _args_, including:
|
17
17
|
# * _return_raw_ - Return objects and errors as their raw SNMP types, such as SNMP::Integer instead of native Ruby integers, SNMP::OctetString instead of native Ruby strings, etc. (default: false)
|
18
18
|
# * _nonrepeaters_ - Number of OIDs passed to which exactly one result will be returned (default is 0)
|
19
19
|
# * _maxrepetitions_ - Number of OID-value pairs to be returned for each OID (default is 10)
|
20
20
|
|
21
21
|
def getbulk(oids, args = {})
|
22
|
-
SnmpGetBulkRequest.new(self, oids, args
|
22
|
+
SnmpGetBulkRequest.new(self, oids, args)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Uses SNMPv2 GET-BULK operations to fetch all values of one or more OID prefixes. This produces the same result as {SNMPCommonRequests#walk}, but with much
|
26
|
+
# higher efficiency, as GET-BULK operations can fetch multiple OIDs at the same time. Multiple OID prefixes can be passed into the _oids_ array, and will be fetched in parallel. The function returns
|
27
|
+
# a {SnmpBulkWalkRequest} object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the
|
28
|
+
# result will be a hash, mapping requested OID prefixes to the returned value. Successful walks will be mapped to a hash,
|
29
|
+
# where each pair is represented as (oid => value). Unsuccessful walks will be mapped to an instance of {SNMP::ResponseError}.
|
30
|
+
#
|
31
|
+
# Optional arguments can be passed into _args_, including:
|
32
|
+
# * _return_raw_ - Return objects and errors as their raw SNMP types, such as SNMP::Integer instead of native Ruby integers, SNMP::OctetString instead of native Ruby strings, etc. (default: false)
|
33
|
+
# * _max_results_ - Maximum number of results to be returned for any single OID prefix (default: nil = unlimited)
|
34
|
+
# * _version_ - Override the version provided in the {SNMP4EM::Manager} constructor
|
35
|
+
|
36
|
+
def bulkwalk(oids, args = {})
|
37
|
+
SnmpBulkWalkRequest.new(self, oids, args)
|
23
38
|
end
|
24
39
|
end
|
25
40
|
end
|
data/lib/snmp4em.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
$:.unshift File.dirname(File.expand_path(__FILE__))
|
2
2
|
|
3
|
-
gem "eventmachine", ">= 0.12.10"
|
4
|
-
gem "snmp", ">= 1.0.2"
|
5
|
-
|
6
3
|
require 'eventmachine'
|
7
4
|
require 'snmp'
|
8
5
|
|
9
6
|
require 'snmp4em/extensions'
|
10
7
|
require 'snmp4em/handler'
|
11
|
-
require 'snmp4em/
|
12
|
-
require 'snmp4em/manager'
|
8
|
+
require 'snmp4em/snmp_common_requests'
|
13
9
|
require 'snmp4em/snmp_v2c_requests'
|
10
|
+
require 'snmp4em/manager'
|
11
|
+
require 'snmp4em/notification_handler'
|
12
|
+
require 'snmp4em/notification_manager'
|
14
13
|
require 'snmp4em/snmp_request'
|
15
14
|
require 'snmp4em/requests/snmp_get_request'
|
16
15
|
require 'snmp4em/requests/snmp_getbulk_request'
|
17
16
|
require 'snmp4em/requests/snmp_getnext_request'
|
18
17
|
require 'snmp4em/requests/snmp_set_request'
|
19
18
|
require 'snmp4em/requests/snmp_walk_request'
|
19
|
+
require 'snmp4em/requests/snmp_bulkwalk_request'
|