use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EifParser method translateEifToOpenNMS.
public static List<Event> translateEifToOpenNMS(NodeDao nodeDao, StringBuilder eifBuff) {
// Create a list of events to return to the packet processor
List<Event> translatedEvents = new ArrayList<>();
// Loop over the received EIF package until we run out of events
while (eifBuff.length() > 0 && eifBuff.indexOf(";END") > 1) {
// Extract a single event from the package
int eventStart = eifBuff.indexOf("<START>>");
int eventEnd = eifBuff.indexOf(";END");
String eifEvent = eifBuff.substring(eventStart + eifStartOffset, eventEnd);
eifBuff.delete(0, eventEnd + 4);
// Parse the EIF slots into OpenNMS parms, and try to look up the source's nodeId
String eifClass = eifEvent.split(";")[0];
String eifSlots = eifEvent.substring(eifClass.length() + 1, eifEvent.length()).replaceAll(System.getProperty("line.separator"), "");
Map<String, String> eifSlotMap = parseEifSlots(eifSlots);
List<Parm> parmList = new ArrayList<>();
eifSlotMap.entrySet().forEach(p -> parmList.add(new Parm(p.getKey(), p.getValue())));
long nodeId = connectEifEventToNode(nodeDao, eifSlotMap);
// Add the translated event to the list
translatedEvents.add(new EventBuilder("uei.opennms.org/vendor/IBM/EIF/" + eifClass, "eif").setNodeid(nodeId).setSeverity(EifSeverity.valueOf(eifSlotMap.get("severity")).toOnmsSeverity().getLabel()).setParms(parmList).getEvent());
}
if (translatedEvents.isEmpty()) {
LOG.error("Received a zero-length list");
return null;
}
return translatedEvents;
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class Discovery method reloadAndReStart.
private void reloadAndReStart() {
EventBuilder ebldr = null;
try {
m_discoveryFactory.reload();
ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, getName());
ebldr.addParam(EventConstants.PARM_DAEMON_NAME, DAEMON_NAME);
this.stop();
this.start();
} catch (IOException e) {
LOG.error("Unable to initialize the discovery configuration factory", e);
ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, getName());
ebldr.addParam(EventConstants.PARM_DAEMON_NAME, DAEMON_NAME);
ebldr.addParam(EventConstants.PARM_REASON, e.getLocalizedMessage().substring(0, 128));
}
m_eventForwarder.sendNow(ebldr.getEvent());
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class BroadcastEventProcessorTest method testReload.
public void testReload() {
MockEventIpcManager eventIpcManager = new MockEventIpcManager();
BroadcastEventProcessor processor = new BroadcastEventProcessor(eventIpcManager, m_eventConfDao);
EventBuilder eventBuilder = new EventBuilder(EventConstants.EVENTSCONFIG_CHANGED_EVENT_UEI, "dunno");
// Expect a call to reload the EventConfDao
m_eventConfDao.reload();
m_mocks.replayAll();
processor.onEvent(eventBuilder.getEvent());
m_mocks.verifyAll();
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventIpcManagerDefaultImplTest method testAsyncVsSyncSendNow.
public void testAsyncVsSyncSendNow() throws InterruptedException {
ThreadRecordingEventHandler threadRecordingEventHandler = new ThreadRecordingEventHandler();
m_manager.setEventHandler(threadRecordingEventHandler);
EventBuilder bldr = new EventBuilder("uei.opennms.org/foo", "testAsyncVsSyncSendNow");
Event e = bldr.getEvent();
// Async: When invoking sendNow, the Runnable should be ran from thread other than the callers
m_manager.sendNow(e);
threadRecordingEventHandler.waitForEvent();
assertNotEquals(Thread.currentThread().getId(), threadRecordingEventHandler.getThreadId());
// Sync: When invoking sendNowSync, the Runnable should be ran from the callers thread
m_manager.sendNowSync(e);
assertEquals(Thread.currentThread().getId(), threadRecordingEventHandler.getThreadId());
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventUtilHibernateIT method testExpandParms.
@Test
@JUnitTemporaryDatabase
public void testExpandParms() {
String testString = "%uei%:%nodeid%:%nodelabel%:%nodelocation%";
/*
* Checking default location
*/
Event event1 = new EventBuilder("testUei", "testSource").setNodeid(1).getEvent();
String string1 = eventUtilDaoImpl.expandParms(testString, event1);
assertEquals("testUei:1:node1:Default", string1);
/*
* Checking custom location
*/
OnmsNode onmsNode = m_populator.getNodeDao().get(2);
onmsNode.setLocation(m_populator.getMonitoringLocationDao().get("RDU"));
m_populator.getNodeDao().update(onmsNode);
Event event2 = new EventBuilder("testUei", "testSource").setNodeid(2).getEvent();
String string2 = eventUtilDaoImpl.expandParms(testString, event2);
assertEquals("testUei:2:node2:RDU", string2);
}
Aggregations