Search in sources :

Example 61 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 62 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 63 with EventBuilder

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

Example 64 with EventBuilder

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

Example 65 with EventBuilder

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);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Aggregations

EventBuilder (org.opennms.netmgt.model.events.EventBuilder)305 Test (org.junit.Test)88 Event (org.opennms.netmgt.xml.event.Event)84 Date (java.util.Date)22 OnmsNode (org.opennms.netmgt.model.OnmsNode)17 InetAddress (java.net.InetAddress)16 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)15 AlarmData (org.opennms.netmgt.xml.event.AlarmData)14 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)12 ServletException (javax.servlet.ServletException)9 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)9 Parm (org.opennms.netmgt.xml.event.Parm)9 Event (org.opennms.netmgt.xml.eventconf.Event)9 File (java.io.File)8 ArrayList (java.util.ArrayList)8 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)7 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)7 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 SyntaxToEvent (org.opennms.netmgt.model.events.snmp.SyntaxToEvent)7 Transactional (org.springframework.transaction.annotation.Transactional)6