Search in sources :

Example 1 with HideMatch

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

the class SyslogdConfigFactoryIT method testHideTheseMessages.

@Test
public void testHideTheseMessages() {
    for (final HideMatch hide : m_factory.getHideMessages()) {
        boolean typeOk = (hide.getMatch().getType().equals("substr") || hide.getMatch().getType().equals("regex"));
        Assert.assertTrue(typeOk);
        if (hide.getMatch().getType().equals("substr")) {
            Assert.assertEquals("TESTHIDING", hide.getMatch().getExpression());
        } else if (hide.getMatch().getType().equals("regex")) {
            Assert.assertEquals("[Dd]ouble[Ss]ecret", hide.getMatch().getExpression());
        }
    }
}
Also used : HideMatch(org.opennms.netmgt.config.syslogd.HideMatch) Test(org.junit.Test)

Example 2 with HideMatch

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

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

HideMatch (org.opennms.netmgt.config.syslogd.HideMatch)3 Test (org.junit.Test)2 UeiMatch (org.opennms.netmgt.config.syslogd.UeiMatch)2 File (java.io.File)1 SyslogdConfigurationGroup (org.opennms.netmgt.config.syslogd.SyslogdConfigurationGroup)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1