Search in sources :

Example 6 with EventBuilder

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;
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) ArrayList(java.util.ArrayList) Event(org.opennms.netmgt.xml.event.Event) Parm(org.opennms.netmgt.xml.event.Parm)

Example 7 with EventBuilder

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());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) IOException(java.io.IOException)

Example 8 with EventBuilder

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();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event)

Example 9 with EventBuilder

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();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

Example 10 with EventBuilder

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));
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event) EventListener(org.opennms.netmgt.events.api.EventListener) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

EventBuilder (org.opennms.netmgt.model.events.EventBuilder)275 Event (org.opennms.netmgt.xml.event.Event)75 Test (org.junit.Test)72 Date (java.util.Date)19 InetAddress (java.net.InetAddress)15 OnmsNode (org.opennms.netmgt.model.OnmsNode)14 AlarmData (org.opennms.netmgt.xml.event.AlarmData)14 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)11 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)11 ServletException (javax.servlet.ServletException)9 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)9 ArrayList (java.util.ArrayList)8 SyntaxToEvent (org.opennms.netmgt.model.events.snmp.SyntaxToEvent)7 Transactional (org.springframework.transaction.annotation.Transactional)7 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)6 Parm (org.opennms.netmgt.xml.event.Parm)6 Event (org.opennms.netmgt.xml.eventconf.Event)6 HttpSession (javax.servlet.http.HttpSession)5 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)5 Log (org.opennms.netmgt.xml.event.Log)5