Search in sources :

Example 1 with UeiMatch

use of org.opennms.netmgt.config.syslogd.UeiMatch 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)

Example 2 with UeiMatch

use of org.opennms.netmgt.config.syslogd.UeiMatch in project opennms by OpenNMS.

the class SyslogdConfigFactory method parseIncludedFiles.

/**
 * Parse import-file tags and add all uei-matchs and hide-messages.
 *
 * @throws IOException
 */
private void parseIncludedFiles() throws IOException {
    final File configDir;
    try {
        configDir = ConfigFileConstants.getFile(ConfigFileConstants.SYSLOGD_CONFIG_FILE_NAME).getParentFile();
    } catch (final Throwable t) {
        LOG.warn("Error getting default syslogd configuration location. <import-file> directives will be ignored.  This should really only happen in unit tests.");
        return;
    }
    for (final String fileName : m_config.getImportFiles()) {
        final File configFile = new File(configDir, fileName);
        final SyslogdConfigurationGroup includeCfg = JaxbUtils.unmarshal(SyslogdConfigurationGroup.class, new FileSystemResource(configFile));
        if (includeCfg.getUeiMatches() != null) {
            for (final UeiMatch ueiMatch : includeCfg.getUeiMatches()) {
                if (m_config.getUeiMatches() == null) {
                    m_config.setUeiMatches(new ArrayList<>());
                }
                m_config.addUeiMatch(ueiMatch);
            }
        }
        if (includeCfg.getHideMatches() != null) {
            for (final HideMatch hideMatch : includeCfg.getHideMatches()) {
                if (m_config.getHideMatches() == null) {
                    m_config.setHideMatches(new ArrayList<>());
                }
                m_config.addHideMatch(hideMatch);
            }
        }
    }
}
Also used : SyslogdConfigurationGroup(org.opennms.netmgt.config.syslogd.SyslogdConfigurationGroup) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) UeiMatch(org.opennms.netmgt.config.syslogd.UeiMatch) HideMatch(org.opennms.netmgt.config.syslogd.HideMatch)

Example 3 with UeiMatch

use of org.opennms.netmgt.config.syslogd.UeiMatch in project opennms by OpenNMS.

the class SyslogdConfigFactoryIT method testUEI.

@Test
public void testUEI() {
    List<UeiMatch> ueiList = m_factory.getUeiList();
    UeiMatch uei = ueiList.get(0);
    Assert.assertEquals("substr", uei.getMatch().getType());
    Assert.assertEquals("CRISCO", uei.getMatch().getExpression());
    Assert.assertEquals("uei.opennms.org/tests/syslogd/substrUeiRewriteTest", uei.getUei());
    uei = ueiList.get(1);
    Assert.assertEquals("regex", uei.getMatch().getType());
    Assert.assertEquals("foo: (\\d+) out of (\\d+) tests failed for (\\S+)$", uei.getMatch().getExpression());
    Assert.assertEquals("uei.opennms.org/tests/syslogd/regexUeiRewriteTest", uei.getUei());
}
Also used : UeiMatch(org.opennms.netmgt.config.syslogd.UeiMatch) Test(org.junit.Test)

Example 4 with UeiMatch

use of org.opennms.netmgt.config.syslogd.UeiMatch in project opennms by OpenNMS.

the class SyslogdConfigFactoryIT method testImportFiles.

@Test
public void testImportFiles() throws Exception {
    SyslogdConfigFactory factory = new SyslogdConfigFactory(this.getClass().getResourceAsStream("syslogd-configuration-with-imports.xml"));
    Assert.assertEquals(22, factory.getUeiList().size());
    Assert.assertEquals(4, factory.getHideMessages().size());
    int countMatch = 0;
    for (final HideMatch hide : factory.getHideMessages()) {
        if (hide.getMatch().getExpression().startsWith("bad"))
            countMatch++;
    }
    Assert.assertEquals(2, countMatch);
    countMatch = 0;
    for (UeiMatch ueiMatch : factory.getUeiList()) {
        if (ueiMatch.getProcessMatch().isPresent() && ueiMatch.getProcessMatch().get().getExpression().startsWith("agalue"))
            countMatch++;
    }
    Assert.assertEquals(8, countMatch);
}
Also used : HideMatch(org.opennms.netmgt.config.syslogd.HideMatch) UeiMatch(org.opennms.netmgt.config.syslogd.UeiMatch) Test(org.junit.Test)

Aggregations

UeiMatch (org.opennms.netmgt.config.syslogd.UeiMatch)4 Test (org.junit.Test)2 HideMatch (org.opennms.netmgt.config.syslogd.HideMatch)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 File (java.io.File)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 SyslogdConfigFactory (org.opennms.netmgt.config.SyslogdConfigFactory)1 ProcessMatch (org.opennms.netmgt.config.syslogd.ProcessMatch)1 SyslogdConfigurationGroup (org.opennms.netmgt.config.syslogd.SyslogdConfigurationGroup)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1