Search in sources :

Example 66 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 67 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 68 with EventBuilder

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

the class HibernateEventWriterIT method testSendEventWithService.

@Test
public void testSendEventWithService() throws Exception {
    int serviceId = 1;
    String serviceName = "some bogus service";
    jdbcTemplate.update("insert into service (serviceId, serviceName) values (?, ?)", new Object[] { serviceId, serviceName });
    EventBuilder bldr = new EventBuilder("uei.opennms.org/foo", "someSource");
    bldr.setLogMessage(HibernateEventWriter.LOG_MSG_DEST_LOG_AND_DISPLAY);
    bldr.setService(serviceName);
    Event event = bldr.getEvent();
    assertEquals(new Integer(0), event.getDbid());
    m_eventWriter.process(bldr.getLog());
    assertTrue(event.getDbid() > 0);
    assertEquals("event count", new Integer(1), jdbcTemplate.queryForObject("select count(*) from events", Integer.class));
    assertEquals("event service ID", new Integer(serviceId), jdbcTemplate.queryForObject("select serviceID from events", Integer.class));
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Example 69 with EventBuilder

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

the class SyslogdIT method testIPPatternsSyslogNG.

@Test
public void testIPPatternsSyslogNG() throws UnknownHostException {
    final EventBuilder expectedEventBldr = new EventBuilder("uei.opennms.org/syslogd/system/Debug", "syslogd");
    expectedEventBldr.setInterface(InetAddressUtils.ONE_TWENTY_SEVEN);
    expectedEventBldr.setLogDest("logndisplay");
    expectedEventBldr.setLogMessage("A SyslogNG style message");
    m_eventIpcManager.getEventAnticipator().anticipateEvent(expectedEventBldr.getEvent());
    final SyslogClient s = new SyslogClient(null, 10, SyslogClient.LOG_DAEMON, InetAddressUtils.ONE_TWENTY_SEVEN);
    s.syslog(SyslogClient.LOG_DEBUG, "2007-01-01 127.0.0.1 A SyslogNG style message");
    m_eventIpcManager.getEventAnticipator().verifyAnticipated(10000, 0, 0, 0, 0);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Test(org.junit.Test)

Example 70 with EventBuilder

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

the class SyslogSinkConsumer method sendNewSuspectEvent.

private void sendNewSuspectEvent(String localAddr, String trapInterface, String distPoller) {
    EventBuilder bldr = new EventBuilder(EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI, "syslogd");
    bldr.setInterface(addr(trapInterface));
    bldr.setHost(localAddr);
    bldr.setDistPoller(distPoller);
    eventForwarder.sendNow(bldr.getEvent());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

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