예제 #1
0
  /**
   * Sends an SNMP tra
   *
   * @param gtrap general trap type
   * @param strap specific trap type
   * @param oid enterprise OID
   * @param vars additional (named) attributes
   */
  public void trap(int gtrap, int strap, SNMPObjectIdentifier oid, SNMPVariablePair... vars) {
    try {
      SNMPTimeTicks timestamp = new SNMPTimeTicks((long) (System.currentTimeMillis() / 10));
      SNMPVarBindList varBindList = new SNMPVarBindList();

      for (SNMPVariablePair var : vars) {
        varBindList.addSNMPObject(var);
      }

      SNMPSequence trap = null;
      if (protocol == SnmpLib.SNMP_V1) {
        trap = new SNMPv1TrapPDU(oid, agentAddr, gtrap, strap, timestamp, varBindList);
      } else if (protocol == SnmpLib.SNMP_V2) {
        trap = new SNMPv2TrapPDU(timestamp, oid, varBindList);
      } else {
        log.error(ZorkaLogger.ZAG_ERRORS, "Unsupported SNMP protocol version: " + protocol);
      }

      if (trap != null) {
        AgentDiagnostics.inc(countTraps, AgentDiagnostics.TRAPS_SUBMITTED);
        if (!submit(trap)) {
          AgentDiagnostics.inc(countTraps, AgentDiagnostics.TRAPS_DROPPED);
        }
      }

    } catch (Exception e) {
      log.error(ZorkaLogger.ZAG_ERRORS, "Error creating trap object", e);
    }
  }
예제 #2
0
 @Override
 protected void process(SNMPSequence trap) {
   try {
     if (trap instanceof SNMPv1TrapPDU) {
       sender.sendTrap(snmpAddr, community, (SNMPv1TrapPDU) trap);
     } else if (trap instanceof SNMPv2TrapPDU) {
       sender.sendTrap(snmpAddr, community, (SNMPv2TrapPDU) trap);
     }
     AgentDiagnostics.inc(countTraps, AgentDiagnostics.TRAPS_SENT);
   } catch (IOException e) {
     log.error(ZorkaLogger.ZAG_ERRORS, "Error sending SNMP trap", e);
   }
 }