Search in sources :

Example 1 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 2 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 3 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 4 with DatacollectionConfig

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

the class ConvertOldDataCollectionToNewDataCollectionTest method testImportEmpty.

@Test
public void testImportEmpty() {
    final String old = "<datacollection-config rrdRepository=\"${install.share.dir}/rrd/snmp/\">\n" + "  <snmp-collection name=\"default\" snmpStorageFlag=\"select\">\n" + "    <rrd step=\"300\">\n" + "      <rra>RRA:AVERAGE:0.5:1:2016</rra>\n" + "      <rra>RRA:AVERAGE:0.5:12:1488</rra>\n" + "      <rra>RRA:AVERAGE:0.5:288:366</rra>\n" + "      <rra>RRA:MAX:0.5:288:366</rra>\n" + "      <rra>RRA:MIN:0.5:288:366</rra>\n" + "    </rrd>\n" + "  </snmp-collection>\n" + "</datacollection-config>";
    final String expected = "<datacollection-config>\n" + "    <snmp-collection name=\"default\">\n" + "        <datacollection-group name=\"default-all\">\n" + "            <resourceType name=\"ifIndex\" label=\"Interfaces (MIB-2 ifTable)\">\n" + "                <resourceName><template>${ifDescr}-${ifPhysAddr}</template></resourceName>\n" + "                <resourceLabel><template>${ifDescr}-${ifPhysAddr}</template></resourceLabel>\n" + "                <resourceKind><template>${ifType}</template></resourceKind>\n" + "                <column oid=\".1.3.6.1.2.1.2.2.1.2\"    alias=\"ifDescr\"    type=\"string\" />\n" + "                <column oid=\".1.3.6.1.2.1.2.2.1.6\"    alias=\"ifPhysAddr\" type=\"string\"  display-hint=\"1x:\"/>\n" + "                <column oid=\".1.3.6.1.2.1.2.2.1.3\"    alias=\"ifType\"     type=\"string\" /> \n" + "                <column oid=\".1.3.6.1.2.1.31.1.1.1.1\" alias=\"ifName\"     type=\"string\" />\n" + "            </resourceType>\n" + "        </datacollection-group>\n" + "    </snmp-collection>\n" + "</datacollection-config>";
    final DatacollectionConfig oldConfig = JaxbUtils.unmarshal(DatacollectionConfig.class, old);
    final DataCollectionConfigImpl expectedNewConfig = JaxbUtils.unmarshal(DataCollectionConfigImpl.class, expected);
    final DataCollectionConfigConverter generator = new DataCollectionConfigConverter();
    oldConfig.visit(generator);
    final DataCollectionConfigImpl actualNewConfig = generator.getDataCollectionConfig();
    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 5 with DatacollectionConfig

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

the class DataCollectionConfigParserTest method testLoadWithOnlyExternalReferences.

@Test
public void testLoadWithOnlyExternalReferences() throws Exception {
    // Create DatacollectionConfig
    Resource resource = new InputStreamResource(this.getClass().getResourceAsStream("datacollection-config-onlyimports.xml"));
    DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, resource, false);
    // Validate default datacollection content
    SnmpCollection collection = config.getSnmpCollections().get(0);
    Assert.assertEquals(3, collection.getIncludeCollections().size());
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertNull(collection.getSystems());
    Assert.assertNull(collection.getGroups());
    // Execute Parser
    executeParser(collection);
    // Validate SNMP Collection
    // Resource Types should live on a special collection
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertEquals(2, collection.getSystems().getSystemDefs().size());
    // Unused groups will be ignored
    Assert.assertEquals(6, collection.getGroups().getGroups().size());
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) FileSystemResource(org.springframework.core.io.FileSystemResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Aggregations

DatacollectionConfig (org.opennms.netmgt.config.datacollection.DatacollectionConfig)14 Test (org.junit.Test)9 SnmpCollection (org.opennms.netmgt.config.datacollection.SnmpCollection)9 FileSystemResource (org.springframework.core.io.FileSystemResource)7 InputStreamResource (org.springframework.core.io.InputStreamResource)6 Resource (org.springframework.core.io.Resource)6 File (java.io.File)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 JaxbUtils (org.opennms.core.xml.JaxbUtils)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