Search in sources :

Example 6 with DatacollectionConfig

use of org.opennms.netmgt.config.datacollection.DatacollectionConfig in project opennms by OpenNMS.

the class DataCollectionConfigResource method getDataCollectionConfiguration.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public Response getDataCollectionConfiguration() throws ConfigurationResourceException {
    LOG.debug("getDatacollectionConfigurationForLocation()");
    @SuppressWarnings("unchecked") final AbstractJaxbConfigDao<DatacollectionConfig, DatacollectionConfig> dao = (AbstractJaxbConfigDao<DatacollectionConfig, DatacollectionConfig>) m_dataCollectionConfigDao;
    final DatacollectionConfig dcc = dao.getContainer().getObject();
    if (dcc == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    return Response.ok(dcc.toDataCollectionConfig()).build();
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) AbstractJaxbConfigDao(org.opennms.core.xml.AbstractJaxbConfigDao) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with DatacollectionConfig

use of org.opennms.netmgt.config.datacollection.DatacollectionConfig in project opennms by OpenNMS.

the class DataCollectionConfigMigrator17Offline method updateDataCollectionConfig.

/**
 * Update data collection configuration.
 *
 * @param snmpCollection the SNMP collection
 * @param dataCollectionGroup the data collection group
 * @throws OnmsUpgradeException the OpenNMS upgrade exception
 */
private void updateDataCollectionConfig(String snmpCollection, String dataCollectionGroup) throws OnmsUpgradeException {
    DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, sourceFile);
    if (config != null) {
        log("Adding datacollection-group %s to snmp-collection %s", dataCollectionGroup, snmpCollection);
        IncludeCollection ic = new IncludeCollection();
        ic.setDataCollectionGroup(dataCollectionGroup);
        config.getSnmpCollections().stream().filter(s -> s.getName().equals(snmpCollection)).findFirst().get().addIncludeCollection(ic);
        try {
            JaxbUtils.marshal(config, new FileWriter(sourceFile));
        } catch (IOException e) {
            throw new OnmsUpgradeException("Can't update " + sourceFile, e);
        }
    }
}
Also used : DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) Iterator(java.util.Iterator) Files(java.nio.file.Files) FileWriter(java.io.FileWriter) ConfigFileConstants(org.opennms.core.utils.ConfigFileConstants) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) HashMap(java.util.HashMap) FileUtils(org.apache.commons.io.FileUtils) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) File(java.io.File) AbstractOnmsUpgrade(org.opennms.upgrade.api.AbstractOnmsUpgrade) Matcher(java.util.regex.Matcher) Paths(java.nio.file.Paths) Map(java.util.Map) JaxbUtils(org.opennms.core.xml.JaxbUtils) IncludeCollection(org.opennms.netmgt.config.datacollection.IncludeCollection) Pattern(java.util.regex.Pattern) Path(java.nio.file.Path) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) IncludeCollection(org.opennms.netmgt.config.datacollection.IncludeCollection) FileWriter(java.io.FileWriter) IOException(java.io.IOException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException)

Example 8 with DatacollectionConfig

use of org.opennms.netmgt.config.datacollection.DatacollectionConfig in project opennms by OpenNMS.

the class DataCollectionConfigMigrator17OfflineTest method canFix.

/**
 * Can fix.
 *
 * @throws OnmsUpgradeException the OpenNMS upgrade exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void canFix() throws OnmsUpgradeException, IOException {
    DataCollectionConfigMigrator17Offline task = new DataCollectionConfigMigrator17Offline();
    task.preExecute();
    task.execute();
    task.postExecute();
    DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, new File(tempFolder.getRoot(), "etc/datacollection-config.xml"));
    Assert.assertNotNull(config);
    config.getSnmpCollections().forEach(s -> {
        Assert.assertTrue(s.getIncludeCollections().stream().filter(i -> i.getDataCollectionGroup().equals("SNMP-Informant")).findFirst().isPresent());
    });
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) Rule(org.junit.Rule) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) JaxbUtils(org.opennms.core.xml.JaxbUtils) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Assert(org.junit.Assert) File(java.io.File) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) File(java.io.File) Test(org.junit.Test)

Example 9 with DatacollectionConfig

use of org.opennms.netmgt.config.datacollection.DatacollectionConfig in project opennms by OpenNMS.

the class ConvertOldDataCollectionToNewDataCollectionTest method testOldOnefileDatacollectionConfig.

@Test
public void testOldOnefileDatacollectionConfig() throws Exception {
    final String oldXml = IOUtils.toString(getClass().getResource("old-datacollection-config-mib2.xml"));
    final DatacollectionConfig oldConfig = JaxbUtils.unmarshal(DatacollectionConfig.class, oldXml);
    assertNotNull(oldConfig);
    final String expectedXml = IOUtils.toString(getClass().getResource("new-datacollection-config-mib2.xml"));
    final DataCollectionConfigImpl expectedNewConfig = JaxbUtils.unmarshal(DataCollectionConfigImpl.class, expectedXml);
    final DataCollectionConfigConverter generator = new DataCollectionConfigConverter();
    oldConfig.visit(generator);
    final DataCollectionConfigImpl actualNewConfig = generator.getDataCollectionConfig();
    // final String newXml = JaxbUtils.marshal(actualNewConfig);
    // XmlTest.assertXmlEquals(expectedXml, newXml);
    XmlTest.assertDepthEquals(expectedNewConfig, actualNewConfig);
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) Test(org.junit.Test) XmlTest(org.opennms.core.test.xml.XmlTest)

Example 10 with DatacollectionConfig

use of org.opennms.netmgt.config.datacollection.DatacollectionConfig in project opennms by OpenNMS.

the class SnmpDataCollectionTest method verifySnmpCollectionIncludeOrder.

/**
 * Verify that the order of the includes in the default 'datacollection-config.xml'
 * file are listed in alphabetical order, with the exception of MIB2 which should
 * always come first.
 *
 * See https://issues.opennms.org/browse/NMS-9643
 */
@Test
public void verifySnmpCollectionIncludeOrder() {
    final DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, new FileSystemResource(ConfigurationTestUtils.getFileForConfigFile("datacollection-config.xml")));
    final SnmpCollection snmpCollection = config.getSnmpCollection("default");
    assertNotNull("'default' snmp-collection should exist.", snmpCollection);
    // Current order
    final List<String> includesInOrderSpecified = snmpCollection.getIncludeCollections().stream().map(inc -> inc.getDataCollectionGroup().toLowerCase()).collect(Collectors.toList());
    // Exepected order
    final List<String> includesInNaturalOrder = snmpCollection.getIncludeCollections().stream().map(inc -> inc.getDataCollectionGroup().toLowerCase()).sorted(Comparator.naturalOrder()).collect(Collectors.toList());
    // Special handling for the "MIB2" include, if present
    if (includesInOrderSpecified.indexOf("mib2") == 0) {
        includesInNaturalOrder.remove("mib2");
        includesInNaturalOrder.add(0, "mib2");
    }
    assertEquals("One or more SNMP data collections included in the default configuration are not listed in alphabetical order." + " Please sort and try again.", includesInNaturalOrder, includesInOrderSpecified);
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) List(java.util.List) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) ConfigurationTestUtils(org.opennms.core.test.ConfigurationTestUtils) JaxbUtils(org.opennms.core.xml.JaxbUtils) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test) Comparator(java.util.Comparator) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test)

Aggregations

DatacollectionConfig (org.opennms.netmgt.config.datacollection.DatacollectionConfig)15 Test (org.junit.Test)10 SnmpCollection (org.opennms.netmgt.config.datacollection.SnmpCollection)10 FileSystemResource (org.springframework.core.io.FileSystemResource)8 InputStreamResource (org.springframework.core.io.InputStreamResource)6 Resource (org.springframework.core.io.Resource)6 File (java.io.File)3 JaxbUtils (org.opennms.core.xml.JaxbUtils)3 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 FileUtils (org.apache.commons.io.FileUtils)2 XmlTest (org.opennms.core.test.xml.XmlTest)2 DatacollectionGroup (org.opennms.netmgt.config.datacollection.DatacollectionGroup)2 OnmsUpgradeException (org.opennms.upgrade.api.OnmsUpgradeException)2 CommitException (com.vaadin.data.fieldgroup.FieldGroup.CommitException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1