use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class SyslogdIT method testRegexFacilitySeverityMatch.
@Test
public void testRegexFacilitySeverityMatch() throws Exception {
MockLogAppender.setupLogging(true, "TRACE");
final String testPDU = "2007-01-01 127.0.0.1 beer - Not just for lunch anymore";
final String testUEI = "uei.opennms.org/tests/syslogd/nonMessageMatch/facilitySeverity";
final String testMsg = "beer - Not just for lunch anymore";
final EventBuilder expectedEventBldr = new EventBuilder(testUEI, "syslogd");
expectedEventBldr.setInterface(InetAddressUtils.ONE_TWENTY_SEVEN);
expectedEventBldr.setLogDest("logndisplay");
expectedEventBldr.setLogMessage(testMsg);
expectedEventBldr.addParam("service", "local1");
expectedEventBldr.addParam("severity", "Warning");
m_eventIpcManager.getEventAnticipator().anticipateEvent(expectedEventBldr.getEvent());
final SyslogClient s = new SyslogClient(null, 10, SyslogClient.LOG_LOCAL1, InetAddressUtils.ONE_TWENTY_SEVEN);
s.syslog(SyslogClient.LOG_WARNING, testPDU);
m_eventIpcManager.getEventAnticipator().verifyAnticipated(5000, 0, 0, 0, 0);
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class SyslogdIT method testRegexUEIWithOnlyUserSpecifiedParameterAssignments.
@Test
public void testRegexUEIWithOnlyUserSpecifiedParameterAssignments() throws InterruptedException, UnknownHostException {
final String testPDU = "2007-01-01 127.0.0.1 tea: Secretly replaced cmiskell's tea with 666 ferrets";
final String testUEI = "uei.opennms.org/tests/syslogd/regexParameterAssignmentTest/userSpecifiedOnly";
final String testMsg = "Secretly replaced cmiskell's tea with 666 ferrets";
final String[] testGroups = { "cmiskell's", "666", "ferrets" };
final EventBuilder expectedEventBldr = new EventBuilder(testUEI, "syslogd");
expectedEventBldr.setInterface(InetAddressUtils.ONE_TWENTY_SEVEN);
expectedEventBldr.setLogDest("logndisplay");
expectedEventBldr.setLogMessage(testMsg);
expectedEventBldr.addParam("whoseBeverage", testGroups[0]);
expectedEventBldr.addParam("count", testGroups[1]);
expectedEventBldr.addParam("replacementItem", testGroups[2]);
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, testPDU);
m_eventIpcManager.getEventAnticipator().verifyAnticipated(5000, 0, 0, 0, 0);
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class SyslogdIT method testResolvePatternsSyslogNG.
@Test
public void testResolvePatternsSyslogNG() 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 SyslogdIT method testRegexSeverityMatch.
@Test
public void testRegexSeverityMatch() throws Exception {
MockLogAppender.setupLogging(true, "TRACE");
final String testPDU = "2007-01-01 127.0.0.1 beer - Not just for dinner anymore";
final String testUEI = "uei.opennms.org/tests/syslogd/nonMessageMatch/severityOnly";
final String testMsg = "beer - Not just for dinner anymore";
final EventBuilder expectedEventBldr = new EventBuilder(testUEI, "syslogd");
expectedEventBldr.setInterface(InetAddressUtils.ONE_TWENTY_SEVEN);
expectedEventBldr.setLogDest("logndisplay");
expectedEventBldr.setLogMessage(testMsg);
m_eventIpcManager.getEventAnticipator().anticipateEvent(expectedEventBldr.getEvent());
final SyslogClient s = new SyslogClient(null, 10, SyslogClient.LOG_DAEMON, InetAddressUtils.ONE_TWENTY_SEVEN);
s.syslog(SyslogClient.LOG_CRIT, testPDU);
m_eventIpcManager.getEventAnticipator().verifyAnticipated(10000, 0, 0, 0, 0);
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventIpcManagerDefaultImplTest method testSlowEventHandlerCausesDiscards.
public void testSlowEventHandlerCausesDiscards() throws InterruptedException {
AtomicInteger counter = new AtomicInteger();
AtomicInteger rejected = new AtomicInteger();
EventHandler handler = new EventHandler() {
@Override
public Runnable createRunnable(Log eventLog, boolean synchronous) {
return createRunnable(eventLog);
}
@Override
public Runnable createRunnable(Log eventLog) {
return new Runnable() {
@Override
public void run() {
try {
Thread.sleep(SLOW_EVENT_OPERATION_DELAY);
} catch (InterruptedException e) {
}
counter.incrementAndGet();
}
};
}
};
EventIpcManagerDefaultImpl manager = new EventIpcManagerDefaultImpl(m_registry);
manager.setEventHandler(handler);
manager.setHandlerPoolSize(1);
manager.setHandlerQueueLength(5);
manager.afterPropertiesSet();
//
for (int i = 0; i < 10; i++) {
EventBuilder bldr = new EventBuilder("uei.opennms.org/foo/" + i, "testDiscardWhenFullWithSlowEventListener");
Event event = bldr.getEvent();
try {
manager.sendNow(event);
} catch (RejectedExecutionException e) {
rejected.incrementAndGet();
}
}
await().pollInterval(1, TimeUnit.SECONDS).untilAtomic(counter, is(equalTo(6)));
await().pollInterval(1, TimeUnit.SECONDS).untilAtomic(rejected, is(equalTo(4)));
}
Aggregations