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