Class: SNMP::SNMPv2_Trap

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

Overview

The PDU class for traps in SNMPv2c. Methods are provided for retrieving the values of the mandatory varbinds: the system uptime and the OID of the trap. The complete varbind list is available through the usual varbind_list method. The first two varbinds in this list will always be the uptime and trap OID varbinds.

Direct Known Subclasses

InformRequest

Constant Summary

Constants inherited from PDU

PDU::ERROR_STATUS_CODE, PDU::ERROR_STATUS_NAME

Instance Attribute Summary collapse

Attributes inherited from PDU

#error_index, #request_id, #varbind_list

Instance Method Summary collapse

Methods inherited from PDU

decode, #each_varbind, #encode_pdu, #error_status, #error_status=, #initialize

Constructor Details

This class inherits a constructor from SNMP::PDU

Instance Attribute Details

#source_ipObject

Returns the source IP address for the trap, usually derived from the source IP address of the packet that delivered the trap.


267
268
269
# File 'lib/snmp/pdu.rb', line 267

def source_ip
  @source_ip
end

Instance Method Details

#encodeObject


259
260
261
# File 'lib/snmp/pdu.rb', line 259

def encode
  encode_pdu(SNMPv2_Trap_PDU_TAG)
end

#sys_up_timeObject

Returns the value of the mandatory sysUpTime varbind for this trap.

Throws InvalidTrapVarbind if the sysUpTime varbind is not present.


274
275
276
277
278
279
280
281
# File 'lib/snmp/pdu.rb', line 274

def sys_up_time
  varbind = @varbind_list[0]
  if varbind && (varbind.name == SYS_UP_TIME_OID)
    return varbind.value
  else
    raise InvalidTrapVarbind, "Expected sysUpTime.0, found " + varbind.to_s
  end
end

#trap_oidObject

Returns the value of the mandatory snmpTrapOID varbind for this trap.

Throws InvalidTrapVarbind if the snmpTrapOID varbind is not present.


288
289
290
291
292
293
294
295
# File 'lib/snmp/pdu.rb', line 288

def trap_oid
  varbind = @varbind_list[1]
  if varbind && (varbind.name == SNMP_TRAP_OID_OID)
    return varbind.value
  else
    raise InvalidTrapVarbind, "Expected snmpTrapOID.0, found " + varbind.to_s
  end
end