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 EventIpcManagerDefaultImplTest method testAddEventListenerTwoArgumentStringWithUeiPartTooLittleAndBroadcast.
public void testAddEventListenerTwoArgumentStringWithUeiPartTooLittleAndBroadcast() throws Exception {
EventBuilder bldr = new EventBuilder("uei.opennms.org/foo", "testAddEventListenerTwoArgumentStringWithUeiPartTooLittleAndBroadcast");
Event e = bldr.getEvent();
m_mocks.replayAll();
m_manager.addEventListener(m_listener, "uei.opennms.org");
m_manager.broadcastNow(e, false);
Thread.sleep(100);
m_mocks.verifyAll();
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventIpcManagerDefaultImplTest method testBroadcastWithNoListeners.
public void testBroadcastWithNoListeners() throws Exception {
EventBuilder bldr = new EventBuilder(null, "testBroadcastWithNoListeners");
m_mocks.replayAll();
m_manager.broadcastNow(bldr.getEvent(), false);
Thread.sleep(100);
m_mocks.verifyAll();
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventIpcManagerDefaultImplTest method testRecursiveEvents.
/**
* This test creates two event listeners that both create events as they
* handle events. This test can be used to detect deadlocks between the
* listeners.
*
* @throws InterruptedException
*/
public void testRecursiveEvents() throws InterruptedException {
final int numberOfEvents = 20;
CountDownLatch fooCounter = new CountDownLatch(numberOfEvents);
CountDownLatch barCounter = new CountDownLatch(numberOfEvents);
CountDownLatch kiwiCounter = new CountDownLatch(numberOfEvents);
CountDownLatch ulfCounter = new CountDownLatch(numberOfEvents);
final EventIpcManagerDefaultImpl manager = new EventIpcManagerDefaultImpl(m_registry);
manager.setHandlerPoolSize(1);
//manager.setHandlerQueueLength(5);
DefaultEventHandlerImpl handler = new DefaultEventHandlerImpl(m_registry);
manager.setEventHandler(handler);
manager.afterPropertiesSet();
EventListener slowFooBarListener = new EventListener() {
@Override
public String getName() {
return "slowFooBarListener";
}
@Override
public void onEvent(Event event) {
if ("uei.opennms.org/foo".equals(event.getUei())) {
EventBuilder bldr = new EventBuilder("uei.opennms.org/bar", "testRecursiveEvents");
Event e = bldr.getEvent();
manager.broadcastNow(e, false);
fooCounter.countDown();
} else {
try {
Thread.sleep(SLOW_EVENT_OPERATION_DELAY);
} catch (InterruptedException e) {
}
barCounter.countDown();
}
}
};
EventListener slowKiwiUlfListener = new EventListener() {
@Override
public String getName() {
return "slowKiwiUlfListener";
}
@Override
public void onEvent(Event event) {
if ("uei.opennms.org/foo".equals(event.getUei())) {
EventBuilder bldr = new EventBuilder("uei.opennms.org/ulf", "testRecursiveEvents");
Event e = bldr.getEvent();
manager.broadcastNow(e, false);
kiwiCounter.countDown();
} else {
try {
Thread.sleep(SLOW_EVENT_OPERATION_DELAY);
} catch (InterruptedException e) {
}
ulfCounter.countDown();
}
}
};
manager.addEventListener(slowFooBarListener);
manager.addEventListener(slowKiwiUlfListener);
//
for (int i = 0; i < numberOfEvents; i++) {
EventBuilder bldr = new EventBuilder("uei.opennms.org/foo", "testRecursiveEvents");
Event e = bldr.getEvent();
manager.broadcastNow(e, false);
}
assertTrue("foo counter not satisfied: " + fooCounter.getCount(), fooCounter.await(100, TimeUnit.SECONDS));
assertTrue("bar counter not satisfied: " + barCounter.getCount(), barCounter.await(100, TimeUnit.SECONDS));
assertTrue("kiwi counter not satisfied: " + kiwiCounter.getCount(), kiwiCounter.await(100, TimeUnit.SECONDS));
assertTrue("ulf counter not satisfied: " + ulfCounter.getCount(), ulfCounter.await(100, TimeUnit.SECONDS));
}
Aggregations