Class: Net::SNMP::MIB::Node
- Inherits:
-
Object
- Object
- Net::SNMP::MIB::Node
show all
- Extended by:
- Forwardable, Debug
- Includes:
- Debug
- Defined in:
- lib/net/snmp/mib/node.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Debug
debug, error, fatal, info, print_packet, time, warn
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
#is_in_mib ⇒ Object
Returns the value of attribute is_in_mib.
8
9
10
|
# File 'lib/net/snmp/mib/node.rb', line 8
def is_in_mib
@is_in_mib
end
|
#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?
(!@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
|