net-snmp 0.2.2 → 0.2.3

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.
@@ -78,6 +78,25 @@ An asynchronous SNMP-GET
78
78
  Net::SNMP::Dispatcher.select(false) #Setting timeout to false causes dispatcher to block until data is ready
79
79
  session.close
80
80
 
81
+ An SNMPv3 synchronous AuthPriv (encrypted) SNMP-GET
82
+
83
+ Net::SNMP::Session.open(:peername => "test.net-snmp.org",
84
+ :community => "demopublic",
85
+ :version => "3",
86
+ :security_level => Net::SNMP::Constants::SNMP_SEC_LEVEL_AUTHPRIV,
87
+ :auth_protocol => :sha1,
88
+ :priv_protocol => :des,
89
+ :username => "myuser",
90
+ :password => "mypassword"
91
+ ) {|session|
92
+ begin
93
+ pdu = session.get("sysDescr.0")
94
+ puts pdu.varbinds.first.value
95
+ rescue Net::SNMP::Error => e
96
+ puts e.message
97
+ end
98
+ end
99
+
81
100
  Running the dispatcher from eventmachine
82
101
  EM.run do
83
102
  Net::SNMP::Dispatcher.em_loop
@@ -31,6 +31,12 @@ module Net
31
31
  # * +version+ - snmp version. Possible values include 1, '2c', and 3. Default is 1.
32
32
  # * +timeout+ - snmp timeout in seconds
33
33
  # * +retries+ - snmp retries. default = 5
34
+ # * +security_level+ - SNMPv3 only. default = Net::SNMP::Constants::SNMP_SEC_LEVEL_NOAUTH
35
+ # * +auth_protocol+ - SNMPv3 only. default is nil (usmNoAuthProtocol). Possible values include :md5, :sha1, and nil
36
+ # * +priv_protocol+ - SNMPv3 only. default is nil (usmNoPrivProtocol). Possible values include :des, :aes, and nil
37
+ # * +context+ - SNMPv3 only.
38
+ # * +username+ - SNMPv3 only.
39
+ # * +password+ - SNMPv3 only.
34
40
  # Returns:
35
41
  # Net::SNMP::Session
36
42
  def open(options = {})
@@ -92,25 +98,64 @@ module Net
92
98
  when nil
93
99
  OID.new("1.3.6.1.6.3.10.1.1.1").pointer
94
100
  end
101
+ @sess.securityPrivProto = case options[:priv_protocol]
102
+ when :aes
103
+ OID.new("1.3.6.1.6.3.10.1.2.4").pointer
104
+ when :des
105
+ OID.new("1.3.6.1.6.3.10.1.2.2").pointer
106
+ when nil
107
+ OID.new("1.3.6.1.6.3.10.1.2.1").pointer
108
+ end
95
109
 
96
110
  @sess.securityAuthProtoLen = 10
97
111
  @sess.securityAuthKeyLen = Constants::USM_AUTH_KU_LEN
98
112
 
113
+ @sess.securityPrivProtoLen = 10
114
+ @sess.securityPrivKeyLen = Constants::USM_PRIV_KU_LEN
115
+
99
116
  if options[:context]
100
117
  @sess.contextName = FFI::MemoryPointer.from_string(options[:context])
101
118
  @sess.contextNameLen = options[:context].length
102
119
  end
103
120
 
104
- if options[:username]
105
- @sess.securityName = FFI::MemoryPointer.from_string(options[:username])
106
- @sess.securityNameLen = options[:username].length
107
- end
108
- auth_len_ptr = FFI::MemoryPointer.new(:size_t)
109
- auth_len_ptr.write_int(Constants::USM_AUTH_KU_LEN)
110
- key_result = Wrapper.generate_Ku(@sess.securityAuthProto, @sess.securityAuthProtoLen, options[:password], options[:password].length, @sess.securityAuthKey, auth_len_ptr)
111
- @sess.securityAuthKeyLen = auth_len_ptr.read_int
112
- unless key_result == Constants::SNMPERR_SUCCESS
113
- Wrapper.snmp_perror("netsnmp")
121
+ # Do not generate_Ku, unless we're Auth or AuthPriv
122
+ unless @sess.securityLevel == Constants::SNMP_SEC_LEVEL_NOAUTH
123
+ if options[:username].nil? or options[:password].nil?
124
+ raise Net::SNMP::Error.new "SecurityLevel requires username and password"
125
+ end
126
+ if options[:username]
127
+ @sess.securityName = FFI::MemoryPointer.from_string(options[:username])
128
+ @sess.securityNameLen = options[:username].length
129
+ end
130
+
131
+ auth_len_ptr = FFI::MemoryPointer.new(:size_t)
132
+ auth_len_ptr.write_int(Constants::USM_AUTH_KU_LEN)
133
+ auth_key_result = Wrapper.generate_Ku(@sess.securityAuthProto,
134
+ @sess.securityAuthProtoLen,
135
+ options[:password],
136
+ options[:password].length,
137
+ @sess.securityAuthKey,
138
+ auth_len_ptr)
139
+ @sess.securityAuthKeyLen = auth_len_ptr.read_int
140
+
141
+ if @sess.securityLevel == Constants::SNMP_SEC_LEVEL_AUTHPRIV
142
+ priv_len_ptr = FFI::MemoryPointer.new(:size_t)
143
+ priv_len_ptr.write_int(Constants::USM_PRIV_KU_LEN)
144
+
145
+ # NOTE I know this is handing off the AuthProto, but generates a proper
146
+ # key for encryption, and using PrivProto does not.
147
+ priv_key_result = Wrapper.generate_Ku(@sess.securityAuthProto,
148
+ @sess.securityAuthProtoLen,
149
+ options[:password],
150
+ options[:password].length,
151
+ @sess.securityPrivKey,
152
+ auth_len_ptr)
153
+ @sess.securityPrivKeyLen = priv_len_ptr.read_int
154
+ end
155
+
156
+ unless auth_key_result == Constants::SNMPERR_SUCCESS and priv_key_result == Constants::SNMPERR_SUCCESS
157
+ Wrapper.snmp_perror("netsnmp")
158
+ end
114
159
  end
115
160
  end
116
161
  # General callback just takes the pdu, calls the session callback if any, then the request specific callback.
@@ -1,5 +1,5 @@
1
1
  module Net
2
2
  module SNMP
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Ron McClain"]
11
11
  s.email = ["mixtli@github.com"]
12
- s.homepage = ""
12
+ s.homepage = "https://github.com/mixtli/net-snmp"
13
13
  s.summary = %q{Object oriented wrapper around C net-snmp libraries}
14
14
  s.description = %q{Uses ffi to create an object oriented wrapper around C net-snmp libraries}
15
15
 
@@ -19,6 +19,12 @@ Gem::Specification.new do |s|
19
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ["lib"]
22
+
23
+ # Documentation options
24
+ s.has_rdoc = true
25
+ s.extra_rdoc_files = %w{ README.rdoc }
26
+ s.rdoc_options = ["--main=README.rdoc", "--line-numbers", "--inline-source", "--title=#{s.name}-#{s.version} Documentation"]
27
+
22
28
  s.add_dependency 'ffi-inliner'
23
29
  s.add_dependency 'nice-ffi'
24
30
  s.add_development_dependency "rspec"
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-snmp
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 2
9
- version: 0.2.2
4
+ prerelease:
5
+ version: 0.2.3
10
6
  platform: ruby
11
7
  authors:
12
8
  - Ron McClain
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-05-04 00:00:00 -05:00
13
+ date: 2011-08-02 00:00:00 -05:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,8 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
24
  version: "0"
31
25
  type: :runtime
32
26
  version_requirements: *id001
@@ -38,8 +32,6 @@ dependencies:
38
32
  requirements:
39
33
  - - ">="
40
34
  - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
35
  version: "0"
44
36
  type: :runtime
45
37
  version_requirements: *id002
@@ -51,8 +43,6 @@ dependencies:
51
43
  requirements:
52
44
  - - ">="
53
45
  - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
46
  version: "0"
57
47
  type: :development
58
48
  version_requirements: *id003
@@ -64,8 +54,6 @@ dependencies:
64
54
  requirements:
65
55
  - - ">="
66
56
  - !ruby/object:Gem::Version
67
- segments:
68
- - 0
69
57
  version: "0"
70
58
  type: :development
71
59
  version_requirements: *id004
@@ -77,8 +65,8 @@ executables:
77
65
  - stress_test.rb
78
66
  extensions: []
79
67
 
80
- extra_rdoc_files: []
81
-
68
+ extra_rdoc_files:
69
+ - README.rdoc
82
70
  files:
83
71
  - .document
84
72
  - .gitignore
@@ -124,12 +112,15 @@ files:
124
112
  - spec/utility_spec.rb
125
113
  - spec/wrapper_spec.rb
126
114
  has_rdoc: true
127
- homepage: ""
115
+ homepage: https://github.com/mixtli/net-snmp
128
116
  licenses: []
129
117
 
130
118
  post_install_message:
131
- rdoc_options: []
132
-
119
+ rdoc_options:
120
+ - --main=README.rdoc
121
+ - --line-numbers
122
+ - --inline-source
123
+ - --title=net-snmp-0.2.3 Documentation
133
124
  require_paths:
134
125
  - lib
135
126
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -137,21 +128,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
128
  requirements:
138
129
  - - ">="
139
130
  - !ruby/object:Gem::Version
140
- segments:
141
- - 0
142
131
  version: "0"
143
132
  required_rubygems_version: !ruby/object:Gem::Requirement
144
133
  none: false
145
134
  requirements:
146
135
  - - ">="
147
136
  - !ruby/object:Gem::Version
148
- segments:
149
- - 0
150
137
  version: "0"
151
138
  requirements: []
152
139
 
153
140
  rubyforge_project: net-snmp
154
- rubygems_version: 1.3.7
141
+ rubygems_version: 1.6.2
155
142
  signing_key:
156
143
  specification_version: 3
157
144
  summary: Object oriented wrapper around C net-snmp libraries