normelton-snmp4em 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
2
2
  require "rake"
3
3
  require "echoe"
4
4
 
5
- Echoe.new("snmp4em", "0.1.0") do |p|
5
+ Echoe.new("snmp4em", "0.1.2") do |p|
6
6
  p.description = "A high-performance SNMP engine built on EventMachine and Ruby-SNMP"
7
7
  p.url = "http://github.com/normelton/snmp4em"
8
8
  p.author = "Norman Elton"
data/lib/snmp4em.rb CHANGED
@@ -1,113 +1,12 @@
1
- require "snmp"
2
- require "common.rb"
3
- require "handler.rb"
4
- require "snmp_request.rb"
5
- require "requests/snmp_get_request.rb"
6
- require "requests/snmp_getnext_request.rb"
7
- require "requests/snmp_walk_request.rb"
8
- require "requests/snmp_set_request.rb"
9
-
10
- require "pp"
11
-
12
- # The SNMP4EM library
13
-
14
- module SNMP4EM
15
- class SNMPv1
16
- @pending_requests = []
17
- @socket = nil
18
-
19
- class << self
20
- attr_reader :pending_requests
21
- attr_reader :socket
22
-
23
- def init_socket #:nodoc:
24
- @socket = EM::open_datagram_socket("0.0.0.0", 0, Handler)
25
- end
26
- end
27
-
28
- attr_reader :host, :port, :community_ro, :community_rw, :timeout, :retries
29
-
30
- # Creates a new object to communicate with SNMPv1 agents. Optionally pass in the following parameters:
31
- # * _host_ - IP/hostname of remote agent (default: 127.0.0.1)
32
- # * _port_ - UDP port on remote agent (default: 161)
33
- # * _community_ - Community string to use (default: public)
34
- # * _community_ro_ - Read-only community string to use for get/getnext/walk operations (default: public)
35
- # * _community_rw_ - Read-write community string to use for set operations (default: public)
36
- # * _timeout_ - Number of seconds to wait before a request times out (default: 1)
37
- # * _retries_ - Number of retries before failing (default: 3)
38
-
39
- def initialize(args = {})
40
- @host = args[:host] || "127.0.0.1"
41
- @port = args[:port] || 161
42
- @community_ro = args[:community_ro] || args[:community] || "public"
43
- @community_rw = args[:community_rw] || args[:community] || "public"
44
- @timeout = args[:timeout] || 1
45
- @retries = args[:retries] || 3
46
-
47
- self.class.init_socket
48
- end
49
-
50
- def send(message) #:nodoc:
51
- self.class.socket.send_datagram message.encode, @host, @port
52
- end
53
-
54
- # Sends an SNMP-GET request to the remote agent for all OIDs specified in the _oids_ array. Returns a SnmpGetRequest object,
55
- # which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the result will be
56
- # a hash, mapping requested OID values to results.
57
- #
58
- # Optional arguments can be passed into _args_, including:
59
- # * _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)
60
-
61
- def get(oids, args = {})
62
- request = SnmpGetRequest.new(self, oids, args)
63
- self.class.pending_requests << request
64
- return request
65
- end
66
-
67
- # Sends an SNMP-GETNEXT request to the remote agent for all OIDs specified in the _oids_ array. Returns a SnmpGetRequest object,
68
- # which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the result will be
69
- # a hash, mapping requested OID values to two-element arrays consisting of [_next_oid_ , _next_value_]. Any values that produced an
70
- # error will map to a symbol representing the error.
71
- #
72
- # Optional arguments can be passed into _args_, including:
73
- # * _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)
74
-
75
- def getnext(oids, args = {})
76
- request = SnmpGetNextRequest.new(self, oids, args)
77
- self.class.pending_requests << request
78
- return request
79
- end
80
-
81
- # 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
82
- # values. Values can either be specified as Ruby native strings/integers, or as SNMP-specific classes (SNMP::IpAddress, etc).
83
- # Returns a SnmpSetRequest object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result.
84
- # On success, the result will be a hash, mapping requested OID values to the returned value from the agent. Any values that were stored
85
- # successfully will map to _true_, otherwise, the value will map to a symbol representing the error.
86
- #
87
- # Optional arguments can be passed into _args_, including:
88
- # * _return_raw_ - Return error objects as SNMP::ResponseError instead of a symbol
89
-
90
- def set(oids, args = {})
91
- request = SnmpSetRequest.new(self, oids, args)
92
- self.class.pending_requests << request
93
- return request
94
- end
95
-
96
- # Sends a series of SNMP-GETNEXT requests to simulate an SNMP "walk" operation. Given an OID prefix, the library will keep requesting the
97
- # next OID until that returned OID does not begin with the requested prefix. This gives the ability to retrieve entire portions of the
98
- # SNMP tree in one "operation". Multiple OID prefixes can be passed into the _oids_ array, and will be fetched in parallel. The function returns
99
- # a SnmpWalkRequest object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the
100
- # result will be a hash, mapping requested OID prefixes to the returned value. Successful walks will be mapped to an array of two-element arrays,
101
- # each of which consists of [_oid_ , _value_]. Unsuccessful walks will be mapped to a symbol representing the error.
102
-
103
- # Optional arguments can be passed into _args_, including:
104
- # * _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)
105
- # * _max_results_ - Maximum number of results to be returned for any single OID prefix (default: nil = unlimited)
106
-
107
- def walk(oids, args = {})
108
- request = SnmpWalkRequest.new(self, oids, args)
109
- self.class.pending_requests << request
110
- return request
111
- end
112
- end
113
- end
1
+ $:.unshift File.expand_path(File.dirname(File.expand_path(__FILE__)))
2
+
3
+ require 'eventmachine'
4
+ require 'snmp'
5
+ require 'snmp4em/common'
6
+ require 'snmp4em/handler'
7
+ require 'snmp4em/snmp_v1'
8
+ require 'snmp4em/snmp_request'
9
+ require 'snmp4em/requests/snmp_get_request'
10
+ require 'snmp4em/requests/snmp_getnext_request'
11
+ require 'snmp4em/requests/snmp_set_request'
12
+ require 'snmp4em/requests/snmp_walk_request'
File without changes
File without changes
@@ -1,5 +1,3 @@
1
- require "snmp_request.rb"
2
-
3
1
  module SNMP4EM
4
2
 
5
3
  # Returned from SNMP4EM::SNMPv1.get(). This implements EM::Deferrable, so you can hang a callback()
@@ -1,5 +1,3 @@
1
- require "snmp_request.rb"
2
-
3
1
  module SNMP4EM
4
2
 
5
3
  # Returned from SNMP4EM::SNMPv1.getnext(). This implements EM::Deferrable, so you can hang a callback()
@@ -1,5 +1,3 @@
1
- require "snmp_request.rb"
2
-
3
1
  module SNMP4EM
4
2
 
5
3
  # Returned from SNMP4EM::SNMPv1.set(). This implements EM::Deferrable, so you can hang a callback()
@@ -1,5 +1,3 @@
1
- require "snmp_request.rb"
2
-
3
1
  module SNMP4EM
4
2
 
5
3
  # Returned from SNMP4EM::SNMPv1.walk(). This implements EM::Deferrable, so you can hang a callback()
File without changes
@@ -0,0 +1,104 @@
1
+ # The SNMP4EM library
2
+
3
+ module SNMP4EM
4
+ class SNMPv1
5
+ @pending_requests = []
6
+ @socket = nil
7
+
8
+ class << self
9
+ attr_reader :pending_requests
10
+ attr_reader :socket
11
+
12
+ def init_socket #:nodoc:
13
+ if @socket.nil?
14
+ @socket = EM::open_datagram_socket("0.0.0.0", 0, Handler)
15
+ end
16
+ end
17
+ end
18
+
19
+ attr_reader :host, :port, :community_ro, :community_rw, :timeout, :retries
20
+
21
+ # Creates a new object to communicate with SNMPv1 agents. Optionally pass in the following parameters:
22
+ # * _host_ - IP/hostname of remote agent (default: 127.0.0.1)
23
+ # * _port_ - UDP port on remote agent (default: 161)
24
+ # * _community_ - Community string to use (default: public)
25
+ # * _community_ro_ - Read-only community string to use for get/getnext/walk operations (default: public)
26
+ # * _community_rw_ - Read-write community string to use for set operations (default: public)
27
+ # * _timeout_ - Number of seconds to wait before a request times out (default: 1)
28
+ # * _retries_ - Number of retries before failing (default: 3)
29
+
30
+ def initialize(args = {})
31
+ @host = args[:host] || "127.0.0.1"
32
+ @port = args[:port] || 161
33
+ @community_ro = args[:community_ro] || args[:community] || "public"
34
+ @community_rw = args[:community_rw] || args[:community] || "public"
35
+ @timeout = args[:timeout] || 1
36
+ @retries = args[:retries] || 3
37
+
38
+ self.class.init_socket
39
+ end
40
+
41
+ def send(message) #:nodoc:
42
+ self.class.socket.send_datagram message.encode, @host, @port
43
+ end
44
+
45
+ # Sends an SNMP-GET request to the remote agent for all OIDs specified in the _oids_ array. Returns a SnmpGetRequest object,
46
+ # which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the result will be
47
+ # a hash, mapping requested OID values to results.
48
+ #
49
+ # Optional arguments can be passed into _args_, including:
50
+ # * _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)
51
+
52
+ def get(oids, args = {})
53
+ request = SnmpGetRequest.new(self, oids, args)
54
+ self.class.pending_requests << request
55
+ return request
56
+ end
57
+
58
+ # Sends an SNMP-GETNEXT request to the remote agent for all OIDs specified in the _oids_ array. Returns a SnmpGetRequest object,
59
+ # which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the result will be
60
+ # a hash, mapping requested OID values to two-element arrays consisting of [_next_oid_ , _next_value_]. Any values that produced an
61
+ # error will map to a symbol representing the error.
62
+ #
63
+ # Optional arguments can be passed into _args_, including:
64
+ # * _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)
65
+
66
+ def getnext(oids, args = {})
67
+ request = SnmpGetNextRequest.new(self, oids, args)
68
+ self.class.pending_requests << request
69
+ return request
70
+ end
71
+
72
+ # 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
73
+ # values. Values can either be specified as Ruby native strings/integers, or as SNMP-specific classes (SNMP::IpAddress, etc).
74
+ # Returns a SnmpSetRequest object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result.
75
+ # On success, the result will be a hash, mapping requested OID values to the returned value from the agent. Any values that were stored
76
+ # successfully will map to _true_, otherwise, the value will map to a symbol representing the error.
77
+ #
78
+ # Optional arguments can be passed into _args_, including:
79
+ # * _return_raw_ - Return error objects as SNMP::ResponseError instead of a symbol
80
+
81
+ def set(oids, args = {})
82
+ request = SnmpSetRequest.new(self, oids, args)
83
+ self.class.pending_requests << request
84
+ return request
85
+ end
86
+
87
+ # Sends a series of SNMP-GETNEXT requests to simulate an SNMP "walk" operation. Given an OID prefix, the library will keep requesting the
88
+ # next OID until that returned OID does not begin with the requested prefix. This gives the ability to retrieve entire portions of the
89
+ # SNMP tree in one "operation". Multiple OID prefixes can be passed into the _oids_ array, and will be fetched in parallel. The function returns
90
+ # a SnmpWalkRequest object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the
91
+ # result will be a hash, mapping requested OID prefixes to the returned value. Successful walks will be mapped to an array of two-element arrays,
92
+ # each of which consists of [_oid_ , _value_]. Unsuccessful walks will be mapped to a symbol representing the error.
93
+
94
+ # Optional arguments can be passed into _args_, including:
95
+ # * _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)
96
+ # * _max_results_ - Maximum number of results to be returned for any single OID prefix (default: nil = unlimited)
97
+
98
+ def walk(oids, args = {})
99
+ request = SnmpWalkRequest.new(self, oids, args)
100
+ self.class.pending_requests << request
101
+ return request
102
+ end
103
+ end
104
+ end
data/snmp4em.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{snmp4em}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Norman Elton"]
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.description = %q{A high-performance SNMP engine built on EventMachine and Ruby-SNMP}
11
11
  s.email = %q{normelton@gmail.com}
12
12
  s.extra_rdoc_files = ["README"]
13
- s.files = ["lib/common.rb", "lib/handler.rb", "lib/requests/snmp_get_request.rb", "lib/requests/snmp_getnext_request.rb", "lib/requests/snmp_set_request.rb", "lib/requests/snmp_walk_request.rb", "lib/snmp4em.rb", "lib/snmp_request.rb", "Rakefile", "README", "snmp4em.gemspec", "Manifest"]
13
+ s.files = ["lib/snmp4em/common.rb", "lib/snmp4em/handler.rb", "lib/snmp4em/requests/snmp_get_request.rb", "lib/snmp4em/requests/snmp_getnext_request.rb", "lib/snmp4em/requests/snmp_set_request.rb", "lib/snmp4em/requests/snmp_walk_request.rb", "lib/snmp4em/snmp_request.rb", "lib/snmp4em/snmp_v1.rb", "lib/snmp4em.rb", "Manifest", "Rakefile", "README", "snmp4em.gemspec"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/normelton/snmp4em}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Snmp4em", "--main", "README"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: normelton-snmp4em
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Norman Elton
@@ -22,18 +22,19 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README
24
24
  files:
25
- - lib/common.rb
26
- - lib/handler.rb
27
- - lib/requests/snmp_get_request.rb
28
- - lib/requests/snmp_getnext_request.rb
29
- - lib/requests/snmp_set_request.rb
30
- - lib/requests/snmp_walk_request.rb
25
+ - lib/snmp4em/common.rb
26
+ - lib/snmp4em/handler.rb
27
+ - lib/snmp4em/requests/snmp_get_request.rb
28
+ - lib/snmp4em/requests/snmp_getnext_request.rb
29
+ - lib/snmp4em/requests/snmp_set_request.rb
30
+ - lib/snmp4em/requests/snmp_walk_request.rb
31
+ - lib/snmp4em/snmp_request.rb
32
+ - lib/snmp4em/snmp_v1.rb
31
33
  - lib/snmp4em.rb
32
- - lib/snmp_request.rb
34
+ - Manifest
33
35
  - Rakefile
34
36
  - README
35
37
  - snmp4em.gemspec
36
- - Manifest
37
38
  has_rdoc: true
38
39
  homepage: http://github.com/normelton/snmp4em
39
40
  post_install_message: