Module: NETSNMP::OID

Extended by:
OID
Included in:
OID
Defined in:
lib/netsnmp/oid.rb

Overview

Abstracts the OID structure

Constant Summary collapse

OIDREGEX =
/^[\d\.]*$/

Instance Method Summary collapse

Instance Method Details

#build(o) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/netsnmp/oid.rb', line 10

def build(o)
  case o
  when OID then o
  when Array
    o.join('.')
  when OIDREGEX
    o = o[1..-1] if o.start_with?('.')
    o
  # TODO: MIB to OID
  else raise Error, "can't convert #{o} to OID"
  end
end

#parent?(parent_oid, child_oid) ⇒ true, false

Returns whether the given OID belongs to the sub-tree.

Parameters:

  • child (OID, String)

    oid another oid

Returns:

  • (true, false)

    whether the given OID belongs to the sub-tree



30
31
32
# File 'lib/netsnmp/oid.rb', line 30

def parent?(parent_oid, child_oid)
  child_oid.match(%r/\A#{parent_oid}\./)
end

#to_asn(oid) ⇒ Object



23
24
25
# File 'lib/netsnmp/oid.rb', line 23

def to_asn(oid)
  OpenSSL::ASN1::ObjectId.new(oid)
end