コード例 #1
0
 @Override
 protected TrapIdentity getTrapIdentity() {
   // Get the value for the snmpTrapOID
   SnmpObjectId snmpTrapOid =
       (SnmpObjectId) m_pdu.getVarBindAt(V2TrapInformation.SNMP_TRAP_OID_INDEX).getValue();
   SnmpObjectId lastVarBindOid = m_pdu.getVarBindAt(getPduLength() - 1).getName();
   SnmpSyntax lastVarBindValue = m_pdu.getVarBindAt(getPduLength() - 1).getValue();
   return new TrapIdentity(
       SnmpObjId.get(snmpTrapOid.getIdentifiers()),
       SnmpObjId.get(lastVarBindOid.getIdentifiers()),
       new JoeSnmpValue(lastVarBindValue));
 }
コード例 #2
0
 @Override
 protected void validate() {
   //
   // verify the type
   //
   if (m_pdu.typeId() != (byte) (SnmpPduPacket.V2TRAP)) {
     // if not V2 trap, do nothing
     throw new IllegalArgumentException(
         "Received not SNMPv2 Trap from host "
             + getTrapAddress()
             + "PDU Type = "
             + m_pdu.getCommand());
   }
   if (log().isDebugEnabled()) {
     log().debug("V2 trap numVars or pdu length: " + getPduLength());
   }
   if (getPduLength() < 2) // check number of varbinds
   {
     throw new IllegalArgumentException(
         "V2 trap from "
             + getTrapAddress()
             + " IGNORED due to not having the required varbinds.  Have "
             + getPduLength()
             + ", needed 2");
   }
   // The first varbind has the sysUpTime
   // Modify the sysUpTime varbind to add the trailing 0 if it is
   // missing
   // The second varbind has the snmpTrapOID
   // Confirm that these two are present
   //
   String varBindName0 = m_pdu.getVarBindAt(0).getName().toString();
   String varBindName1 = m_pdu.getVarBindAt(1).getName().toString();
   if (varBindName0.equals(V2TrapInformation.EXTREME_SNMP_SYSUPTIME_OID)) {
     log()
         .info(
             "V2 trap from "
                 + getTrapAddress()
                 + " has been corrected due to the sysUptime.0 varbind not having been sent with a trailing 0.\n\tVarbinds received are : "
                 + varBindName0
                 + " and "
                 + varBindName1);
     varBindName0 = V2TrapInformation.SNMP_SYSUPTIME_OID;
   }
   if ((!(varBindName0.equals(V2TrapInformation.SNMP_SYSUPTIME_OID)))
       || (!(varBindName1.equals(V2TrapInformation.SNMP_TRAP_OID)))) {
     throw new IllegalArgumentException(
         "V2 trap from "
             + getTrapAddress()
             + " IGNORED due to not having the required varbinds.\n\tThe first varbind must be sysUpTime.0 and the second snmpTrapOID.0\n\tVarbinds received are : "
             + varBindName0
             + " and "
             + varBindName1);
   }
 }
コード例 #3
0
  @Override
  protected long getTimeStamp() {

    if (log().isDebugEnabled()) {
      log().debug("V2 trap first varbind value: " + m_pdu.getVarBindAt(0).getValue().toString());
    }

    switch (m_pdu.getVarBindAt(V2TrapInformation.SNMP_SYSUPTIME_OID_INDEX).getValue().typeId()) {
      case SnmpSMI.SMI_TIMETICKS:
        log().debug("V2 trap first varbind value is of type TIMETICKS (correct)");
        return ((SnmpTimeTicks)
                m_pdu.getVarBindAt(V2TrapInformation.SNMP_SYSUPTIME_OID_INDEX).getValue())
            .getValue();
      case SnmpSMI.SMI_INTEGER:
        log().debug("V2 trap first varbind value is of type INTEGER, casting to TIMETICKS");
        return ((SnmpInt32)
                m_pdu.getVarBindAt(V2TrapInformation.SNMP_SYSUPTIME_OID_INDEX).getValue())
            .getValue();
      default:
        throw new IllegalArgumentException(
            "V2 trap does not have the required first varbind as TIMETICKS - cannot process trap");
    }
  }
コード例 #4
0
 private SnmpVarBind getVarBindAt(int index) {
   return m_pdu.getVarBindAt(index);
 }