Class: SNMP::SNMPv1_Trap

### Home Classes Methods

### In Files

- lib/snmp/pdu.rb

### Parent

Object

### Methods

- ::decode
- ::new
- #each_varbind
- #encode
- #generic_trap
- #generic_trap=

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- SNMP
- SNMP::BER
- SNMP::Counter32
- SNMP::Counter64
- SNMP::EndOfMibView
- SNMP::Gauge32
- SNMP::GetBulkRequest
- SNMP::GetNextRequest
- SNMP::GetRequest
- SNMP::InformRequest
- SNMP::Integer
- SNMP::Integer32
- SNMP::InvalidErrorStatus
- SNMP::InvalidGenericTrap
- SNMP::InvalidIpAddress
- SNMP::InvalidPduTag
- SNMP::InvalidTrapVarbind
- SNMP::IpAddress
- SNMP::MIB
- SNMP::MIB::ModuleNotLoadedError
- SNMP::Manager
- SNMP::Manager::Config
- SNMP::Message
- SNMP::NoSuchInstance
- SNMP::NoSuchObject
- SNMP::Null
- SNMP::ObjectId
- SNMP::ObjectName
- SNMP::OctetString
- SNMP::Opaque
- SNMP::PDU
- SNMP::ParseError
- SNMP::RequestId
- SNMP::RequestTimeout
- SNMP::Response
- SNMP::SNMPv1_Trap
- SNMP::SNMPv2_Trap
- SNMP::SetRequest
- SNMP::TimeTicks
- SNMP::TrapListener
- SNMP::TrapListener::Config
- SNMP::UDPServerTransport
- SNMP::UDPTransport
- SNMP::Unsigned32
- SNMP::UnsignedInteger
- SNMP::UnsupportedPduTag
- SNMP::UnsupportedValueTag
- SNMP::UnsupportedVersion
- SNMP::VarBind
- SNMP::VarBindList
- Fixnum
- Object

No matching classes.

# SNMP::SNMPv1_Trap

The PDU class for traps in SNMPv1.

### Constants

GENERIC_TRAP_CODE

  Code map for all of the generic traps defined in RFC 1157.

GENERIC_TRAP_NAME

  Name map for all of the generic traps defined in RFC 1157.

### Attributes

agent_addr[RW]
enterprise[RW]
source_ip[RW]

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

specific_trap[RW]
timestamp[RW]
varbind_list[RW]
vb_list[RW]

### Public Class Methods

decode(pdu_data, mib=nil) click to toggle source

    # File lib/snmp/pdu.rb, line 313
    def self.decode(pdu_data, mib=nil)
      oid_data, remainder = decode_object_id(pdu_data)
      enterprise = ObjectId.new(oid_data)
      ip_data, remainder = decode_ip_address(remainder)
      agent_addr = IpAddress.new(ip_data)
      generic_trap, remainder = decode_integer(remainder)
      specific_trap, remainder = decode_integer(remainder)
      time_data, remainder = decode_timeticks(remainder)
      timestamp = TimeTicks.new(time_data)
      varbind_list, remainder = VarBindList.decode(remainder, mib)
      assert_no_remainder(remainder)
      SNMPv1_Trap.new(enterprise, agent_addr, generic_trap, specific_trap,
                      timestamp, varbind_list)
    end

new(enterprise, agent_addr, generic_trap, specific_trap, timestamp, varbind_list) click to toggle source

    # File lib/snmp/pdu.rb, line 328
    def initialize(enterprise, agent_addr, generic_trap, specific_trap, timestamp, varbind_list)
      @enterprise = enterprise
      @agent_addr = agent_addr
      self.generic_trap = generic_trap
      @specific_trap = specific_trap
      @timestamp = timestamp
      @varbind_list = varbind_list
    end

### Public Instance Methods

each_varbind(&block) click to toggle source

    # File lib/snmp/pdu.rb, line 376
    def each_varbind(&block)
      @varbind_list.each(&block)
    end

encode() click to toggle source

    # File lib/snmp/pdu.rb, line 366
    def encode
      pdu_data = @enterprise.encode <<
        @agent_addr.encode <<
        encode_integer(@generic_trap) <<
        encode_integer(@specific_trap) <<
        @timestamp.encode <<
        @varbind_list.encode
      encode_tlv(SNMPv1_Trap_PDU_TAG, pdu_data)
    end

generic_trap() click to toggle source

    # File lib/snmp/pdu.rb, line 362
    def generic_trap
      GENERIC_TRAP_NAME[@generic_trap]
    end

generic_trap=(trap) click to toggle source

    # File lib/snmp/pdu.rb, line 351
    def generic_trap=(trap)
      @generic_trap = GENERIC_TRAP_CODE[trap]
      unless @generic_trap
        if trap.respond_to?(:to_i) && GENERIC_TRAP_NAME[trap.to_i]
          @generic_trap = trap
        else
          raise InvalidGenericTrap, trap.to_s
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.