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);
}
}
}
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());
});
}
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);
}
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);
}
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());
}
Aggregations