/**
   * {@inheritDoc}
   *
   * <p>This method is invoked by the EventIpcManager when a new event is available for processing.
   * Each message is examined for its Universal Event Identifier and the appropriate action is
   * taking based on each UEI.
   */
  @Override
  public void onEvent(Event event) {
    ThreadCategory log = ThreadCategory.getInstance(getClass());

    String eventUei = event.getUei();
    if (eventUei == null) return;

    if (log.isDebugEnabled()) log.debug("Received event: " + eventUei);

    if (eventUei.equals(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI)) {
      // add to known nodes
      if (Long.toString(event.getNodeid()) != null && event.getInterface() != null) {
        SyslogdIPMgr.setNodeId(event.getInterface(), event.getNodeid());
      }
      if (log.isDebugEnabled()) {
        log.debug("Added " + event.getInterface() + " to known node list");
      }
    } else if (eventUei.equals(EventConstants.INTERFACE_DELETED_EVENT_UEI)) {
      // remove from known nodes
      if (event.getInterface() != null) {
        SyslogdIPMgr.removeNodeId(event.getInterface());
      }
      if (log.isDebugEnabled()) {
        log.debug("Removed " + event.getInterface() + " from known node list");
      }
    } else if (eventUei.equals(EventConstants.INTERFACE_REPARENTED_EVENT_UEI)) {
      // add to known nodes
      if (Long.toString(event.getNodeid()) != null && event.getInterface() != null) {
        SyslogdIPMgr.setNodeId(event.getInterface(), event.getNodeid());
      }
      if (log.isDebugEnabled()) {
        log.debug("Reparented " + event.getInterface() + " to known node list");
      }
    }
  }
    /**
     * Process the received events. For each event, use the EventExpander to look up matching
     * eventconf entry and load info from that match, expand event parms, add event to database and
     * send event to appropriate listeners.
     */
    @Override
    public void run() {
      Events events = m_eventLog.getEvents();
      if (events == null || events.getEventCount() <= 0) {
        // no events to process
        return;
      }

      for (final Event event : events.getEventCollection()) {
        final ThreadCategory log = log();
        if (log.isDebugEnabled()) {
          // Log the uei, source, and other important aspects
          final String uuid = event.getUuid();
          log.debug("Event {");
          log.debug("  uuid  = " + (uuid != null && uuid.length() > 0 ? uuid : "<not-set>"));
          log.debug("  uei   = " + event.getUei());
          log.debug("  src   = " + event.getSource());
          log.debug("  iface = " + event.getInterface());
          log.debug("  time  = " + event.getTime());
          if (event.getParmCollection().size() > 0) {
            log.debug("  parms {");
            for (final Parm parm : event.getParmCollection()) {
              if ((parm.getParmName() != null) && (parm.getValue().getContent() != null)) {
                log.debug(
                    "    ("
                        + parm.getParmName().trim()
                        + ", "
                        + parm.getValue().getContent().trim()
                        + ")");
              }
            }
            log.debug("  }");
          }
          log.debug("}");
        }

        for (final EventProcessor eventProcessor : m_eventProcessors) {
          try {
            eventProcessor.process(m_eventLog.getHeader(), event);
          } catch (SQLException e) {
            log.warn(
                "Unable to process event using processor "
                    + eventProcessor
                    + "; not processing with any later processors.  Exception: "
                    + e,
                e);
            break;
          } catch (Throwable t) {
            log.warn(
                "Unknown exception processing event with processor "
                    + eventProcessor
                    + "; not processing with any later processors.  Exception: "
                    + t,
                t);
            break;
          }
        }
      }
    }
Exemplo n.º 3
0
  /**
   * nodeInterfaceServiceValid
   *
   * @param notif a {@link org.opennms.netmgt.config.notifications.Notification} object.
   * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
   * @return a boolean.
   */
  protected boolean nodeInterfaceServiceValid(final Notification notif, final Event event) {
    Assert.notNull(notif, "notif argument must not be null");
    Assert.notNull(event, "event argument must not be null");
    Assert.notNull(notif.getRule(), "getRule() on notif argument must not return null");

    /*
     *  If the event doesn't have a nodeId, interface, or service,
     *  return true since there is nothing on which to filter.
     */
    if (event.getNodeid() == 0 && event.getInterface() == null && event.getService() == null) {
      if ("MATCH-ANY-UEI".equals(notif.getUei())) {
        // TODO: Trim parentheses from the filter and trim whitespace from inside the
        // filter statement. This comparison is very brittle as it is.
        if ("ipaddr != '0.0.0.0'".equals(notif.getRule().toLowerCase())
            || "ipaddr iplike *.*.*.*".equals(notif.getRule().toLowerCase())) {
          return true;
        } else {
          return false;
        }
      }
      return true;
    }

    StringBuffer constraints = new StringBuffer();
    if (event.getNodeid() != 0) {
      constraints.append(" & (nodeId == " + event.getNodeid() + ")");
    }

    if (event.getInterface() != null && !"0.0.0.0".equals(event.getInterface())) {
      constraints.append(" & (ipAddr == '" + event.getInterface() + "')");
      if (event.getService() != null) {
        constraints.append(" & (serviceName == '" + event.getService() + "')");
      }
    }

    String rule = "((" + notif.getRule() + ")" + constraints + ")";

    return isRuleMatchingFilter(notif, rule);
  }
  /**
   * {@inheritDoc}
   *
   * <p>This method is invoked by the EventIpcManager when a new event is available for processing.
   * Each message is examined for its Universal Event Identifier and the appropriate action is
   * taking based on each UEI.
   */
  public void onEvent(Event event) {
    ThreadCategory log = ThreadCategory.getInstance(getClass());

    String eventUei = event.getUei();
    if (eventUei == null) {
      log.warn("Received an unexpected event with a null UEI");
      return;
    }

    if (log.isDebugEnabled()) {
      log.debug("Received event: " + eventUei);
    }

    if (eventUei.equals(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI)
        || eventUei.equals(EventConstants.INTERFACE_REPARENTED_EVENT_UEI)) {
      String action =
          eventUei.equals(EventConstants.INTERFACE_REPARENTED_EVENT_UEI) ? "reparent" : "add";
      if (Long.toString(event.getNodeid()) == null) {
        log.warn("Not " + action + "ing interface to known node list: " + "nodeId is null");
      } else if (event.getInterface() == null) {
        log.warn("Not " + action + "ing interface to known node list: " + "interface is null");
      } else {
        m_trapdIpMgr.setNodeId(event.getInterface(), event.getNodeid());
        if (log.isDebugEnabled()) {
          log.debug(
              "Successfully " + action + "ed " + event.getInterface() + " to known node list");
        }
      }
    } else if (eventUei.equals(EventConstants.INTERFACE_DELETED_EVENT_UEI)) {
      if (event.getInterface() != null) {
        m_trapdIpMgr.removeNodeId(event.getInterface());
        if (log.isDebugEnabled()) {
          log.debug("Removed " + event.getInterface() + " from known node list");
        }
      }
    } else {
      log.warn("Received an unexpected event with UEI of \"" + eventUei + "\"");
    }
  }
Exemplo n.º 5
0
  /**
   * acknowledgeNotice
   *
   * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
   * @param uei a {@link java.lang.String} object.
   * @param matchList an array of {@link java.lang.String} objects.
   * @return a {@link java.util.Collection} object.
   * @throws java.sql.SQLException if any.
   * @throws java.io.IOException if any.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   */
  public Collection<Integer> acknowledgeNotice(
      final Event event, final String uei, final String[] matchList)
      throws SQLException, IOException, MarshalException, ValidationException {
    Connection connection = null;
    List<Integer> notifIDs = new LinkedList<Integer>();
    final DBUtils d = new DBUtils(getClass());
    ThreadCategory log = this.log();

    try {
      // First get most recent event ID from notifications
      // that match the matchList, then get all notifications
      // with this event ID
      connection = getConnection();
      d.watch(connection);
      int eventID = 0;
      boolean wasAcked = false;
      StringBuffer sql = new StringBuffer("SELECT eventid FROM notifications WHERE eventuei=? ");
      for (int i = 0; i < matchList.length; i++) {
        sql.append("AND ").append(matchList[i]).append("=? ");
      }
      sql.append("ORDER BY eventid desc limit 1");
      PreparedStatement statement = connection.prepareStatement(sql.toString());
      d.watch(statement);
      statement.setString(1, uei);

      for (int i = 0; i < matchList.length; i++) {
        if (matchList[i].equals("nodeid")) {
          statement.setLong(i + 2, event.getNodeid());
        }

        if (matchList[i].equals("interfaceid")) {
          statement.setString(i + 2, event.getInterface());
        }

        if (matchList[i].equals("serviceid")) {
          statement.setInt(i + 2, getServiceId(event.getService()));
        }
      }

      ResultSet results = statement.executeQuery();
      d.watch(results);
      if (results != null && results.next()) {
        eventID = results.getInt(1);
        if (log.isDebugEnabled()) log.debug("EventID for notice(s) to be acked: " + eventID);

        sql =
            new StringBuffer(
                "SELECT notifyid, answeredby, respondtime FROM notifications WHERE eventID=?");

        statement = connection.prepareStatement(sql.toString());
        statement.setInt(1, eventID);

        results = statement.executeQuery();

        if (results != null) {
          while (results.next()) {
            int notifID = results.getInt(1);
            String ansBy = results.getString(2);
            Timestamp ts = results.getTimestamp(3);
            if (ansBy == null) {
              ansBy = "auto-acknowledged";
              ts = new Timestamp((new Date()).getTime());
            } else if (ansBy.indexOf("auto-acknowledged") > -1) {
              if (log.isDebugEnabled())
                log.debug("Notice has previously been auto-acknowledged. Skipping...");
              continue;
            } else {
              wasAcked = true;
              ansBy = ansBy + "/auto-acknowledged";
            }
            if (log.isDebugEnabled())
              log.debug(
                  "Matching DOWN notifyID = "
                      + notifID
                      + ", was acked by user = "******", ansBy = "
                      + ansBy);
            final PreparedStatement update =
                connection.prepareStatement(
                    getConfigManager().getConfiguration().getAcknowledgeUpdateSql());
            d.watch(update);

            update.setString(1, ansBy);
            update.setTimestamp(2, ts);
            update.setInt(3, notifID);

            update.executeUpdate();
            update.close();
            if (wasAcked) {
              notifIDs.add(-1 * notifID);
            } else {
              notifIDs.add(notifID);
            }
          }
        }
      } else {
        if (log.isDebugEnabled()) log.debug("No matching DOWN eventID found");
      }
    } finally {
      d.cleanUp();
    }
    return notifIDs;
  }
Exemplo n.º 6
0
  /**
   * Create an SNMP trap, based on the content of an event derived from a TL1 autonomous message
   * received by Tl1d, and forward the trap to the specified address and port. The type of trap
   * created depends on the value of the "trapVersion" parameter. The "community" parameter
   * determines the SNMP community string of the resulting trap, defaulting to "public".
   *
   * @param event The event upon which the trap content should be based
   * @param destAddr The address to which the trap should be sent
   * @param destPort The port to which the trap should be sent
   * @param trapVersion The SNMP version ("v1" or "v2c") of the trap
   * @param community The SNMP community string for the trap (defaults to "public")
   * @throws org.opennms.netmgt.scriptd.helper.SnmpTrapHelperException if any.
   * @throws java.net.UnknownHostException if any.
   * @exception Throws SnmpTrapHelperException if the event is not of the appropriate type.
   * @exception Throws UnknownHostException if agent-addr resolution fails for the case of an SNMPv1
   *     trap
   * @exception Throws SnmpTrapHelperException if the event is not of the appropriate type.
   * @exception Throws UnknownHostException if agent-addr resolution fails for the case of an SNMPv1
   *     trap
   */
  public void sendTL1AutonomousMsgTrap(
      Event event, String destAddr, int destPort, String trapVersion, String community)
      throws SnmpTrapHelperException, UnknownHostException {

    // Check first thing that the event is of the right type.
    if (!org.opennms.netmgt.EventConstants.TL1_AUTONOMOUS_MESSAGE_UEI.equals(event.getUei())) {
      throw new SnmpTrapHelperException(
          "The event must have a UEI of "
              + org.opennms.netmgt.EventConstants.TL1_AUTONOMOUS_MESSAGE_UEI);
    }

    // Create a TrapBuilder and bootstrap it according to trapVersion
    SnmpTrapBuilder trapBuilder = null;
    // What to do about timestamp? Hard-wiring to zero for now.
    long trapTimeStamp = 0;

    final String iface = event.getInterface();
    if ("v1".equalsIgnoreCase(trapVersion)) {
      trapBuilder =
          createV1Trap(
              ".1.3.6.1.4.1.5813.1", // OPENNMS-MIB::openNMS-traps
              iface,
              ENTERPRISE_SPECIFIC,
              2, // OPENNMS-MIB::openNMS-tl1AutonomousMessageTrap
              trapTimeStamp);
    } else if ("v2c".equalsIgnoreCase(trapVersion)) {
      trapBuilder =
          createV2Trap(
              ".1.3.6.1.4.1.5813.1.0.2", // OPENNMS-MIB::openNMS-tl1AutonomousMessageTrap
              Long.toString(trapTimeStamp));
    } else {
      throw new SnmpTrapHelperException("The trap SNMP version must be either v1 or v2c");
    }

    // Add all the MIB-specified varbinds
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.1.8.0", // OPENNMS-MIB::openNMS-event-nodeid
        EventConstants.TYPE_SNMP_OCTET_STRING,
        Long.toString(event.getNodeid()));
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.1.9.0", // OPENNMS-MIB::openNMS-event-time
        EventConstants.TYPE_SNMP_OCTET_STRING,
        event.getTime());
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.1.10.0", // OPENNMS-MIB::openNMS-event-host
        EventConstants.TYPE_SNMP_OCTET_STRING,
        event.getHost());
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.1.11.0", // OPENNMS-MIB::openNMS-event-interface
        EventConstants.TYPE_SNMP_OCTET_STRING,
        iface);
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.1.13.0", // OPENNMS-MIB::openNMS-event-service
        EventConstants.TYPE_SNMP_OCTET_STRING,
        event.getService());
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.1.18.0", // OPENNMS-MIB::openNMS-event-severity
        EventConstants.TYPE_SNMP_OCTET_STRING,
        event.getSeverity());
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.2.1.1.0", // OPENNMS-MIB::tl1amRawMessage
        EventConstants.TYPE_SNMP_OCTET_STRING,
        EventUtil.expandParms("%parm[raw-message]%", event));
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.2.1.2.0", // OPENNMS-MIB::tl1amAlarmCode
        EventConstants.TYPE_SNMP_OCTET_STRING,
        EventUtil.expandParms("%parm[alarm-code]%", event));
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.2.1.3.0", // OPENNMS-MIB::tl1amAutonomousTag
        EventConstants.TYPE_SNMP_OCTET_STRING,
        EventUtil.expandParms("%parm[atag]%", event));
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.2.1.4.0", // OPENNMS-MIB::tl1amVerb
        EventConstants.TYPE_SNMP_OCTET_STRING,
        EventUtil.expandParms("%parm[verb]%", event));
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.2.1.5.0", // OPENNMS-MIB::tl1amAutoBlock
        EventConstants.TYPE_SNMP_OCTET_STRING,
        EventUtil.expandParms("%parm[autoblock]%", event));
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.2.1.6.0", // OPENNMS-MIB::tl1amAID
        EventConstants.TYPE_SNMP_OCTET_STRING,
        EventUtil.expandParms("%parm[aid]%", event));
    addVarBinding(
        trapBuilder,
        ".1.3.6.1.4.1.5813.20.2.1.7.0", // OPENNMS-MIB::tl1amAdditionalParams
        EventConstants.TYPE_SNMP_OCTET_STRING,
        EventUtil.expandParms("%parm[additionalParams]%", event));

    // Finally, send the trap!
    this.sendTrap(destAddr, destPort, community, trapBuilder);
  }
Exemplo n.º 7
0
  /**
   * {@inheritDoc}
   *
   * <p>The method that inserts the event into the database
   */
  @Override
  public void process(final Header eventHeader, final Event event) throws EventProcessorException {
    if (!checkEventSanityAndDoWeProcess(event, "JdbcEventWriter")) {
      return;
    }

    LOG.debug(
        "JdbcEventWriter: processing {} nodeid: {} ipaddr: {} serviceid: {} time: {}",
        event.getUei(),
        event.getNodeid(),
        event.getInterface(),
        event.getService(),
        event.getTime());

    Connection connection;
    try {
      connection = getDataSource().getConnection();
    } catch (final SQLException e) {
      throw new EventProcessorException(e);
    }

    try {
      connection.setAutoCommit(false);

      try {
        insertEvent(eventHeader, event, connection);

        connection.commit();
      } catch (final SQLException e) {
        LOG.warn("Error inserting event into the datastore.", e);
        try {
          connection.rollback();
        } catch (final Throwable e2) {
          LOG.warn("Rollback of transaction failed.", e2);
        }

        throw e;
      } catch (final DataAccessException e) {
        LOG.warn("Error inserting event into the datastore.", e);
        try {
          connection.rollback();
        } catch (final Throwable e2) {
          LOG.warn("Rollback of transaction failed.", e2);
        }

        throw e;
      }
    } catch (final DataAccessException e) {
      throw new EventProcessorException(e);
    } catch (SQLException e) {
      throw new EventProcessorException(e);
    } finally {
      try {
        connection.close();
      } catch (final SQLException e) {
        LOG.warn("SQLException while closing database connection.", e);
      }
    }

    LOG.debug("EventWriter finished for : {}", event.getUei());
  }
Exemplo n.º 8
0
  /**
   * Insert values into the EVENTS table
   *
   * @exception java.sql.SQLException Thrown if there is an error adding the event to the database.
   * @exception java.lang.NullPointerException Thrown if a required resource cannot be found in the
   *     properties file.
   */
  private void insertEvent(final Header eventHeader, final Event event, final Connection connection)
      throws SQLException {
    // Execute the statement to get the next event id
    final int eventID = getNextId();

    LOG.debug("DBID: {}", eventID);

    synchronized (event) {
      event.setDbid(eventID);
    }
    final DBUtils d = new DBUtils(getClass());

    try {
      final PreparedStatement insStmt =
          connection.prepareStatement(EventdConstants.SQL_DB_INS_EVENT);
      d.watch(insStmt);

      // eventID
      insStmt.setInt(1, eventID);

      // eventUEI
      insStmt.setString(2, Constants.format(event.getUei(), EVENT_UEI_FIELD_SIZE));

      // nodeID
      final Long nodeid = event.getNodeid();
      set(insStmt, 3, event.hasNodeid() ? nodeid.intValue() : -1);

      // eventTime
      insStmt.setTimestamp(4, getEventTime(event));

      // Resolve the event host to a hostname using the ipInterface table
      String hostname = getEventHost(event);

      // eventHost
      set(insStmt, 5, Constants.format(hostname, EVENT_HOST_FIELD_SIZE));

      // ipAddr
      set(insStmt, 6, Constants.format(event.getInterface(), EVENT_INTERFACE_FIELD_SIZE));

      // eventDpName
      String dpName = "localhost";
      if (eventHeader != null && eventHeader.getDpName() != null) {
        dpName = Constants.format(eventHeader.getDpName(), EVENT_DPNAME_FIELD_SIZE);
      } else if (event.getDistPoller() != null) {
        dpName = Constants.format(event.getDistPoller(), EVENT_DPNAME_FIELD_SIZE);
      }
      insStmt.setString(7, dpName);

      // eventSnmpHost
      set(insStmt, 8, Constants.format(event.getSnmphost(), EVENT_SNMPHOST_FIELD_SIZE));

      // service identifier - convert the service name to a service id
      set(insStmt, 9, getEventServiceId(event));

      // eventSnmp
      if (event.getSnmp() != null) {
        insStmt.setString(10, SnmpInfo.format(event.getSnmp(), EVENT_SNMP_FIELD_SIZE));
      } else {
        insStmt.setNull(10, Types.VARCHAR);
      }

      // eventParms

      // Replace any null bytes with a space, otherwise postgres will complain about encoding in
      // UNICODE
      final String parametersString = Parameter.format(event);
      set(insStmt, 11, Constants.format(parametersString, 0));

      // eventCreateTime
      final Timestamp eventCreateTime = new Timestamp(System.currentTimeMillis());
      insStmt.setTimestamp(12, eventCreateTime);

      // eventDescr
      set(insStmt, 13, Constants.format(event.getDescr(), 0));

      // eventLoggroup
      set(
          insStmt,
          14,
          (event.getLoggroupCount() > 0)
              ? Constants.format(event.getLoggroup(), EVENT_LOGGRP_FIELD_SIZE)
              : null);

      // eventLogMsg
      // eventLog
      // eventDisplay
      if (event.getLogmsg() != null) {
        // set log message
        set(insStmt, 15, Constants.format(event.getLogmsg().getContent(), 0));
        String logdest = event.getLogmsg().getDest();
        if (logdest.equals("logndisplay")) {
          // if 'logndisplay' set both log and display column to yes
          set(insStmt, 16, MSG_YES);
          set(insStmt, 17, MSG_YES);
        } else if (logdest.equals("logonly")) {
          // if 'logonly' set log column to true
          set(insStmt, 16, MSG_YES);
          set(insStmt, 17, MSG_NO);
        } else if (logdest.equals("displayonly")) {
          // if 'displayonly' set display column to true
          set(insStmt, 16, MSG_NO);
          set(insStmt, 17, MSG_YES);
        } else if (logdest.equals("suppress")) {
          // if 'suppress' set both log and display to false
          set(insStmt, 16, MSG_NO);
          set(insStmt, 17, MSG_NO);
        }
      } else {
        insStmt.setNull(15, Types.VARCHAR);

        /*
         * If this is an event that had no match in the event conf
         * mark it as to be logged and displayed so that there
         * are no events that slip through the system
         * without the user knowing about them
         */
        set(insStmt, 17, MSG_YES);
      }

      // eventSeverity
      set(insStmt, 18, OnmsSeverity.get(event.getSeverity()).getId());

      // eventPathOutage
      set(
          insStmt,
          19,
          (event.getPathoutage() != null)
              ? Constants.format(event.getPathoutage(), EVENT_PATHOUTAGE_FIELD_SIZE)
              : null);

      // eventCorrelation
      set(
          insStmt,
          20,
          (event.getCorrelation() != null)
              ? org.opennms.netmgt.dao.util.Correlation.format(
                  event.getCorrelation(), EVENT_CORRELATION_FIELD_SIZE)
              : null);

      // eventSuppressedCount
      insStmt.setNull(21, Types.INTEGER);

      // eventOperInstruct
      set(insStmt, 22, Constants.format(event.getOperinstruct(), EVENT_OPERINSTRUCT_FIELD_SIZE));

      // eventAutoAction
      set(
          insStmt,
          23,
          (event.getAutoactionCount() > 0)
              ? AutoAction.format(event.getAutoaction(), EVENT_AUTOACTION_FIELD_SIZE)
              : null);

      // eventOperAction / eventOperActionMenuText
      if (event.getOperactionCount() > 0) {
        final List<Operaction> a = new ArrayList<Operaction>();
        final List<String> b = new ArrayList<String>();

        for (final Operaction eoa : event.getOperactionCollection()) {
          a.add(eoa);
          b.add(eoa.getMenutext());
        }

        set(insStmt, 24, OperatorAction.format(a, EVENT_OPERACTION_FIELD_SIZE));
        set(insStmt, 25, Constants.format(b, EVENT_OPERACTION_MENU_FIELD_SIZE));
      } else {
        insStmt.setNull(24, Types.VARCHAR);
        insStmt.setNull(25, Types.VARCHAR);
      }

      // eventNotification, this column no longer needed
      insStmt.setNull(26, Types.VARCHAR);

      // eventTroubleTicket / eventTroubleTicket state
      if (event.getTticket() != null) {
        set(
            insStmt,
            27,
            Constants.format(event.getTticket().getContent(), EVENT_TTICKET_FIELD_SIZE));
        set(insStmt, 28, event.getTticket().getState().equals("on") ? 1 : 0);
      } else {
        insStmt.setNull(27, Types.VARCHAR);
        insStmt.setNull(28, Types.INTEGER);
      }

      // eventForward
      set(
          insStmt,
          29,
          (event.getForwardCount() > 0)
              ? org.opennms.netmgt.dao.util.Forward.format(
                  event.getForward(), EVENT_FORWARD_FIELD_SIZE)
              : null);

      // event mouseOverText
      set(insStmt, 30, Constants.format(event.getMouseovertext(), EVENT_MOUSEOVERTEXT_FIELD_SIZE));

      // eventAckUser
      if (event.getAutoacknowledge() != null
          && event.getAutoacknowledge().getState().equals("on")) {
        set(
            insStmt,
            31,
            Constants.format(event.getAutoacknowledge().getContent(), EVENT_ACKUSER_FIELD_SIZE));

        // eventAckTime - if autoacknowledge is present,
        // set time to event create time
        set(insStmt, 32, eventCreateTime);
      } else {
        insStmt.setNull(31, Types.INTEGER);
        insStmt.setNull(32, Types.TIMESTAMP);
      }

      // eventSource
      set(insStmt, 33, Constants.format(event.getSource(), EVENT_SOURCE_FIELD_SIZE));

      // ifindex
      if (event.hasIfIndex()) {
        set(insStmt, 34, event.getIfIndex());
      } else {
        insStmt.setNull(34, Types.INTEGER);
      }

      // execute
      insStmt.executeUpdate();
    } finally {
      d.cleanUp();
    }

    LOG.debug("SUCCESSFULLY added {} related  data into the EVENTS table.", event.getUei());
  }