Search in sources :

Example 6 with SyslogMessageLogDTO

use of org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO in project opennms by OpenNMS.

the class SyslogdLoadIT method testNGSyslog.

@Test
@Transactional
public void testNGSyslog() throws Exception {
    loadSyslogConfiguration("/etc/syslogd-syslogng-configuration.xml");
    startSyslogdJavaNet();
    m_eventCounter.anticipate();
    InetAddress address = InetAddress.getLocalHost();
    // handle an invalid packet
    byte[] bytes = "<34>main: 2010-08-19 localhost foo0: load test 0 on tty1\0".getBytes();
    DatagramPacket pkt = new DatagramPacket(bytes, bytes.length, address, SyslogClient.PORT);
    SyslogMessageLogDTO messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
    m_syslogSinkConsumer.handleMessage(messageLog);
    // handle a valid packet
    bytes = "<34>monkeysatemybrain!\0".getBytes();
    pkt = new DatagramPacket(bytes, bytes.length, address, SyslogClient.PORT);
    messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
    m_syslogSinkConsumer.handleMessage(messageLog);
    m_eventCounter.waitForFinish(120000);
    assertEquals(1, m_eventCounter.getCount());
}
Also used : SyslogMessageLogDTO(org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO) DatagramPacket(java.net.DatagramPacket) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection) InetAddress(java.net.InetAddress) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with SyslogMessageLogDTO

use of org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO in project opennms by OpenNMS.

the class SyslogdLoadIT method testRfcSyslog.

@Test
@Transactional
public void testRfcSyslog() throws Exception {
    loadSyslogConfiguration("/etc/syslogd-rfc-configuration.xml");
    startSyslogdJavaNet();
    m_eventCounter.anticipate();
    InetAddress address = InetAddress.getLocalHost();
    // handle an invalid packet
    byte[] bytes = "<34>1 2010-08-19T22:14:15.000Z localhost - - - - foo0: load test 0 on tty1\0".getBytes();
    DatagramPacket pkt = new DatagramPacket(bytes, bytes.length, address, SyslogClient.PORT);
    SyslogMessageLogDTO messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
    m_syslogSinkConsumer.handleMessage(messageLog);
    // handle a valid packet
    bytes = "<34>1 2003-10-11T22:14:15.000Z plonk -ev/pts/8\0".getBytes();
    pkt = new DatagramPacket(bytes, bytes.length, address, SyslogClient.PORT);
    messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
    m_syslogSinkConsumer.handleMessage(messageLog);
    m_eventCounter.waitForFinish(120000);
    assertEquals(1, m_eventCounter.getCount());
}
Also used : SyslogMessageLogDTO(org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO) DatagramPacket(java.net.DatagramPacket) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection) InetAddress(java.net.InetAddress) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with SyslogMessageLogDTO

use of org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO in project opennms by OpenNMS.

the class SyslogdEventdLoadIT method testNGSyslog.

@Test(timeout = 120000)
@Transactional
public void testNGSyslog() throws Exception {
    loadSyslogConfiguration("/etc/syslogd-syslogng-configuration.xml");
    startSyslogdGracefully();
    m_eventCounter.anticipate();
    InetAddress address = InetAddress.getLocalHost();
    // handle an invalid packet
    byte[] bytes = "<34>main: 2010-08-19 localhost foo0: load test 0 on tty1\0".getBytes();
    DatagramPacket pkt = new DatagramPacket(bytes, bytes.length, address, SyslogClient.PORT);
    SyslogMessageLogDTO messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
    m_syslogSinkConsumer.handleMessage(messageLog);
    // handle a valid packet
    bytes = "<34>monkeysatemybrain!\0".getBytes();
    pkt = new DatagramPacket(bytes, bytes.length, address, SyslogClient.PORT);
    messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
    m_syslogSinkConsumer.handleMessage(messageLog);
    m_eventCounter.waitForFinish(120000);
    assertEquals(1, m_eventCounter.getCount());
}
Also used : SyslogMessageLogDTO(org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO) DatagramPacket(java.net.DatagramPacket) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection) InetAddress(java.net.InetAddress) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with SyslogMessageLogDTO

use of org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO in project opennms by OpenNMS.

the class SyslogdIT 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 {
    final EventBuilder expectedEventBldr = new EventBuilder(expectedUEI, "syslogd");
    expectedEventBldr.setInterface(addr(expectedHost));
    expectedEventBldr.setLogDest("logndisplay");
    expectedEventBldr.setLogMessage(expectedLogMsg);
    m_eventIpcManager.getEventAnticipator().anticipateEvent(expectedEventBldr.getEvent());
    final SyslogClient sc = new SyslogClient(null, 10, SyslogClient.LOG_DAEMON, InetAddressUtils.ONE_TWENTY_SEVEN);
    final DatagramPacket pkt = sc.getPacket(SyslogClient.LOG_DEBUG, testPDU);
    SyslogMessageLogDTO messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
    m_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) DatagramPacket(java.net.DatagramPacket) Event(org.opennms.netmgt.xml.event.Event) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection)

Example 10 with SyslogMessageLogDTO

use of org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO in project opennms by OpenNMS.

the class SyslogSinkConsumerNewSuspectIT method dispatchAndCapture.

/**
     * Converts given connection to a DTO and dispatches it to the consumer.
     *
     * We then wait until an Event is sent to the forwarder, and return the
     * captured event.
     */
private Event dispatchAndCapture(SyslogConnection connection) {
    // Wrap
    SyslogMessageLogDTO messageLog = m_syslogSinkModule.toMessageLog(connection);
    // Dispatch
    m_syslogSinkConsumer.handleMessage(messageLog);
    // Capture
    await().until(() -> m_anticipator.getUnanticipatedEvents().size(), equalTo(1));
    // Capture
    final List<Event> events = m_anticipator.getUnanticipatedEvents();
    assertEquals(1, events.size());
    final Event event = events.get(0);
    m_anticipator.reset();
    return event;
}
Also used : SyslogMessageLogDTO(org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO) Event(org.opennms.netmgt.xml.event.Event)

Aggregations

SyslogMessageLogDTO (org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO)11 SyslogConnection (org.opennms.netmgt.syslogd.api.SyslogConnection)10 DatagramPacket (java.net.DatagramPacket)8 Test (org.junit.Test)6 Transactional (org.springframework.transaction.annotation.Transactional)6 InetAddress (java.net.InetAddress)4 Event (org.opennms.netmgt.xml.event.Event)3 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)2 SyslogMessageDTO (org.opennms.netmgt.syslogd.api.SyslogMessageDTO)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 AggregationPolicy (org.opennms.core.ipc.sink.api.AggregationPolicy)1