Class: Net::SNMP::MIB::Node

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/net/snmp/mib/node.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ Node

Returns a new instance of Node.



18
19
20
21
22
23
24
25
# File 'lib/net/snmp/mib/node.rb', line 18

def initialize(arg)
  case arg
  when FFI::Pointer
    @struct = Wrapper::Tree.new(arg)
  else
    raise "invalid type"
  end
end

Instance Attribute Details

#structObject

Returns the value of attribute struct.



5
6
7
# File 'lib/net/snmp/mib/node.rb', line 5

def struct
  @struct
end

Class Method Details

.get_node(oid) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/net/snmp/mib/node.rb', line 9

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)
  new(struct.pointer)
end

Instance Method Details

#childrenObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/net/snmp/mib/node.rb', line 47

def children
  return nil unless @struct.child_list
  child = self.class.new(@struct.child_list)
  children = [child]
  while child = child.next
    children << child
  end
  children.pop
  children.reverse  # For some reason, net-snmp returns everything backwards
end

#descriptionObject



27
28
29
# File 'lib/net/snmp/mib/node.rb', line 27

def description
  @struct.description.read_string
end

#nextObject

actually seems like list is linked backward, so this will retrieve the previous oid numerically



37
38
39
40
# File 'lib/net/snmp/mib/node.rb', line 37

def next
  return nil unless @struct.next_peer
  self.class.new(@struct.next_peer)
end

#oidObject



31
32
33
34
# File 'lib/net/snmp/mib/node.rb', line 31

def oid
  return @oid if @oid
  @oid = OID.new(label)
end

#parentObject



42
43
44
45
# File 'lib/net/snmp/mib/node.rb', line 42

def parent
  return nil unless @struct.parent
  self.class.new(@struct.parent)
end

#siblingsObject



58
59
60
# File 'lib/net/snmp/mib/node.rb', line 58

def siblings
  parent.children
end