Class: SNMP::VarBind

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

Constant Summary collapse

ValueDecoderMap =
{
  INTEGER_TAG           => Integer,
  OCTET_STRING_TAG      => OctetString,
  NULL_TAG              => Null,
  OBJECT_IDENTIFIER_TAG => ObjectId,
  IpAddress_TAG         => IpAddress,
  Counter32_TAG         => Counter32,
  Gauge32_TAG           => Gauge32,
  # note Gauge32 tag same as Unsigned32
  TimeTicks_TAG         => TimeTicks,
  Opaque_TAG            => Opaque,
  Counter64_TAG         => Counter64,
  NoSuchObject_TAG      => NoSuchObject,
  NoSuchInstance_TAG    => NoSuchInstance,
  EndOfMibView_TAG      => EndOfMibView
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = Null) ⇒ VarBind

Returns a new instance of VarBind



577
578
579
580
581
582
583
584
# File 'lib/snmp/varbind.rb', line 577

def initialize(name, value=Null)
  if name.kind_of? ObjectId
    @name = name
  else
    @name = ObjectName.new(name)
  end
  @value = value
end

Instance Attribute Details

#nameObject Also known as: oid

Returns the value of attribute name



534
535
536
# File 'lib/snmp/varbind.rb', line 534

def name
  @name
end

#valueObject

Returns the value of attribute value



535
536
537
# File 'lib/snmp/varbind.rb', line 535

def value
  @value
end

Class Method Details

.decode(data, mib = nil) ⇒ Object



540
541
542
543
544
545
546
# File 'lib/snmp/varbind.rb', line 540

def decode(data, mib=nil)
  varbind_data, remaining_varbind_data = decode_sequence(data)
  name, remainder = decode_object_id(varbind_data)
  value, remainder = decode_value(remainder)
  assert_no_remainder(remainder)
  return VarBind.new(name, value).with_mib(mib), remaining_varbind_data
end

.decode_value(data) ⇒ Object



565
566
567
568
569
570
571
572
573
574
# File 'lib/snmp/varbind.rb', line 565

def decode_value(data)
  value_tag, value_data, remainder = decode_tlv(data)
  decoder_class = ValueDecoderMap[value_tag]
  if decoder_class
    value = decoder_class.decode(value_data)
  else
    raise UnsupportedValueTag, value_tag.to_s
  end
  return value, remainder
end

Instance Method Details

#asn1_typeObject



595
596
597
# File 'lib/snmp/varbind.rb', line 595

def asn1_type
  "VarBind"
end

#each {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (SNMP::VarBind)

    the object that the method was called on



607
608
609
# File 'lib/snmp/varbind.rb', line 607

def each
  yield self
end

#encodeObject



611
612
613
614
# File 'lib/snmp/varbind.rb', line 611

def encode
  data = encode_object_id(@name) << value.encode
  encode_sequence(data)
end

#to_sObject



603
604
605
# File 'lib/snmp/varbind.rb', line 603

def to_s
  "[name=#{@name.to_s}, value=#{@value.to_s} (#{@value.asn1_type})]"
end

#to_varbindObject



599
600
601
# File 'lib/snmp/varbind.rb', line 599

def to_varbind
  self
end

#with_mib(mib) ⇒ Object

Adds MIB information to this varbind for use with to_s.



589
590
591
592
593
# File 'lib/snmp/varbind.rb', line 589

def with_mib(mib)
  @name.with_mib(mib) if @name
  @value.with_mib(mib) if @value.respond_to? :with_mib
  self
end