Search in sources :

Example 16 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class EventUtilIT method testNamedParameterExpansion.

@Test
public void testNamedParameterExpansion() {
    // Create an expandable string that references N
    // distinct named parameters
    final int N = 6;
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < N; i++) {
        sb.append("%parm[" + i + "]%");
    }
    String expandable = sb.toString();
    // Now create an event with N parameters matching
    // the names that are referenced above
    EventBuilder eb = new EventBuilder("uei", "test");
    for (int i = 0; i < N; i++) {
        // The named parameters in the expandable should
        // match the parameters name here even when we pad
        // them with whitespace
        eb.addParam(" \n\t" + i + "\n\t ", i);
    }
    Event e = eb.getEvent();
    // Manually generate the expected string
    sb = new StringBuilder();
    for (int i = 0; i < N; i++) {
        sb.append(i);
    }
    String expected = sb.toString();
    // Expand!
    assertEquals(expected, eventUtil.expandParms(expandable, e));
    final int M = 1000;
    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++) {
        eventUtil.expandParms(expandable, e);
    }
    System.err.printf("Succesfully expanded %d events with %d parameters in %d ms\n", M, N, System.currentTimeMillis() - start);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Example 17 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class EventdIT method sendServiceDownEvent.

/**
     * @param reductionKey
     */
private void sendServiceDownEvent(String reductionKey, OnmsMonitoredService svc) {
    final EventBuilder e = MockEventUtil.createEventBuilder("Test", EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, svc.getNodeId(), str(svc.getIpAddress()), svc.getServiceName(), "Not responding");
    if (reductionKey != null) {
        AlarmData data = new AlarmData();
        data.setAlarmType(1);
        data.setReductionKey(reductionKey);
        e.setAlarmData(data);
    } else {
        e.setAlarmData(null);
    }
    e.setLogDest("logndisplay");
    e.setLogMessage("testing");
    m_eventdIpcMgr.sendNow(e.getEvent());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) AlarmData(org.opennms.netmgt.xml.event.AlarmData)

Example 18 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class EventdMemoryLeakIT method sendEvent.

private void sendEvent(EventProxy proxy, long count) throws Exception {
    EventBuilder bldr = new EventBuilder("uei.opennms.org/internal/authentication/successfulLogin", "MemoryLeakTest");
    bldr.addParam("user", "brozow");
    proxy.send(bldr.getEvent());
    long free = Runtime.getRuntime().freeMemory();
    long max = Runtime.getRuntime().maxMemory();
    double pct = ((double) free) / ((double) max);
    System.err.println("% Free Memory is " + pct);
    if (pct < 0.01) {
        throw new IllegalStateException("Memory Used up!");
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

Example 19 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class HibernateEventWriterIT method testWriteEventDescrWithNull.

/**
     * Tests writing nulls to postgres db and the db encoding.
     * @throws SQLException
     */
@Test
public void testWriteEventDescrWithNull() throws Exception {
    EventBuilder bldr = new EventBuilder("testUei", "testSource");
    bldr.setLogDest(HibernateEventWriter.LOG_MSG_DEST_LOG_AND_DISPLAY);
    bldr.setDescription("abcdef");
    Event event = bldr.getEvent();
    assertEquals(new Integer(0), event.getDbid());
    m_eventWriter.process(bldr.getLog());
    assertTrue(event.getDbid() > 0);
    final String descr = jdbcTemplate.queryForObject("SELECT eventDescr FROM events LIMIT 1", String.class);
    assertEquals("abc%0def", descr);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Example 20 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class HibernateEventWriterIT method testEventDistPoller.

/**
     * Tests writing events with various distPoller values.
     * 
     * @throws SQLException
     */
@Test
public void testEventDistPoller() throws Exception {
    String systemId = UUID.randomUUID().toString();
    EventBuilder bldr = new EventBuilder("testUei", "testSource");
    bldr.setDistPoller(systemId);
    bldr.setLogMessage("test");
    Event event = bldr.getEvent();
    assertEquals(new Integer(0), event.getDbid());
    m_eventWriter.process(bldr.getLog());
    assertTrue(event.getDbid() > 0);
    String minionId = jdbcTemplate.queryForObject("SELECT systemId FROM events LIMIT 1", String.class);
    assertEquals(DistPollerDao.DEFAULT_DIST_POLLER_ID, minionId);
    jdbcTemplate.execute("DELETE FROM events");
    jdbcTemplate.execute(String.format("INSERT INTO monitoringsystems (id, location, type) VALUES ('%s', 'Hello World', '%s')", systemId, OnmsMonitoringSystem.TYPE_MINION));
    event = bldr.getEvent();
    m_eventWriter.process(bldr.getLog());
    assertTrue(event.getDbid() > 0);
    minionId = jdbcTemplate.queryForObject("SELECT systemId FROM events LIMIT 1", String.class);
    assertEquals(systemId, minionId);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

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