Class: Net::SNMP::Varbind

Inherits:
Object
  • Object
show all
Defined in:
lib/net/snmp/varbind.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr = nil) ⇒ Varbind

Returns a new instance of Varbind.



7
8
9
# File 'lib/net/snmp/varbind.rb', line 7

def initialize(ptr = nil)
  @struct = Net::SNMP::Wrapper::VariableList.new(ptr)
end

Instance Attribute Details

#structObject

Represents an SNMP Variable Binding



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

def struct
  @struct
end

Class Method Details

.from_pointer(ptr) ⇒ Object



11
12
13
# File 'lib/net/snmp/varbind.rb', line 11

def self.from_pointer(ptr)
  new(ptr)
end

Instance Method Details

#object_typeObject Also known as: type

Returns the data type of the varbind



16
17
18
# File 'lib/net/snmp/varbind.rb', line 16

def object_type
  @struct.type
end

#oidObject

Returns the OID associated with the varbind



22
23
24
# File 'lib/net/snmp/varbind.rb', line 22

def oid
  @oid ||= OID.from_pointer(@struct.name, @struct.name_length)
end

#valueObject

Returns the value of the varbind



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/net/snmp/varbind.rb', line 27

def value
  case object_type
  when Constants::ASN_OCTET_STR, Constants::ASN_OPAQUE
    struct.val[:string].read_string(struct.val_len)
  when Constants::ASN_INTEGER
    struct.val[:integer].read_long
  when Constants::ASN_UINTEGER, Constants::ASN_TIMETICKS,  Constants::ASN_COUNTER, Constants::ASN_GAUGE
    struct.val[:integer].read_ulong
  when Constants::ASN_IPADDRESS
    struct.val[:objid].read_string(struct.val_len).unpack('CCCC').join(".")
  when Constants::ASN_NULL
    nil
  when Constants::ASN_OBJECT_ID
    Net::SNMP::OID.from_pointer(struct.val[:objid], struct.val_len / OID.oid_size)
  when Constants::ASN_COUNTER64
    counter = Wrapper::Counter64.new(struct.val[:counter64])
    counter.high * 2^32 + counter.low
  when Constants::ASN_BIT_STR
    # XXX not sure what to do here.  Is this obsolete?

  when Constants::SNMP_ENDOFMIBVIEW
    :endofmibview
  when Constants::SNMP_NOSUCHOBJECT
    :nosuchobject
  when Constants::SNMP_NOSUCHINSTANCE
    :nosuchinstance
  else
    raise Net::SNMP::Error.new, "Unknown value type #{object_type}"
  end
end