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