use of org.opennms.netmgt.config.datacollection.SnmpCollection 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);
}
use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.
the class DataCollectionConfigParserTest method testPrecedence.
@Test
public void testPrecedence() throws Exception {
// Create DatacollectionConfig
Resource resource = new InputStreamResource(this.getClass().getResourceAsStream("datacollection-config-hybrid-precedence.xml"));
DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, resource, false);
// Validate default datacollection content
SnmpCollection collection = config.getSnmpCollections().get(0);
Assert.assertEquals(1, collection.getIncludeCollections().size());
Assert.assertEquals(0, collection.getResourceTypes().size());
Assert.assertEquals(1, collection.getSystems().getSystemDefs().size());
Assert.assertEquals(1, collection.getGroups().getGroups().size());
// Execute Parser
executeParser(collection);
// Validate SNMP Collection
// Resource Types should live on a special collection
Assert.assertEquals(0, collection.getResourceTypes().size());
Assert.assertEquals(71, collection.getSystems().getSystemDefs().size());
Assert.assertEquals(14, collection.getGroups().getGroups().size());
// This is a way to "override" the content of a specific datacollection-group.
for (Group group : collection.getGroups().getGroups()) {
if (group.getName().equals("cisco-frame-relay")) {
Assert.assertEquals(4, group.getMibObjs().size());
}
}
for (SystemDef systemDef : collection.getSystems().getSystemDefs()) {
if (systemDef.getName().equals("Cisco Routers")) {
Assert.assertEquals(3, systemDef.getCollect().getIncludeGroups().size());
}
}
}
use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.
the class DataCollectionConfigParserTest method testLoadWithEmptyConfig.
@Test
public void testLoadWithEmptyConfig() throws Exception {
// Create a SNMP collection
SnmpCollection collection = new SnmpCollection();
collection.setName("default");
// Validate default datacollection content
Assert.assertEquals(0, collection.getIncludeCollections().size());
Assert.assertEquals(0, collection.getResourceTypes().size());
Assert.assertNull(collection.getSystems());
Assert.assertNull(collection.getGroups());
// Execute Parser
final DataCollectionConfigParser parser = new DataCollectionConfigParser("target");
parser.parseCollection(collection);
// Validate SNMP Collection
Assert.assertEquals(0, collection.getResourceTypes().size());
Assert.assertNull(collection.getSystems());
Assert.assertNull(collection.getGroups());
}
use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDaoIT method executeSystemDefCount.
private void executeSystemDefCount(DefaultDataCollectionConfigDao dao, int expectedCount) {
DatacollectionConfig config = dao.getContainer().getObject();
int systemDefCount = 0;
for (SnmpCollection collection : config.getSnmpCollections()) {
systemDefCount += collection.getSystems().getSystemDefs().size();
}
Assert.assertEquals(expectedCount, systemDefCount);
}
use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.
the class DataCollectionConfigFile method visit.
/**
* <p>visit</p>
*
* @param visitor a {@link org.opennms.netmgt.dao.jaxb.collector.DataCollectionVisitor} object.
*/
public void visit(DataCollectionVisitor visitor) {
DatacollectionConfig dataCollectionConfig = getDataCollectionConfig();
visitor.visitDataCollectionConfig(dataCollectionConfig);
for (Iterator<SnmpCollection> it = dataCollectionConfig.getSnmpCollections().iterator(); it.hasNext(); ) {
SnmpCollection snmpCollection = it.next();
doVisit(snmpCollection, visitor);
}
visitor.completeDataCollectionConfig(dataCollectionConfig);
}
Aggregations