snmp 0.5.1 → 0.6.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.
@@ -93,6 +93,11 @@ class Integer
93
93
  def encode
94
94
  encode_integer(@value)
95
95
  end
96
+
97
+ def to_oid
98
+ raise RangeError, "@{value} cannot be an OID (must be >0)" if @value < 0
99
+ ObjectId.new([@value])
100
+ end
96
101
  end
97
102
 
98
103
  class Integer32 < Integer
@@ -115,6 +120,12 @@ class OctetString < String
115
120
  def encode
116
121
  encode_octet_string(self)
117
122
  end
123
+
124
+ def to_oid
125
+ oid = ObjectId.new
126
+ each_byte { |b| oid << b }
127
+ oid
128
+ end
118
129
  end
119
130
 
120
131
  class ObjectId < Array
@@ -133,19 +144,25 @@ class ObjectId < Array
133
144
  # in the format "n.n.n.n.n.n" or an array of integers.
134
145
  #
135
146
  def initialize(id=[])
136
- if id.respond_to? :to_str
147
+ if id.nil?
148
+ raise ArgumentError
149
+ elsif id.respond_to? :to_str
137
150
  super(make_integers(id.to_str.split(".")))
138
151
  else
139
152
  super(make_integers(id.to_ary))
140
153
  end
141
154
  rescue ArgumentError
142
- raise ArgumentError, "'#{id}' not a valid object ID"
155
+ raise ArgumentError, "#{id.inspect}:#{id.class} not a valid object ID"
143
156
  end
144
157
 
145
158
  def to_varbind
146
159
  VarBind.new(self, Null)
147
160
  end
148
161
 
162
+ def to_oid
163
+ self
164
+ end
165
+
149
166
  def to_s
150
167
  self.join('.')
151
168
  end
@@ -163,9 +180,7 @@ class ObjectId < Array
163
180
  # ObjectId. For example, "1.3.6.1.5" is a subtree of "1.3.6.1".
164
181
  #
165
182
  def subtree_of?(parent_tree)
166
- unless parent_tree.kind_of? ObjectId
167
- parent_tree = ObjectId.new(parent_tree)
168
- end
183
+ parent_tree = make_object_id(parent_tree)
169
184
  if parent_tree.length > self.length
170
185
  false
171
186
  else
@@ -176,11 +191,34 @@ class ObjectId < Array
176
191
  end
177
192
  end
178
193
 
194
+ ##
195
+ # Returns an index based on the difference between this ObjectId
196
+ # and the provided parent ObjectId.
197
+ #
198
+ # For example, ObjectId.new("1.3.6.1.5").index("1.3.6.1") returns an
199
+ # ObjectId of "5".
200
+ #
201
+ def index(parent_tree)
202
+ parent_tree = make_object_id(parent_tree)
203
+ if not subtree_of?(parent_tree)
204
+ raise ArgumentError, "#{self.to_s} not a subtree of #{parent_tree.to_s}"
205
+ elsif self.length == parent_tree.length
206
+ raise ArgumentError, "OIDs are the same"
207
+ else
208
+ ObjectId.new(self[parent_tree.length..-1])
209
+ end
210
+ end
211
+
179
212
  private
180
213
 
181
214
  def make_integers(list)
182
215
  list.collect{|n| Integer(n)}
216
+ end
217
+
218
+ def make_object_id(oid)
219
+ oid.kind_of?(ObjectId) ? oid : ObjectId.new(oid)
183
220
  end
221
+
184
222
  end
185
223
 
186
224
  class IpAddress
@@ -200,12 +238,13 @@ class IpAddress
200
238
  # (i.e. "10.1.2.3").
201
239
  #
202
240
  def initialize(value_data)
203
- if value_data.length > 4
204
- value_data = parse_string(value_data)
205
- elsif value_data.length != 4
241
+ ip = value_data.to_str
242
+ if ip.length > 4
243
+ ip = parse_string(ip)
244
+ elsif ip.length != 4
206
245
  raise InvalidIpAddress, "Expected 4 octets or formatted string, got #{value_data.inspect}"
207
246
  end
208
- @value = value_data
247
+ @value = ip
209
248
  end
210
249
 
211
250
  ##
@@ -224,6 +263,12 @@ class IpAddress
224
263
  octets.join('.')
225
264
  end
226
265
 
266
+ def to_oid
267
+ oid = ObjectId.new
268
+ @value.each_byte { |b| oid << b }
269
+ oid
270
+ end
271
+
227
272
  def ==(other)
228
273
  if other.respond_to? :to_str
229
274
  return @value.eql?(other.to_str)
@@ -442,6 +487,8 @@ class VarBind
442
487
  attr_accessor :name
443
488
  attr_accessor :value
444
489
 
490
+ alias :oid :name
491
+
445
492
  class << self
446
493
  def decode(data)
447
494
  varbind_data, remaining_varbind_data = decode_sequence(data)
@@ -0,0 +1,81 @@
1
+ ---
2
+ -
3
+ - 1.3.6.1.2.1.2.2.1.1
4
+ - noSuchObject
5
+ - SNMP::NoSuchObject
6
+ -
7
+ - 1.3.6.1.2.1.2.2.1.1.1
8
+ - "1"
9
+ - SNMP::Integer
10
+ -
11
+ - 1.3.6.1.2.1.2.2.1.2
12
+ - noSuchObject
13
+ - SNMP::NoSuchObject
14
+ -
15
+ - 1.3.6.1.2.1.2.2.1.2.1
16
+ - lo0
17
+ - SNMP::OctetString
18
+ -
19
+ - 1.3.6.1.2.1.2.2.1.3
20
+ - noSuchObject
21
+ - SNMP::NoSuchObject
22
+ -
23
+ - 1.3.6.1.2.1.2.2.1.4.1
24
+ - "16384"
25
+ - SNMP::Integer
26
+ -
27
+ - 1.3.6.1.2.1.2.2.1.5.1
28
+ - "0"
29
+ - SNMP::Gauge32
30
+ -
31
+ - 1.3.6.1.2.1.2.2.1.7.1
32
+ - "1"
33
+ - SNMP::Integer
34
+ -
35
+ - 1.3.6.1.2.1.2.2.1.8.1
36
+ - "1"
37
+ - SNMP::Integer
38
+ -
39
+ - 1.3.6.1.2.1.2.2.1.9.1
40
+ - "0"
41
+ - SNMP::TimeTicks
42
+ -
43
+ - 1.3.6.1.2.1.2.2.1.10.1
44
+ - "18228208"
45
+ - SNMP::Counter32
46
+ -
47
+ - 1.3.6.1.2.1.2.2.1.11.1
48
+ - "141603"
49
+ - SNMP::Counter32
50
+ -
51
+ - 1.3.6.1.2.1.2.2.1.12.1
52
+ - "12738"
53
+ - SNMP::Counter32
54
+ -
55
+ - 1.3.6.1.2.1.2.2.1.13.1
56
+ - "0"
57
+ - SNMP::Counter32
58
+ -
59
+ - 1.3.6.1.2.1.2.2.1.14.1
60
+ - "0"
61
+ - SNMP::Counter32
62
+ -
63
+ - 1.3.6.1.2.1.2.2.1.15.1
64
+ - "0"
65
+ - SNMP::Counter32
66
+ -
67
+ - 1.3.6.1.2.1.2.2.1.16.1
68
+ - "18233800"
69
+ - SNMP::Counter32
70
+ -
71
+ - 1.3.6.1.2.1.2.2.1.17.1
72
+ - "154413"
73
+ - SNMP::Counter32
74
+ -
75
+ - 1.3.6.1.2.1.2.2.1.18.1
76
+ - "0"
77
+ - SNMP::Counter32
78
+ -
79
+ - 1.3.6.1.2.1.2.2.1.20.1
80
+ - "0"
81
+ - SNMP::Counter32
@@ -0,0 +1,441 @@
1
+ ---
2
+ -
3
+ - 1.3.6.1.2.1.2.2.1.1
4
+ - noSuchObject
5
+ - SNMP::NoSuchObject
6
+ -
7
+ - 1.3.6.1.2.1.2.2.1.1.1
8
+ - "1"
9
+ - SNMP::Integer
10
+ -
11
+ - 1.3.6.1.2.1.2.2.1.1.2
12
+ - "2"
13
+ - SNMP::Integer
14
+ -
15
+ - 1.3.6.1.2.1.2.2.1.1.3
16
+ - "3"
17
+ - SNMP::Integer
18
+ -
19
+ - 1.3.6.1.2.1.2.2.1.1.4
20
+ - "4"
21
+ - SNMP::Integer
22
+ -
23
+ - 1.3.6.1.2.1.2.2.1.1.5
24
+ - "5"
25
+ - SNMP::Integer
26
+ -
27
+ - 1.3.6.1.2.1.2.2.1.1.6
28
+ - "6"
29
+ - SNMP::Integer
30
+ -
31
+ - 1.3.6.1.2.1.2.2.1.2
32
+ - noSuchObject
33
+ - SNMP::NoSuchObject
34
+ -
35
+ - 1.3.6.1.2.1.2.2.1.2.1
36
+ - lo0
37
+ - SNMP::OctetString
38
+ -
39
+ - 1.3.6.1.2.1.2.2.1.2.2
40
+ - gif0
41
+ - SNMP::OctetString
42
+ -
43
+ - 1.3.6.1.2.1.2.2.1.2.3
44
+ - stf0
45
+ - SNMP::OctetString
46
+ -
47
+ - 1.3.6.1.2.1.2.2.1.2.4
48
+ - en0
49
+ - SNMP::OctetString
50
+ -
51
+ - 1.3.6.1.2.1.2.2.1.2.5
52
+ - en1
53
+ - SNMP::OctetString
54
+ -
55
+ - 1.3.6.1.2.1.2.2.1.2.6
56
+ - fw0
57
+ - SNMP::OctetString
58
+ -
59
+ - 1.3.6.1.2.1.2.2.1.3.1
60
+ - "24"
61
+ - SNMP::Integer
62
+ -
63
+ - 1.3.6.1.2.1.2.2.1.3.2
64
+ - "55"
65
+ - SNMP::Integer
66
+ -
67
+ - 1.3.6.1.2.1.2.2.1.3.3
68
+ - "57"
69
+ - SNMP::Integer
70
+ -
71
+ - 1.3.6.1.2.1.2.2.1.3.4
72
+ - "6"
73
+ - SNMP::Integer
74
+ -
75
+ - 1.3.6.1.2.1.2.2.1.3.5
76
+ - "6"
77
+ - SNMP::Integer
78
+ -
79
+ - 1.3.6.1.2.1.2.2.1.3.6
80
+ - "144"
81
+ - SNMP::Integer
82
+ -
83
+ - 1.3.6.1.2.1.2.2.1.4.1
84
+ - "16384"
85
+ - SNMP::Integer
86
+ -
87
+ - 1.3.6.1.2.1.2.2.1.4.2
88
+ - "1280"
89
+ - SNMP::Integer
90
+ -
91
+ - 1.3.6.1.2.1.2.2.1.4.3
92
+ - "1280"
93
+ - SNMP::Integer
94
+ -
95
+ - 1.3.6.1.2.1.2.2.1.4.4
96
+ - "1500"
97
+ - SNMP::Integer
98
+ -
99
+ - 1.3.6.1.2.1.2.2.1.4.5
100
+ - "1500"
101
+ - SNMP::Integer
102
+ -
103
+ - 1.3.6.1.2.1.2.2.1.4.6
104
+ - "4078"
105
+ - SNMP::Integer
106
+ -
107
+ - 1.3.6.1.2.1.2.2.1.5.1
108
+ - "0"
109
+ - SNMP::Gauge32
110
+ -
111
+ - 1.3.6.1.2.1.2.2.1.5.2
112
+ - "0"
113
+ - SNMP::Gauge32
114
+ -
115
+ - 1.3.6.1.2.1.2.2.1.5.3
116
+ - "0"
117
+ - SNMP::Gauge32
118
+ -
119
+ - 1.3.6.1.2.1.2.2.1.5.4
120
+ - "10000000"
121
+ - SNMP::Gauge32
122
+ -
123
+ - 1.3.6.1.2.1.2.2.1.5.5
124
+ - "10000000"
125
+ - SNMP::Gauge32
126
+ -
127
+ - 1.3.6.1.2.1.2.2.1.5.6
128
+ - "10000000"
129
+ - SNMP::Gauge32
130
+ -
131
+ - 1.3.6.1.2.1.2.2.1.7.1
132
+ - "1"
133
+ - SNMP::Integer
134
+ -
135
+ - 1.3.6.1.2.1.2.2.1.7.2
136
+ - "2"
137
+ - SNMP::Integer
138
+ -
139
+ - 1.3.6.1.2.1.2.2.1.7.3
140
+ - "2"
141
+ - SNMP::Integer
142
+ -
143
+ - 1.3.6.1.2.1.2.2.1.7.4
144
+ - "1"
145
+ - SNMP::Integer
146
+ -
147
+ - 1.3.6.1.2.1.2.2.1.7.5
148
+ - "1"
149
+ - SNMP::Integer
150
+ -
151
+ - 1.3.6.1.2.1.2.2.1.7.6
152
+ - "1"
153
+ - SNMP::Integer
154
+ -
155
+ - 1.3.6.1.2.1.2.2.1.8.1
156
+ - "1"
157
+ - SNMP::Integer
158
+ -
159
+ - 1.3.6.1.2.1.2.2.1.8.2
160
+ - "2"
161
+ - SNMP::Integer
162
+ -
163
+ - 1.3.6.1.2.1.2.2.1.8.3
164
+ - "2"
165
+ - SNMP::Integer
166
+ -
167
+ - 1.3.6.1.2.1.2.2.1.8.4
168
+ - "1"
169
+ - SNMP::Integer
170
+ -
171
+ - 1.3.6.1.2.1.2.2.1.8.5
172
+ - "1"
173
+ - SNMP::Integer
174
+ -
175
+ - 1.3.6.1.2.1.2.2.1.8.6
176
+ - "1"
177
+ - SNMP::Integer
178
+ -
179
+ - 1.3.6.1.2.1.2.2.1.9.1
180
+ - "0"
181
+ - SNMP::TimeTicks
182
+ -
183
+ - 1.3.6.1.2.1.2.2.1.9.2
184
+ - "0"
185
+ - SNMP::TimeTicks
186
+ -
187
+ - 1.3.6.1.2.1.2.2.1.9.3
188
+ - "0"
189
+ - SNMP::TimeTicks
190
+ -
191
+ - 1.3.6.1.2.1.2.2.1.9.4
192
+ - "0"
193
+ - SNMP::TimeTicks
194
+ -
195
+ - 1.3.6.1.2.1.2.2.1.9.5
196
+ - "0"
197
+ - SNMP::TimeTicks
198
+ -
199
+ - 1.3.6.1.2.1.2.2.1.9.6
200
+ - "0"
201
+ - SNMP::TimeTicks
202
+ -
203
+ - 1.3.6.1.2.1.2.2.1.10.1
204
+ - "18228208"
205
+ - SNMP::Counter32
206
+ -
207
+ - 1.3.6.1.2.1.2.2.1.10.2
208
+ - "0"
209
+ - SNMP::Counter32
210
+ -
211
+ - 1.3.6.1.2.1.2.2.1.10.3
212
+ - "0"
213
+ - SNMP::Counter32
214
+ -
215
+ - 1.3.6.1.2.1.2.2.1.10.4
216
+ - "561918678"
217
+ - SNMP::Counter32
218
+ -
219
+ - 1.3.6.1.2.1.2.2.1.10.5
220
+ - "0"
221
+ - SNMP::Counter32
222
+ -
223
+ - 1.3.6.1.2.1.2.2.1.10.6
224
+ - "0"
225
+ - SNMP::Counter32
226
+ -
227
+ - 1.3.6.1.2.1.2.2.1.11.1
228
+ - "141603"
229
+ - SNMP::Counter32
230
+ -
231
+ - 1.3.6.1.2.1.2.2.1.11.2
232
+ - "0"
233
+ - SNMP::Counter32
234
+ -
235
+ - 1.3.6.1.2.1.2.2.1.11.3
236
+ - "0"
237
+ - SNMP::Counter32
238
+ -
239
+ - 1.3.6.1.2.1.2.2.1.11.4
240
+ - "544419"
241
+ - SNMP::Counter32
242
+ -
243
+ - 1.3.6.1.2.1.2.2.1.11.5
244
+ - "0"
245
+ - SNMP::Counter32
246
+ -
247
+ - 1.3.6.1.2.1.2.2.1.11.6
248
+ - "0"
249
+ - SNMP::Counter32
250
+ -
251
+ - 1.3.6.1.2.1.2.2.1.12.1
252
+ - "12738"
253
+ - SNMP::Counter32
254
+ -
255
+ - 1.3.6.1.2.1.2.2.1.12.2
256
+ - "0"
257
+ - SNMP::Counter32
258
+ -
259
+ - 1.3.6.1.2.1.2.2.1.12.3
260
+ - "0"
261
+ - SNMP::Counter32
262
+ -
263
+ - 1.3.6.1.2.1.2.2.1.12.4
264
+ - "159"
265
+ - SNMP::Counter32
266
+ -
267
+ - 1.3.6.1.2.1.2.2.1.12.5
268
+ - "0"
269
+ - SNMP::Counter32
270
+ -
271
+ - 1.3.6.1.2.1.2.2.1.12.6
272
+ - "0"
273
+ - SNMP::Counter32
274
+ -
275
+ - 1.3.6.1.2.1.2.2.1.13.1
276
+ - "0"
277
+ - SNMP::Counter32
278
+ -
279
+ - 1.3.6.1.2.1.2.2.1.13.2
280
+ - "0"
281
+ - SNMP::Counter32
282
+ -
283
+ - 1.3.6.1.2.1.2.2.1.13.3
284
+ - "0"
285
+ - SNMP::Counter32
286
+ -
287
+ - 1.3.6.1.2.1.2.2.1.13.4
288
+ - "0"
289
+ - SNMP::Counter32
290
+ -
291
+ - 1.3.6.1.2.1.2.2.1.13.5
292
+ - "0"
293
+ - SNMP::Counter32
294
+ -
295
+ - 1.3.6.1.2.1.2.2.1.13.6
296
+ - "0"
297
+ - SNMP::Counter32
298
+ -
299
+ - 1.3.6.1.2.1.2.2.1.14.1
300
+ - "0"
301
+ - SNMP::Counter32
302
+ -
303
+ - 1.3.6.1.2.1.2.2.1.14.2
304
+ - "0"
305
+ - SNMP::Counter32
306
+ -
307
+ - 1.3.6.1.2.1.2.2.1.14.3
308
+ - "0"
309
+ - SNMP::Counter32
310
+ -
311
+ - 1.3.6.1.2.1.2.2.1.14.4
312
+ - "0"
313
+ - SNMP::Counter32
314
+ -
315
+ - 1.3.6.1.2.1.2.2.1.14.5
316
+ - "0"
317
+ - SNMP::Counter32
318
+ -
319
+ - 1.3.6.1.2.1.2.2.1.14.6
320
+ - "0"
321
+ - SNMP::Counter32
322
+ -
323
+ - 1.3.6.1.2.1.2.2.1.15.1
324
+ - "0"
325
+ - SNMP::Counter32
326
+ -
327
+ - 1.3.6.1.2.1.2.2.1.15.2
328
+ - "0"
329
+ - SNMP::Counter32
330
+ -
331
+ - 1.3.6.1.2.1.2.2.1.15.3
332
+ - "0"
333
+ - SNMP::Counter32
334
+ -
335
+ - 1.3.6.1.2.1.2.2.1.15.4
336
+ - "0"
337
+ - SNMP::Counter32
338
+ -
339
+ - 1.3.6.1.2.1.2.2.1.15.5
340
+ - "0"
341
+ - SNMP::Counter32
342
+ -
343
+ - 1.3.6.1.2.1.2.2.1.15.6
344
+ - "0"
345
+ - SNMP::Counter32
346
+ -
347
+ - 1.3.6.1.2.1.2.2.1.16.1
348
+ - "18233800"
349
+ - SNMP::Counter32
350
+ -
351
+ - 1.3.6.1.2.1.2.2.1.16.2
352
+ - "0"
353
+ - SNMP::Counter32
354
+ -
355
+ - 1.3.6.1.2.1.2.2.1.16.3
356
+ - "0"
357
+ - SNMP::Counter32
358
+ -
359
+ - 1.3.6.1.2.1.2.2.1.16.4
360
+ - "68141195"
361
+ - SNMP::Counter32
362
+ -
363
+ - 1.3.6.1.2.1.2.2.1.16.5
364
+ - "342"
365
+ - SNMP::Counter32
366
+ -
367
+ - 1.3.6.1.2.1.2.2.1.16.6
368
+ - "346"
369
+ - SNMP::Counter32
370
+ -
371
+ - 1.3.6.1.2.1.2.2.1.17.1
372
+ - "154413"
373
+ - SNMP::Counter32
374
+ -
375
+ - 1.3.6.1.2.1.2.2.1.17.2
376
+ - "0"
377
+ - SNMP::Counter32
378
+ -
379
+ - 1.3.6.1.2.1.2.2.1.17.3
380
+ - "0"
381
+ - SNMP::Counter32
382
+ -
383
+ - 1.3.6.1.2.1.2.2.1.17.4
384
+ - "351526"
385
+ - SNMP::Counter32
386
+ -
387
+ - 1.3.6.1.2.1.2.2.1.17.5
388
+ - "0"
389
+ - SNMP::Counter32
390
+ -
391
+ - 1.3.6.1.2.1.2.2.1.17.6
392
+ - "0"
393
+ - SNMP::Counter32
394
+ -
395
+ - 1.3.6.1.2.1.2.2.1.18.1
396
+ - "0"
397
+ - SNMP::Counter32
398
+ -
399
+ - 1.3.6.1.2.1.2.2.1.18.2
400
+ - "0"
401
+ - SNMP::Counter32
402
+ -
403
+ - 1.3.6.1.2.1.2.2.1.18.3
404
+ - "0"
405
+ - SNMP::Counter32
406
+ -
407
+ - 1.3.6.1.2.1.2.2.1.18.4
408
+ - "0"
409
+ - SNMP::Counter32
410
+ -
411
+ - 1.3.6.1.2.1.2.2.1.18.5
412
+ - "0"
413
+ - SNMP::Counter32
414
+ -
415
+ - 1.3.6.1.2.1.2.2.1.18.6
416
+ - "0"
417
+ - SNMP::Counter32
418
+ -
419
+ - 1.3.6.1.2.1.2.2.1.20.1
420
+ - "0"
421
+ - SNMP::Counter32
422
+ -
423
+ - 1.3.6.1.2.1.2.2.1.20.2
424
+ - "0"
425
+ - SNMP::Counter32
426
+ -
427
+ - 1.3.6.1.2.1.2.2.1.20.3
428
+ - "0"
429
+ - SNMP::Counter32
430
+ -
431
+ - 1.3.6.1.2.1.2.2.1.20.4
432
+ - "0"
433
+ - SNMP::Counter32
434
+ -
435
+ - 1.3.6.1.2.1.2.2.1.20.5
436
+ - "0"
437
+ - SNMP::Counter32
438
+ -
439
+ - 1.3.6.1.2.1.2.2.1.20.6
440
+ - "0"
441
+ - SNMP::Counter32