snmp4em 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +47 -0
- data/lib/snmp4em/manager.rb +17 -0
- data/lib/snmp4em/snmp_common_requests.rb +8 -4
- data/lib/snmp4em/snmp_v2c_requests.rb +4 -2
- metadata +16 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d5aea9c134c9785958dbeaf94f757aa74b1ea166
|
4
|
+
data.tar.gz: eac0b67478cbddbd37756289194943ca297339cc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f6bfb1d99e40f5b28c9d0cb0ec8d7c8b5bc977d1c0df5eafdb6921531fb8fcf9d1bb4e1e5fea24cf6737130b08ff1d431a1fc5ef161d56e391c6743aa9251fb
|
7
|
+
data.tar.gz: 8a32202b3dbe22a36b641be5083b6d29ae5cb439bf42ac19e8d3ee6dfad734a8ca098793756a3491fc03934ace423acacccd35afdfca31f3bed83d055476f3a2
|
data/README.rdoc
CHANGED
@@ -12,6 +12,7 @@ The library currently supports:
|
|
12
12
|
* SNMP v1 and v2
|
13
13
|
* SNMP Get, GetNext, Set, and Walk requests. For SNMPv2 clients, GetBulk and WalkBulk
|
14
14
|
* Ability to query/set/walk multiple OIDs in parallel.
|
15
|
+
* For Ruby 1.9 and above, fiber support to streamline asychronous code
|
15
16
|
|
16
17
|
Future revisions of this library may support:
|
17
18
|
|
@@ -31,6 +32,7 @@ You may set the following options:
|
|
31
32
|
:community => "public", # Shorthand for setting both :community_ro and :community_rw
|
32
33
|
:community_ro => "public",
|
33
34
|
:community_rw => "public",
|
35
|
+
:fiber => false,
|
34
36
|
:timeout => 1,
|
35
37
|
:retries => 3 # Can also be specified as an array of individual timeouts
|
36
38
|
# For instance, [0.5, 1, 2.5] would send three requests with increasing timeout values
|
@@ -41,6 +43,13 @@ These options may also be passed to an individual query method, for instance:
|
|
41
43
|
snmp = SNMP4EM::Manager.new(...)
|
42
44
|
snmp.get(OID, :retries => 2, :timeout => 1)
|
43
45
|
|
46
|
+
And when receiving traps:
|
47
|
+
|
48
|
+
SNMP4EM::NotificationManager.new(
|
49
|
+
:host => "127.0.0.1", # Local interface on which to listen for traps. By default, localhost only!
|
50
|
+
:port => 161 # Port on which to listen for traps.
|
51
|
+
)
|
52
|
+
|
44
53
|
|
45
54
|
== Backwards compatibility
|
46
55
|
|
@@ -181,9 +190,47 @@ A simple SNMP-GET-BULK:
|
|
181
190
|
end
|
182
191
|
}
|
183
192
|
|
193
|
+
Handling traps:
|
194
|
+
|
195
|
+
EM.run {
|
196
|
+
manager = SNMP4EM::NotificationManager.new
|
197
|
+
|
198
|
+
manager.on_trap do |trap|
|
199
|
+
if trap.is_a? SNMP::SNMPv1_Trap
|
200
|
+
puts "Got a SNMPv1_Trap"
|
201
|
+
elsif trap.is_a? SNMP::SNMPv2_Trap
|
202
|
+
puts "Got a SNMPv2_Trap"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
}
|
206
|
+
|
207
|
+
== Fiber Support
|
208
|
+
|
209
|
+
If your Ruby supports it, you can pass enable fibers, either per-manager or per-request. This unwinds much of the complexity in writing event-driven code. Instead of receiving an object on which to hang callbacks, the current fiber will be suspended until the response is available. If an error occurs, it will be returned as a StandardError. Unfortunately, there is no way to raise this error, you are responsible for manually checking whether the returned object is an error or not.
|
210
|
+
|
211
|
+
For example:
|
212
|
+
|
213
|
+
EM.run {
|
214
|
+
snmp = SNMP4EM::Manager.new(:host => "192.168.1.1")
|
215
|
+
|
216
|
+
f = Fiber.new do
|
217
|
+
response = snmp.get([OID_SYSNAME, OID_SYSLOCATION])
|
218
|
+
|
219
|
+
if response.is_a? StandardError
|
220
|
+
puts "Uh oh!"
|
221
|
+
else
|
222
|
+
puts "System name = #{response[OID_SYSNAME]}"
|
223
|
+
puts "System location = #{response[OID_SYSLOCATION]}"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
}
|
184
227
|
|
185
228
|
== Change Log
|
186
229
|
|
230
|
+
Version 1.1.0:
|
231
|
+
|
232
|
+
* Fiber support
|
233
|
+
|
187
234
|
Version 1.0.2:
|
188
235
|
|
189
236
|
* Ability to specify timeouts as an array of timeout values. Inspired by https://github.com/calmh/node-snmp-native.
|
data/lib/snmp4em/manager.rb
CHANGED
@@ -62,6 +62,7 @@ module SNMP4EM
|
|
62
62
|
@timeout = args[:timeout] || 1
|
63
63
|
@retries = args[:retries] || 3
|
64
64
|
@version = args[:version] || :SNMPv2c
|
65
|
+
@fiber = args[:fiber] || false
|
65
66
|
|
66
67
|
self.extend SNMPv2cRequests if @version == :SNMPv2c
|
67
68
|
|
@@ -75,5 +76,21 @@ module SNMP4EM
|
|
75
76
|
self.class.socket.send_datagram message.encode, @host, @port
|
76
77
|
end
|
77
78
|
|
79
|
+
def wrap_in_fiber(request) # @private
|
80
|
+
require "fiber"
|
81
|
+
|
82
|
+
fiber = Fiber.current
|
83
|
+
|
84
|
+
request.callback do |response|
|
85
|
+
fiber.resume response
|
86
|
+
end
|
87
|
+
|
88
|
+
request.errback do |error|
|
89
|
+
fiber.resume StandardError.new(error)
|
90
|
+
end
|
91
|
+
|
92
|
+
Fiber.yield
|
93
|
+
end
|
94
|
+
|
78
95
|
end
|
79
96
|
end
|
@@ -11,7 +11,8 @@ module SNMP4EM
|
|
11
11
|
# * _version_ - Override the version provided in the {SNMP4EM::Manager} constructor
|
12
12
|
|
13
13
|
def get(oids, args = {})
|
14
|
-
SnmpGetRequest.new(self, oids, args.merge(:version => @version))
|
14
|
+
request = SnmpGetRequest.new(self, oids, args.merge(:version => @version))
|
15
|
+
if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end
|
15
16
|
end
|
16
17
|
|
17
18
|
# Sends an SNMP-GETNEXT request to the remote agent for all OIDs specified in the _oids_ array. Returns a {SnmpGetRequest} object,
|
@@ -24,7 +25,8 @@ module SNMP4EM
|
|
24
25
|
# * _version_ - Override the version provided in the {SNMP4EM::Manager} constructor
|
25
26
|
|
26
27
|
def getnext(oids, args = {})
|
27
|
-
SnmpGetNextRequest.new(self, oids, args.merge(:version => @version))
|
28
|
+
request = SnmpGetNextRequest.new(self, oids, args.merge(:version => @version))
|
29
|
+
if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end
|
28
30
|
end
|
29
31
|
|
30
32
|
# 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
|
@@ -37,7 +39,8 @@ module SNMP4EM
|
|
37
39
|
# * _version_ - Override the version provided in the {SNMP4EM::Manager} constructor
|
38
40
|
|
39
41
|
def set(oids, args = {})
|
40
|
-
SnmpSetRequest.new(self, oids, args.merge(:version => @version))
|
42
|
+
request = SnmpSetRequest.new(self, oids, args.merge(:version => @version))
|
43
|
+
if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end
|
41
44
|
end
|
42
45
|
|
43
46
|
# Sends a series of SNMP-GETNEXT requests to simulate an SNMP "walk" operation. Given an OID prefix, the library will keep requesting the
|
@@ -53,7 +56,8 @@ module SNMP4EM
|
|
53
56
|
# * _version_ - Override the version provided in the {SNMP4EM::Manager} constructor
|
54
57
|
|
55
58
|
def walk(oids, args = {})
|
56
|
-
SnmpWalkRequest.new(self, oids, args.merge(:version => @version))
|
59
|
+
request = SnmpWalkRequest.new(self, oids, args.merge(:version => @version))
|
60
|
+
if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end
|
57
61
|
end
|
58
62
|
end
|
59
63
|
end
|
@@ -19,7 +19,8 @@ module SNMP4EM
|
|
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
|
+
request = SnmpGetBulkRequest.new(self, oids, args)
|
23
|
+
if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end
|
23
24
|
end
|
24
25
|
|
25
26
|
# 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
|
@@ -34,7 +35,8 @@ module SNMP4EM
|
|
34
35
|
# * _version_ - Override the version provided in the {SNMP4EM::Manager} constructor
|
35
36
|
|
36
37
|
def bulkwalk(oids, args = {})
|
37
|
-
SnmpBulkWalkRequest.new(self, oids, args)
|
38
|
+
request = SnmpBulkWalkRequest.new(self, oids, args)
|
39
|
+
if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snmp4em
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Norman Elton
|
@@ -14,65 +13,57 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: snmp
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.0.2
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 1.0.2
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: eventmachine
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 1.0.0
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 1.0.0
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: yard
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: A high-performance SNMP engine built on EventMachine and Ruby-SNMP
|
@@ -106,7 +97,9 @@ files:
|
|
106
97
|
- lib/snmp4em.rb
|
107
98
|
- README.rdoc
|
108
99
|
homepage: http://github.com/normelton/snmp4em
|
109
|
-
licenses:
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
110
103
|
post_install_message:
|
111
104
|
rdoc_options:
|
112
105
|
- --line-numbers
|
@@ -118,22 +111,20 @@ rdoc_options:
|
|
118
111
|
require_paths:
|
119
112
|
- lib
|
120
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
114
|
requirements:
|
123
|
-
- -
|
115
|
+
- - '>='
|
124
116
|
- !ruby/object:Gem::Version
|
125
117
|
version: '0'
|
126
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
-
none: false
|
128
119
|
requirements:
|
129
|
-
- -
|
120
|
+
- - '>='
|
130
121
|
- !ruby/object:Gem::Version
|
131
122
|
version: '1.2'
|
132
123
|
requirements: []
|
133
124
|
rubyforge_project: snmp4em
|
134
|
-
rubygems_version: 1.
|
125
|
+
rubygems_version: 2.1.11
|
135
126
|
signing_key:
|
136
|
-
specification_version:
|
127
|
+
specification_version: 4
|
137
128
|
summary: A high-performance SNMP engine built on EventMachine and Ruby-SNMP
|
138
129
|
test_files: []
|
139
130
|
has_rdoc:
|