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