Пример #1
0
  @Override
  public void process(final Header eventHeader, final Event event) throws EventProcessorException {
    LOG.debug("Writing event: {}", event);
    final OnmsEvent oe = new OnmsEvent();
    oe.setEventAutoAction(
        (event.getAutoactionCount() > 0)
            ? AutoAction.format(event.getAutoaction(), EVENT_AUTOACTION_FIELD_SIZE)
            : null);
    oe.setEventCorrelation(
        (event.getCorrelation() != null)
            ? org.opennms.netmgt.dao.util.Correlation.format(
                event.getCorrelation(), EVENT_CORRELATION_FIELD_SIZE)
            : null);
    oe.setEventCreateTime(event.getCreationTime());
    oe.setId(event.getDbid());
    oe.setEventDescr(event.getDescr());
    try {
      oe.setDistPoller(m_distPollerDao.get(event.getDistPoller()));
    } catch (final DataAccessException e) {
      throw new EventProcessorException(e);
    }
    oe.setEventHost(event.getHost());
    oe.setEventForward(
        (event.getForwardCount() > 0)
            ? org.opennms.netmgt.dao.util.Forward.format(
                event.getForward(), EVENT_FORWARD_FIELD_SIZE)
            : null);
    oe.setIfIndex(event.getIfIndex());
    oe.setIpAddr(event.getInterfaceAddress());

    if (event.getLogmsg() != null) {
      // set log message
      oe.setEventLogMsg(EventDatabaseConstants.format(event.getLogmsg().getContent(), 0));
      final String logdest = event.getLogmsg().getDest();
      if (logdest.equals("logndisplay")) {
        // if 'logndisplay' set both log and display column to yes
        oe.setEventLog("Y");
        oe.setEventDisplay("Y");
      } else if (logdest.equals("logonly")) {
        // if 'logonly' set log column to true
        oe.setEventLog("Y");
        oe.setEventDisplay("N");
      } else if (logdest.equals("displayonly")) {
        // if 'displayonly' set display column to true
        oe.setEventLog("N");
        oe.setEventDisplay("Y");
      } else if (logdest.equals("suppress")) {
        // if 'suppress' set both log and display to false
        oe.setEventLog("N");
        oe.setEventDisplay("N");
      }
    }

    oe.setEventMouseOverText(event.getMouseovertext());
    try {
      oe.setNode(m_nodeDao.get(event.getNodeid().intValue()));
    } catch (final DataAccessException e) {
      throw new EventProcessorException(e);
    }

    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());
      }

      oe.setEventOperAction(OperatorAction.format(a, EVENT_OPERACTION_FIELD_SIZE));
      oe.setEventOperActionMenuText(
          EventDatabaseConstants.format(b, EVENT_OPERACTION_MENU_FIELD_SIZE));
    }
    oe.setEventOperInstruct(event.getOperinstruct());
    oe.setEventParms(EventParameterUtils.format(event));
    oe.setEventPathOutage(event.getPathoutage());
    try {
      oe.setServiceType(m_serviceTypeDao.findByName(event.getService()));
    } catch (final DataAccessException e) {
      throw new EventProcessorException(e);
    }
    oe.setSeverityLabel(event.getSeverity());
    oe.setEventSnmp(SnmpInfo.format(event.getSnmp(), EVENT_SNMP_FIELD_SIZE));
    oe.setEventSnmpHost(
        EventDatabaseConstants.format(event.getSnmphost(), EVENT_SNMPHOST_FIELD_SIZE));
    oe.setEventSource(event.getSource());
    oe.setEventTime(event.getTime());

    if (event.getTticket() != null) {
      oe.setEventTTicket(
          EventDatabaseConstants.format(event.getTticket().getContent(), EVENT_TTICKET_FIELD_SIZE));
      oe.setEventTTicketState(event.getTticket().getState().equals("on") ? 1 : 0);
    }
    oe.setEventUei(event.getUei());

    m_eventDao.saveOrUpdate(oe);
  }
Пример #2
0
  /**
   * getNotifForEvent
   *
   * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
   * @return an array of {@link org.opennms.netmgt.config.notifications.Notification} objects.
   * @throws java.io.IOException if any.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   */
  public Notification[] getNotifForEvent(final Event event)
      throws IOException, MarshalException, ValidationException {
    update();
    List<Notification> notifList = new ArrayList<Notification>();
    boolean matchAll = getConfigManager().getNotificationMatch();
    ThreadCategory log = this.log();

    // This if statement will check to see if notification should be suppressed for this event.

    if (event == null) {
      log.warn("unable to get notification for null event!");
      return null;
    } else if (event.getLogmsg() != null && !(event.getLogmsg().getNotify())) {
      if (log.isDebugEnabled())
        log.debug("Event " + event.getUei() + " is configured to suppress notifications.");
      return null;
    }

    for (Notification curNotif : m_notifications.getNotificationCollection()) {
      if (log.isDebugEnabled())
        log.debug("Checking " + event.getUei() + " against " + curNotif.getUei());

      if (event.getUei().equals(curNotif.getUei()) || "MATCH-ANY-UEI".equals(curNotif.getUei())) {
        // Match!
      } else if (curNotif.getUei().charAt(0) == '~') {
        if (event.getUei().matches(curNotif.getUei().substring(1))) {
          // Match!
        } else {
          if (log.isDebugEnabled())
            log.debug(
                "Notification regex "
                    + curNotif.getUei()
                    + " failed to match event UEI: "
                    + event.getUei());
          continue;
        }
      } else {
        if (log.isDebugEnabled())
          log.debug("Event UEI " + event.getUei() + " did not match " + curNotif.getUei());
        continue;
      }

      /** Check if event severity matches pattern in notification */
      if (log.isDebugEnabled())
        log.debug(
            "Checking event severity: "
                + event.getSeverity()
                + " against notification severity: "
                + curNotif.getEventSeverity());
      // parameter is optional, return true if not set
      if (curNotif.getEventSeverity() == null) {
        // Skip matching on severity
      } else if (event
          .getSeverity()
          .toLowerCase()
          .matches(curNotif.getEventSeverity().toLowerCase())) {
        // Severities match
      } else {
        if (log.isDebugEnabled())
          log.debug(
              "Event severity: "
                  + event.getSeverity()
                  + " did not match notification severity: "
                  + curNotif.getEventSeverity());
        continue;
      }

      // The notice has to be "on"
      // The notice has to match a severity if configured - currHasSeverity should be true if there
      // is no severity rule
      // The notice has to match the UEI of the event or MATCH-ANY-UEI
      // If all those things are true:
      // Then the service has to match if configured, the interface if configured, and the node if
      // configured.

      if (curNotif.getStatus().equals("on")) {
        if (nodeInterfaceServiceValid(curNotif, event)) {
          boolean parmsmatched = getConfigManager().matchNotificationParameters(event, curNotif);

          if (!parmsmatched) {
            if (log.isDebugEnabled())
              log.debug(
                  "Event "
                      + event.getUei()
                      + " did not match parameters for notice "
                      + curNotif.getName());
            continue;
          }
          // Add this notification to the return value
          notifList.add(curNotif);

          if (log.isDebugEnabled())
            log.debug("Event " + event.getUei() + " matched notice " + curNotif.getName());

          if (!matchAll) break;
        } else {
          if (log.isDebugEnabled())
            log.debug("Node/interface/service combination in the event was invalid");
        }
      } else {
        if (log.isDebugEnabled()) log.debug("Current notification is turned off.");
      }
    }

    if (!notifList.isEmpty()) {
      return notifList.toArray(new Notification[0]);
    } else {
      return null;
    }
  }
Пример #3
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());
  }
Пример #4
0
  /**
   * {@inheritDoc}
   *
   * <p>The OpenNMS event listener runs this routine when a new event is detected. This can be run
   * on any event but only needs to run on uei.opennms.org/vacuumd/alarmListChanged
   */
  @Override
  public void onEvent(Event event) {
    LOG.debug(
        "Qosd.onEvent: OpenNMS Event Detected by QosD. uei '{}' Dbid(): {}  event.getTime(): {}",
        event.getUei(),
        event.getDbid(),
        event.getTime());

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

    if (EventConstants.NODE_ADDED_EVENT_UEI.equals(s)
        || EventConstants.NODE_LABEL_CHANGED_EVENT_UEI.equals(s)
        || EventConstants.NODE_DELETED_EVENT_UEI.equals(s)
        || EventConstants.ASSET_INFO_CHANGED_EVENT_UEI.equals(s)) {
      try {
        LOG.debug("QosD.onEvent Event causing update to node list");
        openNMSEventHandlerThread.updateNodeCache();
        return;
      } catch (Exception ex) {
        LOG.error(
            "Qosd.onEvent. Problem calling openNMSEventHandlerThread.updateNodeCache(). Error:",
            ex);
        return;
      }
    }

    if (event.getUei().equals("uei.opennms.org/vacuumd/alarmListChanged")) {
      LOG.debug(
          "QosD.onEvent received 'uei.opennms.org/vacuumd/alarmListChanged' event; Updating alarm list");
    } else {
      // used code from AlarmWriter.java Check value of <logmsg> attribute 'dest', if set to
      // "donotpersist" then simply return, the uei is not to be persisted to the database
      // The uei.opennms.org/vacuumd/alarmListChanged event must be set to be reised
      // as auto-action from vacumd-configuration.xml and is called
      // when vacumd updates the current ( alarm not acknowledgd and cleared ) alarm list
      // note alarmListChanged event may be marked as 'donotpersist' so checked first
      try {
        // this section prints out events received which are not
        // uei.opennms.org/vacuumd/alarmListChanged
        // return if a donotpersist event
        if (event.getLogmsg().getDest().equals("donotpersist")) {
          LOG.debug(
              "QosD.onEvent Ignoring event marked as 'doNotPersist'. Event Uei:{}", event.getUei());
          return;
        }
        // AlarmData should not be null if QoSD-configuration.xml is set up only to receive raise
        // and not clearing alarms
        if (event.getAlarmData().getAlarmType() == 2) {
          LOG.debug(
              "Qosd.onEvent: uei '{}' Dbid(): {} alarm type = 2 (clearing alarm) so ignoring.",
              event.getUei(),
              event.getDbid());
          return;
        }
      } catch (NullPointerException e) {
        LOG.error(
            "Qosd.onEvent: uei '{}' Dbid(): {}' problem dealing with event. Check QoSD-configuration.xml.",
            event.getUei(),
            event.getDbid());
        return;
      }
    }

    // This forces the ossDao to update it's list on this event and call back to sendAlarms() to
    // send the
    // updated alarm list.
    try {
      LOG.debug("QosD.onEvent calling openNMSEventHandlerThread.sendAlarmList() to update list.");
      // ossDao.updateAlarmCacheAndSendAlarms();
      openNMSEventHandlerThread.sendAlarmList();
    } catch (Exception ex) {
      LOG.error(
          "Qosd.onEvent. Problem calling openNMSEventHandlerThread.sendAlarmList(). Error:", ex);
    }
  }
 /**
  * setLogMessage
  *
  * @param content a {@link java.lang.String} object.
  * @return a {@link org.opennms.netmgt.model.events.EventBuilder} object.
  */
 public EventBuilder setLogMessage(final String content) {
   ensureLogmsg();
   m_event.getLogmsg().setContent(content);
   return this;
 }
 /**
  * setLogDest
  *
  * @param dest a {@link java.lang.String} object.
  * @return a {@link org.opennms.netmgt.model.events.EventBuilder} object.
  */
 public EventBuilder setLogDest(final String dest) {
   ensureLogmsg();
   m_event.getLogmsg().setDest(dest);
   return this;
 }
 private void ensureLogmsg() {
   if (m_event.getLogmsg() == null) {
     m_event.setLogmsg(new Logmsg());
   }
 }