Search in sources :

Example 1 with SyslogdConfigFactory

use of org.opennms.netmgt.config.SyslogdConfigFactory in project opennms by OpenNMS.

the class SyslogdImplementationsIT method loadSyslogConfiguration.

private void loadSyslogConfiguration(final String configuration) throws IOException {
    InputStream stream = null;
    try {
        stream = ConfigurationTestUtils.getInputStreamForResource(this, configuration);
        m_config = new SyslogdConfigFactory(stream);
    } finally {
        if (stream != null) {
            IOUtils.closeQuietly(stream);
        }
    }
}
Also used : InputStream(java.io.InputStream) SyslogdConfigFactory(org.opennms.netmgt.config.SyslogdConfigFactory)

Example 2 with SyslogdConfigFactory

use of org.opennms.netmgt.config.SyslogdConfigFactory in project opennms by OpenNMS.

the class ConvertToEventTest method testCiscoEventConversion.

@Test
public void testCiscoEventConversion() throws IOException {
    InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-cisco-configuration.xml");
    SyslogdConfig config = new SyslogdConfigFactory(stream);
    try {
        ConvertToEvent convertToEvent = new ConvertToEvent(DistPollerDao.DEFAULT_DIST_POLLER_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, InetAddressUtils.ONE_TWENTY_SEVEN, 9999, SyslogdTestUtils.toByteBuffer("<190>Mar 11 08:35:17 aaa_host 30128311: Mar 11 08:35:16.844 CST: %SEC-6-IPACCESSLOGP: list in110 denied tcp 192.168.10.100(63923) -> 192.168.11.128(1521), 1 packet"), config);
        LOG.info("Generated event: {}", convertToEvent.getEvent().toString());
    } catch (MessageDiscardedException e) {
        LOG.error("Message Parsing failed", e);
        fail("Message Parsing failed: " + e.getMessage());
    }
}
Also used : InputStream(java.io.InputStream) SyslogdConfig(org.opennms.netmgt.config.SyslogdConfig) SyslogdConfigFactory(org.opennms.netmgt.config.SyslogdConfigFactory) Test(org.junit.Test)

Example 3 with SyslogdConfigFactory

use of org.opennms.netmgt.config.SyslogdConfigFactory in project opennms by OpenNMS.

the class ConvertToEventTest method testConvertToEvent.

/**
 * Test method which calls the ConvertToEvent constructor.
 *
 * @throws IOException
 */
@Test
public void testConvertToEvent() throws IOException {
    InterfaceToNodeCacheDaoImpl.setInstance(new MockInterfaceToNodeCache());
    // 10000 sample syslogmessages from xml file are taken and passed as
    // Inputstream to create syslogdconfiguration
    InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-loadtest-configuration.xml");
    SyslogdConfig config = new SyslogdConfigFactory(stream);
    // Sample message which is embedded in packet and passed as parameter
    // to
    // ConvertToEvent constructor
    byte[] bytes = "<34> 2010-08-19 localhost foo10000: load test 10000 on tty1".getBytes(StandardCharsets.US_ASCII);
    // Datagram packet which is passed as parameter for ConvertToEvent
    // constructor
    DatagramPacket pkt = new DatagramPacket(bytes, bytes.length, InetAddress.getLocalHost(), SyslogClient.PORT);
    ByteBuffer data = ByteBuffer.wrap(pkt.getData());
    // @param len The length of the XML data in the buffer
    try {
        ConvertToEvent convertToEvent = new ConvertToEvent(DistPollerDao.DEFAULT_DIST_POLLER_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, pkt.getAddress(), pkt.getPort(), data, config);
        LOG.info("Generated event: {}", convertToEvent.getEvent().toString());
    } catch (MessageDiscardedException e) {
        LOG.error("Message Parsing failed", e);
        fail("Message Parsing failed: " + e.getMessage());
    }
}
Also used : InputStream(java.io.InputStream) DatagramPacket(java.net.DatagramPacket) MockInterfaceToNodeCache(org.opennms.netmgt.dao.mock.MockInterfaceToNodeCache) SyslogdConfig(org.opennms.netmgt.config.SyslogdConfig) ByteBuffer(java.nio.ByteBuffer) SyslogdConfigFactory(org.opennms.netmgt.config.SyslogdConfigFactory) Test(org.junit.Test)

Example 4 with SyslogdConfigFactory

use of org.opennms.netmgt.config.SyslogdConfigFactory in project opennms by OpenNMS.

the class SyslogMessageTest method testCustomParserNms5242.

@Test
public void testCustomParserNms5242() throws Exception {
    final Locale startLocale = Locale.getDefault();
    try {
        Locale.setDefault(Locale.FRANCE);
        final InputStream stream = new ByteArrayInputStream(("<?xml version=\"1.0\"?>\n" + "<syslogd-configuration>\n" + "    <configuration\n" + "            syslog-port=\"10514\"\n" + "            new-suspect-on-message=\"false\"\n" + "            parser=\"org.opennms.netmgt.syslogd.CustomSyslogParser\"\n" + "            forwarding-regexp=\"^((.+?) (.*))\\n?$\"\n" + "            matching-group-host=\"2\"\n" + "            matching-group-message=\"3\"\n" + "            discard-uei=\"DISCARD-MATCHING-MESSAGES\"\n" + "            />\n" + "\n" + "    <hideMessage>\n" + "        <hideMatch>\n" + "            <match type=\"substr\" expression=\"TEST\"/>\n" + "        </hideMatch>\n" + "    </hideMessage>\n" + "</syslogd-configuration>\n").getBytes());
        final SyslogdConfigFactory config = new SyslogdConfigFactory(stream);
        final SyslogParser parser = new CustomSyslogParser(config, SyslogdTestUtils.toByteBuffer("<0>Mar 14 17:10:25 petrus sudo:  cyrille : user NOT in sudoers ; TTY=pts/2 ; PWD=/home/cyrille ; USER=root ; COMMAND=/usr/bin/vi /etc/aliases"));
        assertTrue(parser.find());
        final SyslogMessage message = parser.parse();
        LOG.debug("message = {}", message);
        final Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, ZonedDateTimeBuilder.getBestYearForMonth(Month.MARCH.getValue()));
        cal.set(Calendar.MONTH, Calendar.MARCH);
        cal.set(Calendar.DAY_OF_MONTH, 14);
        cal.set(Calendar.HOUR_OF_DAY, 17);
        cal.set(Calendar.MINUTE, 10);
        cal.set(Calendar.SECOND, 25);
        cal.set(Calendar.MILLISECOND, 0);
        assertEquals(SyslogFacility.KERNEL, message.getFacility());
        assertEquals(SyslogSeverity.EMERGENCY, message.getSeverity());
        assertNull(message.getMessageID());
        assertEquals(cal.getTime(), message.getDate());
        assertEquals("petrus", message.getHostName());
        assertEquals("sudo", message.getProcessName());
        assertEquals(null, message.getProcessId());
        assertEquals("cyrille : user NOT in sudoers ; TTY=pts/2 ; PWD=/home/cyrille ; USER=root ; COMMAND=/usr/bin/vi /etc/aliases", message.getMessage());
    } finally {
        Locale.setDefault(startLocale);
    }
}
Also used : Locale(java.util.Locale) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) SyslogdConfigFactory(org.opennms.netmgt.config.SyslogdConfigFactory) Test(org.junit.Test)

Example 5 with SyslogdConfigFactory

use of org.opennms.netmgt.config.SyslogdConfigFactory in project opennms by OpenNMS.

the class SyslogdIT method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    MockLogAppender.resetState();
    InputStream stream = null;
    try {
        stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-configuration.xml");
        m_config = new SyslogdConfigFactory(stream);
    } finally {
        if (stream != null) {
            IOUtils.closeQuietly(stream);
        }
    }
    // Verify that the test syslogd-configuration.xml file was loaded
    boolean foundBeer = false;
    boolean foundMalt = false;
    assertEquals(10514, m_config.getSyslogPort());
    for (final UeiMatch match : m_config.getUeiList()) {
        if (match.getProcessMatch().isPresent()) {
            final ProcessMatch processMatch = match.getProcessMatch().get();
            if (!foundBeer && "beerd".equals(processMatch.getExpression())) {
                foundBeer = true;
            } else if (!foundMalt && "maltd".equals(processMatch.getExpression())) {
                foundMalt = true;
            }
        }
    }
    assertTrue(foundBeer);
    assertTrue(foundMalt);
    m_syslogSinkConsumer = new SyslogSinkConsumer(new MetricRegistry());
    m_syslogSinkConsumer.setDistPollerDao(m_distPollerDao);
    m_syslogSinkConsumer.setSyslogdConfig(m_config);
    m_syslogSinkConsumer.setEventForwarder(m_eventIpcManager);
    m_syslogSinkModule = m_syslogSinkConsumer.getModule();
    m_messageDispatcherFactory.setConsumer(m_syslogSinkConsumer);
    SyslogReceiverJavaNetImpl receiver = new SyslogReceiverJavaNetImpl(m_config);
    receiver.setDistPollerDao(m_distPollerDao);
    receiver.setMessageDispatcherFactory(m_messageDispatcherFactory);
    m_syslogd.setSyslogReceiver(receiver);
    m_syslogd.init();
    SyslogdTestUtils.startSyslogdGracefully(m_syslogd);
}
Also used : ProcessMatch(org.opennms.netmgt.config.syslogd.ProcessMatch) InputStream(java.io.InputStream) MetricRegistry(com.codahale.metrics.MetricRegistry) UeiMatch(org.opennms.netmgt.config.syslogd.UeiMatch) SyslogdConfigFactory(org.opennms.netmgt.config.SyslogdConfigFactory) Before(org.junit.Before)

Aggregations

SyslogdConfigFactory (org.opennms.netmgt.config.SyslogdConfigFactory)12 InputStream (java.io.InputStream)11 Test (org.junit.Test)6 SyslogdConfig (org.opennms.netmgt.config.SyslogdConfig)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Before (org.junit.Before)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 ByteBuffer (java.nio.ByteBuffer)2 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 DatagramPacket (java.net.DatagramPacket)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Date (java.util.Date)1 List (java.util.List)1 Locale (java.util.Locale)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertNull (org.junit.Assert.assertNull)1