Class: Net::SNMP::MIB::Node
- Inherits:
-
Object
- Object
- Net::SNMP::MIB::Node
- Extended by:
- Forwardable, Debug
- Includes:
- Debug
- Defined in:
- lib/net/snmp/mib/node.rb
Instance Attribute Summary collapse
-
#struct ⇒ Object
Returns the value of attribute struct.
Class Method Summary collapse
Instance Method Summary collapse
- #children {|child| ... } ⇒ Object
-
#descendants(&block) ⇒ Object
Depth-first traversal of all descendants.
- #description ⇒ Object
- #enums ⇒ Object
- #exists_in_mib? ⇒ Boolean (also: #in_mib?)
-
#initialize(arg) ⇒ Node
constructor
A new instance of Node.
- #module ⇒ Object
-
#next ⇒ Object
actually seems like list is linked backward, so this will retrieve the previous oid numerically.
- #next_peer ⇒ Object
- #oid ⇒ Object
- #parent ⇒ Object
- #peers ⇒ Object (also: #siblings)
Methods included from Debug
Constructor Details
#initialize(arg) ⇒ Node
Returns a new instance of Node.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/net/snmp/mib/node.rb', line 24 def initialize(arg) @oid = nil @module = nil case arg when Wrapper::Tree @struct = arg when FFI::Pointer @struct = Wrapper::Tree.new(arg) else raise "invalid type" end end |
Instance Attribute Details
#struct ⇒ Object
Returns the value of attribute struct.
8 9 10 |
# File 'lib/net/snmp/mib/node.rb', line 8 def struct @struct end |
Class Method Details
.get_node(oid) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/net/snmp/mib/node.rb', line 13 def get_node(oid) if oid.kind_of?(String) oid = OID.new(oid) end struct = Wrapper.get_tree(oid.pointer, oid.length_pointer.read_int, Wrapper.get_tree_head().pointer) node = new(struct.pointer) warn "OID #{oid.to_s} not found in MIB" unless node.in_mib? node end |
Instance Method Details
#children {|child| ... } ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/net/snmp/mib/node.rb', line 82 def children return to_enum __method__ unless block_given? return if @struct.child_list.null? child = self.class.new(@struct.child_list) yield child while child = child.next_peer yield child end end |
#descendants(&block) ⇒ Object
Depth-first traversal of all descendants
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/net/snmp/mib/node.rb', line 93 def descendants(&block) return to_enum __method__ unless block_given? return if @struct.child_list.null? child = self.class.new(@struct.child_list) block[child] child.descendants(&block) while child = child.next_peer block[child] child.descendants(&block) end end |
#description ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/net/snmp/mib/node.rb', line 53 def description if @struct.description.null? nil else @struct.description.read_string end end |
#enums ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/net/snmp/mib/node.rb', line 111 def enums return to_enum __method__ unless block_given? enum = struct.enums while !enum.null? yield({value: enum.value, label: enum.label.read_string}) enum = enum.next end end |
#exists_in_mib? ⇒ Boolean Also known as: in_mib?
37 38 39 40 41 42 43 |
# File 'lib/net/snmp/mib/node.rb', line 37 def exists_in_mib? # The structure can be created without the oid actually # existing in the mib, but the parent will be null. # Of course, the parent is null for the root node as well, # so ignore that case. (!@struct.parent.null?) || oid.to_s == '1' end |
#module ⇒ Object
46 47 48 49 50 51 |
# File 'lib/net/snmp/mib/node.rb', line 46 def module unless @module @module = Module.find(modid) end @module end |
#next ⇒ Object
actually seems like list is linked backward, so this will retrieve the previous oid numerically
67 68 69 70 |
# File 'lib/net/snmp/mib/node.rb', line 67 def next return nil if @struct.next.null? self.class.new(@struct.next) end |
#next_peer ⇒ Object
72 73 74 75 |
# File 'lib/net/snmp/mib/node.rb', line 72 def next_peer return nil if @struct.next_peer.null? self.class.new(@struct.next_peer) end |
#oid ⇒ Object
61 62 63 64 |
# File 'lib/net/snmp/mib/node.rb', line 61 def oid return @oid if @oid @oid = OID.new(label) end |
#parent ⇒ Object
77 78 79 80 |
# File 'lib/net/snmp/mib/node.rb', line 77 def parent return nil if @struct.parent.null? self.class.new(@struct.parent) end |
#peers ⇒ Object Also known as: siblings
105 106 107 108 |
# File 'lib/net/snmp/mib/node.rb', line 105 def peers return [] if oid.to_s == '1' parent.children.reject { |n| n.oid.to_s == oid.to_s } end |