Class: SNMP::ObjectId
Class Method Summary
collapse
Instance Method Summary
collapse
assert_no_remainder, build_integer, decode_integer, decode_integer_value, decode_ip_address, decode_object_id, decode_object_id_value, decode_octet_string, decode_sequence, decode_timeticks, decode_tlv, decode_uinteger_value
#encode_exception, #encode_integer, #encode_length, #encode_null, #encode_object_id, #encode_octet_string, #encode_sequence, #encode_tagged_integer, #encode_tlv, #integer_to_octets
Constructor Details
#initialize(id = [], mib = nil) ⇒ ObjectId
Create an object id. The input is expected to be either a string in the format “n.n.n.n.n.n” or an array of integers.
178
179
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/snmp/varbind.rb', line 178
def initialize(id=[], mib=nil)
if id.nil?
raise ArgumentError
elsif id.respond_to? :to_str
super(make_integers(id.to_str.split(".")))
else
super(make_integers(id.to_ary))
end
@mib = mib
rescue ArgumentError
raise ArgumentError, "#{id.inspect}:#{id.class} not a valid object ID"
end
|
Class Method Details
.decode(value_data, mib = nil) ⇒ Object
166
167
168
|
# File 'lib/snmp/varbind.rb', line 166
def self.decode(value_data, mib=nil)
ObjectId.new(decode_object_id_value(value_data), mib)
end
|
Instance Method Details
#asn1_type ⇒ Object
170
171
172
|
# File 'lib/snmp/varbind.rb', line 170
def asn1_type
"OBJECT IDENTIFIER"
end
|
#encode ⇒ Object
223
224
225
|
# File 'lib/snmp/varbind.rb', line 223
def encode
encode_object_id(self)
end
|
#index(parent_tree) ⇒ Object
Returns an index based on the difference between this ObjectId and the provided parent ObjectId.
For example, ObjectId.new(“1.3.6.1.5”).index(“1.3.6.1”) returns an ObjectId of “5”.
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/snmp/varbind.rb', line 250
def index(parent_tree)
parent_tree = make_object_id(parent_tree)
if not subtree_of?(parent_tree)
raise ArgumentError, "#{self.to_s} not a subtree of #{parent_tree.to_s}"
elsif self.length == parent_tree.length
raise ArgumentError, "OIDs are the same"
else
ObjectId.new(self[parent_tree.length..-1])
end
end
|
#inspect ⇒ Object
219
220
221
|
# File 'lib/snmp/varbind.rb', line 219
def inspect
"[#{to_str}]"
end
|
#subtree_of?(parent_tree) ⇒ Boolean
Returns true if this ObjectId is a subtree of the provided parent tree ObjectId. For example, “1.3.6.1.5” is a subtree of “1.3.6.1”.
231
232
233
234
235
236
237
238
239
240
241
|
# File 'lib/snmp/varbind.rb', line 231
def subtree_of?(parent_tree)
parent_tree = make_object_id(parent_tree)
if parent_tree.length > self.length
false
else
parent_tree.each_index do |i|
return false if parent_tree[i] != self[i]
end
true
end
end
|
#to_oid ⇒ Object
203
204
205
|
# File 'lib/snmp/varbind.rb', line 203
def to_oid
self
end
|
#to_s ⇒ Object
207
208
209
210
211
212
213
|
# File 'lib/snmp/varbind.rb', line 207
def to_s
if @mib
@mib.name(self)
else
to_str
end
end
|
#to_str ⇒ Object
215
216
217
|
# File 'lib/snmp/varbind.rb', line 215
def to_str
self.join('.')
end
|
#to_varbind ⇒ Object
199
200
201
|
# File 'lib/snmp/varbind.rb', line 199
def to_varbind
VarBind.new(self, Null)
end
|
#with_mib(mib) ⇒ Object
Adds MIB information to this object_id for use with to_s.
194
195
196
197
|
# File 'lib/snmp/varbind.rb', line 194
def with_mib(mib)
@mib = mib
self
end
|