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.

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.



246
247
248
# File 'lib/snmp/pdu.rb', line 246

def source_ip
  @source_ip
end

Instance Method Details

#encodeObject



238
239
240
# File 'lib/snmp/pdu.rb', line 238

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.



253
254
255
256
257
258
259
260
261
# File 'lib/snmp/pdu.rb', line 253

def sys_up_time
    sys_up_time_oid = ObjectId.new("1.3.6.1.2.1.1.3.0")
    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.



268
269
270
271
272
273
274
275
276
# File 'lib/snmp/pdu.rb', line 268

def trap_oid
    snmp_trap_oid_oid = ObjectId.new("1.3.6.1.6.3.1.1.4.1.0")
    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