Search in sources :

Example 1 with Operaction

use of org.opennms.netmgt.xml.event.Operaction in project opennms by OpenNMS.

the class MockEventWriter method process.

private void process(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);
}
Also used : EventProcessorException(org.opennms.netmgt.events.api.EventProcessorException) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Operaction(org.opennms.netmgt.xml.event.Operaction) ArrayList(java.util.ArrayList) DataAccessException(org.springframework.dao.DataAccessException)

Example 2 with Operaction

use of org.opennms.netmgt.xml.event.Operaction in project opennms by OpenNMS.

the class OperatorAction method format.

/**
     * Format the list of operator action entries of the event
     *
     * @param opacts
     *            the list
     * @param sz
     *            the size to which the formatted string is to be limited
     *            to(usually the size of the column in the database)
     * @return the formatted string
     */
public static String format(List<Operaction> opacts, int sz) {
    StringBuffer buf = new StringBuffer();
    boolean first = true;
    for (Operaction opact : opacts) {
        if (!first) {
            buf.append(EventDatabaseConstants.MULTIPLE_VAL_DELIM);
        } else {
            first = false;
        }
        buf.append(EventDatabaseConstants.escape(format(opact), EventDatabaseConstants.MULTIPLE_VAL_DELIM));
    }
    if (buf.length() >= sz) {
        buf.setLength(sz - 4);
        buf.append(EventDatabaseConstants.VALUE_TRUNCATE_INDICATOR);
    }
    return buf.toString();
}
Also used : Operaction(org.opennms.netmgt.xml.event.Operaction)

Example 3 with Operaction

use of org.opennms.netmgt.xml.event.Operaction in project opennms by OpenNMS.

the class HibernateEventWriter method createOnmsEvent.

/**
     * Creates OnmsEvent to be inserted afterwards.
     * 
     * @exception java.lang.NullPointerException
     *                Thrown if a required resource cannot be found in the
     *                properties file.
     */
private OnmsEvent createOnmsEvent(final Header eventHeader, final Event event) {
    OnmsEvent ovent = new OnmsEvent();
    // eventID
    //ovent.setId(event.getDbid());
    // eventUEI
    ovent.setEventUei(EventDatabaseConstants.format(event.getUei(), EVENT_UEI_FIELD_SIZE));
    // nodeID
    if (event.hasNodeid()) {
        ovent.setNode(nodeDao.get(event.getNodeid().intValue()));
    }
    // eventTime
    ovent.setEventTime(event.getTime());
    // eventHost
    // Resolve the event host to a hostname using the ipInterface table
    ovent.setEventHost(EventDatabaseConstants.format(eventUtil.getEventHost(event), EVENT_HOST_FIELD_SIZE));
    // eventSource
    ovent.setEventSource(EventDatabaseConstants.format(event.getSource(), EVENT_SOURCE_FIELD_SIZE));
    // ipAddr
    ovent.setIpAddr(event.getInterfaceAddress());
    // ifindex
    if (event.hasIfIndex()) {
        ovent.setIfIndex(event.getIfIndex());
    } else {
        ovent.setIfIndex(null);
    }
    // If available, use the header's distPoller
    if (eventHeader != null && eventHeader.getDpName() != null && !"".equals(eventHeader.getDpName().trim())) {
        // TODO: Should we also try a look up the value in the MinionDao and LocationMonitorDao here?
        ovent.setDistPoller(distPollerDao.get(eventHeader.getDpName()));
    }
    // Otherwise, use the event's distPoller
    if (ovent.getDistPoller() == null && event.getDistPoller() != null && !"".equals(event.getDistPoller().trim())) {
        ovent.setDistPoller(monitoringSystemDao.get(event.getDistPoller()));
    }
    // And if both are unavailable, use the local system as the event's source system
    if (ovent.getDistPoller() == null) {
        ovent.setDistPoller(distPollerDao.whoami());
    }
    // eventSnmpHost
    ovent.setEventSnmpHost(EventDatabaseConstants.format(event.getSnmphost(), EVENT_SNMPHOST_FIELD_SIZE));
    // service
    ovent.setServiceType(serviceTypeDao.findByName(event.getService()));
    // eventSnmp
    ovent.setEventSnmp(event.getSnmp() == null ? null : SnmpInfo.format(event.getSnmp(), EVENT_SNMP_FIELD_SIZE));
    // eventParms
    // Replace any null bytes with a space, otherwise postgres will complain about encoding in UNICODE
    final String parametersString = EventParameterUtils.format(event);
    ovent.setEventParms(EventDatabaseConstants.format(parametersString, 0));
    // eventCreateTime
    // TODO: We are overriding the 'eventcreatetime' field of the event with a new Date
    // representing the storage time of the event. 'eventcreatetime' should really be
    // renamed to something like 'eventpersisttime' since that is closer to its meaning.
    ovent.setEventCreateTime(new Date());
    // eventDescr
    ovent.setEventDescr(EventDatabaseConstants.format(event.getDescr(), 0));
    // eventLoggroup
    ovent.setEventLogGroup(event.getLoggroupCount() > 0 ? EventDatabaseConstants.format(event.getLoggroup(), EVENT_LOGGRP_FIELD_SIZE) : null);
    // eventDisplay
    if (event.getLogmsg() != null) {
        // set log message
        ovent.setEventLogMsg(EventDatabaseConstants.format(event.getLogmsg().getContent(), 0));
        String logdest = event.getLogmsg().getDest();
        if (LOG_MSG_DEST_LOG_AND_DISPLAY.equals(logdest)) {
            // if 'logndisplay' set both log and display column to yes
            ovent.setEventLog(String.valueOf(MSG_YES));
            ovent.setEventDisplay(String.valueOf(MSG_YES));
        } else if (LOG_MSG_DEST_LOG_ONLY.equals(logdest)) {
            // if 'logonly' set log column to true
            ovent.setEventLog(String.valueOf(MSG_YES));
            ovent.setEventDisplay(String.valueOf(MSG_NO));
        } else if (LOG_MSG_DEST_DISPLAY_ONLY.equals(logdest)) {
            // if 'displayonly' set display column to true
            ovent.setEventLog(String.valueOf(MSG_NO));
            ovent.setEventDisplay(String.valueOf(MSG_YES));
        } else if (LOG_MSG_DEST_SUPRRESS.equals(logdest)) {
            // if 'suppress' set both log and display to false
            ovent.setEventLog(String.valueOf(MSG_NO));
            ovent.setEventDisplay(String.valueOf(MSG_NO));
        }
    } else {
        ovent.setEventLogMsg(null);
        ovent.setEventLog(String.valueOf(MSG_YES));
        ovent.setEventDisplay(String.valueOf(MSG_YES));
    }
    // eventSeverity
    ovent.setEventSeverity(OnmsSeverity.get(event.getSeverity()).getId());
    // eventPathOutage
    ovent.setEventPathOutage(event.getPathoutage() != null ? EventDatabaseConstants.format(event.getPathoutage(), EVENT_PATHOUTAGE_FIELD_SIZE) : null);
    // eventCorrelation
    ovent.setEventCorrelation(event.getCorrelation() != null ? Correlation.format(event.getCorrelation(), EVENT_CORRELATION_FIELD_SIZE) : null);
    // eventSuppressedCount
    ovent.setEventSuppressedCount(null);
    // eventOperInstruct
    ovent.setEventOperInstruct(EventDatabaseConstants.format(event.getOperinstruct(), 0));
    // eventAutoAction
    ovent.setEventAutoAction(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());
        }
        ovent.setEventOperAction(OperatorAction.format(a, EVENT_OPERACTION_FIELD_SIZE));
        ovent.setEventOperActionMenuText(EventDatabaseConstants.format(b, EVENT_OPERACTION_FIELD_SIZE));
    } else {
        ovent.setEventOperAction(null);
        ovent.setEventOperActionMenuText(null);
    }
    // eventNotification, this column no longer needed
    ovent.setEventNotification(null);
    // eventTroubleTicket / eventTroubleTicket state
    if (event.getTticket() != null) {
        ovent.setEventTTicket(EventDatabaseConstants.format(event.getTticket().getContent(), EVENT_TTICKET_FIELD_SIZE));
        ovent.setEventTTicketState("on".equals(event.getTticket().getState()) ? 1 : 0);
    } else {
        ovent.setEventTTicket(null);
        ovent.setEventTTicketState(null);
    }
    // eventForward
    ovent.setEventForward(event.getForwardCount() > 0 ? Forward.format(event.getForward(), EVENT_FORWARD_FIELD_SIZE) : null);
    // eventmouseOverText
    ovent.setEventMouseOverText(EventDatabaseConstants.format(event.getMouseovertext(), EVENT_MOUSEOVERTEXT_FIELD_SIZE));
    // eventAckUser
    if (event.getAutoacknowledge() != null && "on".equals(event.getAutoacknowledge().getState())) {
        ovent.setEventAckUser(EventDatabaseConstants.format(event.getAutoacknowledge().getContent(), EVENT_ACKUSER_FIELD_SIZE));
        // eventAckTime - if autoacknowledge is present,
        // set time to event create time
        ovent.setEventAckTime(ovent.getEventCreateTime());
    } else {
        ovent.setEventAckUser(null);
        ovent.setEventAckTime(null);
    }
    return ovent;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Operaction(org.opennms.netmgt.xml.event.Operaction) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 4 with Operaction

use of org.opennms.netmgt.xml.event.Operaction in project opennms by OpenNMS.

the class EventExpander method expandParms.

/**
     * Expand parms in the event operaction(s)
     */
private void expandParms(Operaction[] operactions, Event event) {
    boolean expanded = false;
    for (Operaction action : operactions) {
        String strRet = m_eventUtil.expandParms(action.getContent(), event);
        if (strRet != null) {
            action.setContent(strRet);
            expanded = true;
        }
    }
    if (expanded) {
        event.setOperaction(operactions);
    }
}
Also used : Operaction(org.opennms.netmgt.xml.event.Operaction)

Aggregations

Operaction (org.opennms.netmgt.xml.event.Operaction)4 ArrayList (java.util.ArrayList)2 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)2 Date (java.util.Date)1 EventProcessorException (org.opennms.netmgt.events.api.EventProcessorException)1 DataAccessException (org.springframework.dao.DataAccessException)1