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);
}
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!");
}
}
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));
}
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);
}
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());
}
Aggregations