Search in sources :

Example 1 with EventProcessorException

use of org.opennms.netmgt.events.api.EventProcessorException 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<>();
        final List<String> b = new ArrayList<>();
        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.setEventParametersFromEvent(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 EventProcessorException

use of org.opennms.netmgt.events.api.EventProcessorException in project opennms by OpenNMS.

the class HibernateEventWriter method process.

@Override
public void process(Log eventLog) throws EventProcessorException {
    if (eventLog != null && eventLog.getEvents() != null) {
        final List<Event> eventsInLog = eventLog.getEvents().getEventCollection();
        // This shouldn't happen, but just to be safe...
        if (eventsInLog == null) {
            return;
        }
        // Find the events in the log that need to be persisted
        final List<Event> eventsToPersist = eventsInLog.stream().filter(e -> checkEventSanityAndDoWeProcess(e, "HibernateEventWriter")).collect(Collectors.toList());
        // If there are no events to persist, avoid creating a database transaction
        if (eventsToPersist.size() < 1) {
            return;
        }
        // Time the transaction and insertions
        try (Context context = writeTimer.time()) {
            final AtomicReference<EventProcessorException> exception = new AtomicReference<>();
            m_transactionManager.execute(new TransactionCallbackWithoutResult() {

                @Override
                protected void doInTransactionWithoutResult(TransactionStatus status) {
                    for (Event eachEvent : eventsToPersist) {
                        try {
                            process(eventLog.getHeader(), eachEvent);
                        } catch (EventProcessorException e) {
                            exception.set(e);
                            return;
                        }
                    }
                }
            });
            if (exception.get() != null) {
                throw exception.get();
            }
        }
    }
}
Also used : MonitoringSystemDao(org.opennms.netmgt.dao.api.MonitoringSystemDao) Date(java.util.Date) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AtomicReference(java.util.concurrent.atomic.AtomicReference) EventDatabaseConstants(org.opennms.netmgt.events.api.EventDatabaseConstants) ArrayList(java.util.ArrayList) DeadlockLoserDataAccessException(org.springframework.dao.DeadlockLoserDataAccessException) DistPollerDao(org.opennms.netmgt.dao.api.DistPollerDao) Event(org.opennms.netmgt.xml.event.Event) ServiceTypeDao(org.opennms.netmgt.dao.api.ServiceTypeDao) Context(com.codahale.metrics.Timer.Context) Log(org.opennms.netmgt.xml.event.Log) Operaction(org.opennms.netmgt.xml.event.Operaction) NodeDao(org.opennms.netmgt.dao.api.NodeDao) Logger(org.slf4j.Logger) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) MetricRegistry(com.codahale.metrics.MetricRegistry) OperatorAction(org.opennms.netmgt.dao.util.OperatorAction) EventDao(org.opennms.netmgt.dao.api.EventDao) Collectors(java.util.stream.Collectors) EventProcessorException(org.opennms.netmgt.events.api.EventProcessorException) Objects(java.util.Objects) List(java.util.List) Correlation(org.opennms.netmgt.dao.util.Correlation) AutoAction(org.opennms.netmgt.dao.util.AutoAction) Forward(org.opennms.netmgt.dao.util.Forward) EventUtil(org.opennms.netmgt.eventd.EventUtil) TransactionOperations(org.springframework.transaction.support.TransactionOperations) Header(org.opennms.netmgt.xml.event.Header) TransactionStatus(org.springframework.transaction.TransactionStatus) Timer(com.codahale.metrics.Timer) SnmpInfo(org.opennms.netmgt.dao.util.SnmpInfo) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) Assert(org.springframework.util.Assert) Context(com.codahale.metrics.Timer.Context) EventProcessorException(org.opennms.netmgt.events.api.EventProcessorException) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Event(org.opennms.netmgt.xml.event.Event) TransactionStatus(org.springframework.transaction.TransactionStatus) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 3 with EventProcessorException

use of org.opennms.netmgt.events.api.EventProcessorException in project opennms by OpenNMS.

the class HibernateEventWriter method process.

/**
 * {@inheritDoc}
 *
 * The method that inserts the event into the database
 */
private void process(final Header eventHeader, final Event event) throws EventProcessorException {
    LOG.debug("HibernateEventWriter: processing {}, nodeid: {}, ipaddr: {}, serviceid: {}, time: {}", event.getUei(), event.getNodeid(), event.getInterface(), event.getService(), event.getTime());
    try {
        final OnmsEvent ovent = createOnmsEvent(eventHeader, event);
        eventDao.save(ovent);
        // Update the event with the database ID of the event stored in the database
        event.setDbid(ovent.getId());
    } catch (DeadlockLoserDataAccessException e) {
        throw new EventProcessorException("Encountered deadlock when inserting event: " + event.toString(), e);
    } catch (Throwable e) {
        throw new EventProcessorException("Unexpected exception while storing event: " + event.toString(), e);
    }
}
Also used : EventProcessorException(org.opennms.netmgt.events.api.EventProcessorException) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) DeadlockLoserDataAccessException(org.springframework.dao.DeadlockLoserDataAccessException)

Aggregations

EventProcessorException (org.opennms.netmgt.events.api.EventProcessorException)3 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)3 ArrayList (java.util.ArrayList)2 Operaction (org.opennms.netmgt.xml.event.Operaction)2 DeadlockLoserDataAccessException (org.springframework.dao.DeadlockLoserDataAccessException)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Timer (com.codahale.metrics.Timer)1 Context (com.codahale.metrics.Timer.Context)1 Date (java.util.Date)1 List (java.util.List)1 Objects (java.util.Objects)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Collectors (java.util.stream.Collectors)1 DistPollerDao (org.opennms.netmgt.dao.api.DistPollerDao)1 EventDao (org.opennms.netmgt.dao.api.EventDao)1 MonitoringSystemDao (org.opennms.netmgt.dao.api.MonitoringSystemDao)1 NodeDao (org.opennms.netmgt.dao.api.NodeDao)1 ServiceTypeDao (org.opennms.netmgt.dao.api.ServiceTypeDao)1 AutoAction (org.opennms.netmgt.dao.util.AutoAction)1 Correlation (org.opennms.netmgt.dao.util.Correlation)1