Search in sources :

Example 71 with EventBuilder

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);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Test(org.junit.Test)

Example 72 with EventBuilder

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);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Test(org.junit.Test)

Example 73 with EventBuilder

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);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Test(org.junit.Test)

Example 74 with EventBuilder

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);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Test(org.junit.Test)

Example 75 with EventBuilder

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)));
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Log(org.opennms.netmgt.xml.event.Log) EventHandler(org.opennms.netmgt.events.api.EventHandler) Event(org.opennms.netmgt.xml.event.Event) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

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