Search in sources :

Example 26 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 27 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)

Example 28 with EventBuilder

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

the class Nms4335IT method doMessageTest.

/**
     * Send a raw syslog message and expect a given event as a result
     * 
     * @param testPDU The raw syslog message as it would appear on the wire (just the UDP payload)
     * @param expectedHost The host from which the event should be resolved as originating
     * @param expectedUEI The expected UEI of the resulting event
     * @param expectedLogMsg The expected contents of the logmsg for the resulting event 
     * 
     * @throws UnknownHostException 
     * @throws InterruptedException 
     * @throws ExecutionException 
     */
private List<Event> doMessageTest(String testPDU, String expectedHost, String expectedUEI, String expectedLogMsg) throws UnknownHostException, InterruptedException, ExecutionException {
    SyslogdTestUtils.startSyslogdGracefully(m_syslogd);
    final EventBuilder expectedEventBldr = new EventBuilder(expectedUEI, "syslogd");
    expectedEventBldr.setInterface(addr(expectedHost));
    expectedEventBldr.setLogDest("logndisplay");
    expectedEventBldr.setLogMessage(expectedLogMsg);
    m_eventIpcManager.getEventAnticipator().anticipateEvent(expectedEventBldr.getEvent());
    final SyslogSinkConsumer syslogSinkConsumer = new SyslogSinkConsumer(new MetricRegistry());
    syslogSinkConsumer.setDistPollerDao(m_distPollerDao);
    syslogSinkConsumer.setSyslogdConfig(m_config);
    syslogSinkConsumer.setEventForwarder(m_eventIpcManager);
    final SyslogSinkModule syslogSinkModule = syslogSinkConsumer.getModule();
    final SyslogClient sc = new SyslogClient(null, 10, SyslogClient.LOG_DAEMON, addr("127.0.0.1"));
    final DatagramPacket pkt = sc.getPacket(SyslogClient.LOG_DEBUG, testPDU);
    final SyslogMessageLogDTO messageLog = syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
    syslogSinkConsumer.handleMessage(messageLog);
    m_eventIpcManager.getEventAnticipator().verifyAnticipated(5000, 0, 0, 0, 0);
    final Event receivedEvent = m_eventIpcManager.getEventAnticipator().getAnticipatedEventsReceived().get(0);
    assertEquals("Log messages do not match", expectedLogMsg, receivedEvent.getLogmsg().getContent());
    return m_eventIpcManager.getEventAnticipator().getAnticipatedEventsReceived();
}
Also used : SyslogMessageLogDTO(org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) MetricRegistry(com.codahale.metrics.MetricRegistry) DatagramPacket(java.net.DatagramPacket) Event(org.opennms.netmgt.xml.event.Event) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection)

Example 29 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 30 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)

Aggregations

EventBuilder (org.opennms.netmgt.model.events.EventBuilder)275 Event (org.opennms.netmgt.xml.event.Event)75 Test (org.junit.Test)72 Date (java.util.Date)19 InetAddress (java.net.InetAddress)15 OnmsNode (org.opennms.netmgt.model.OnmsNode)14 AlarmData (org.opennms.netmgt.xml.event.AlarmData)14 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)11 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)11 ServletException (javax.servlet.ServletException)9 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)9 ArrayList (java.util.ArrayList)8 SyntaxToEvent (org.opennms.netmgt.model.events.snmp.SyntaxToEvent)7 Transactional (org.springframework.transaction.annotation.Transactional)7 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)6 Parm (org.opennms.netmgt.xml.event.Parm)6 Event (org.opennms.netmgt.xml.eventconf.Event)6 HttpSession (javax.servlet.http.HttpSession)5 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)5 Log (org.opennms.netmgt.xml.event.Log)5