use of org.opennms.netmgt.config.datacollection.SystemDef in project opennms by OpenNMS.
the class DataCollectionConfigParserTest method testsForNMS8030.
@Test
public void testsForNMS8030() throws Exception {
File home = new File("src/test/resources/NMS8030");
Assert.assertTrue(home.exists());
File configFile = new File(home, "etc/datacollection-config.xml");
DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
dao.setConfigResource(new FileSystemResource(configFile));
dao.setConfigDirectory(new File(home, "etc/datacollection").getAbsolutePath());
dao.setReloadCheckInterval(0l);
dao.afterPropertiesSet();
// Use case 1
Optional<SystemDef> systemDef = dao.getRootDataCollection().getSnmpCollections().stream().filter(sc -> sc.getName().equals("sample1")).flatMap(sc -> sc.getSystems().getSystemDefs().stream()).filter(s -> s.getName().equals("Cisco Routers")).findFirst();
Assert.assertTrue(systemDef.isPresent());
Assert.assertEquals(5, systemDef.get().getCollect().getIncludeGroups().size());
// Use Case 2
Optional<Group> group = dao.getRootDataCollection().getSnmpCollections().stream().filter(sc -> sc.getName().equals("sample2")).flatMap(sc -> sc.getGroups().getGroups().stream()).filter(s -> s.getName().equals("cisco-memory-pool")).findFirst();
Assert.assertTrue(group.isPresent());
Assert.assertEquals(3, group.get().getMibObjs().size());
// Use case 3
systemDef = dao.getRootDataCollection().getSnmpCollections().stream().filter(sc -> sc.getName().equals("sample2")).flatMap(sc -> sc.getSystems().getSystemDefs().stream()).filter(s -> s.getName().equals("Cisco Routers")).findFirst();
Assert.assertTrue(systemDef.isPresent());
Assert.assertEquals(5, systemDef.get().getCollect().getIncludeGroups().size());
// Use Case 4
group = dao.getRootDataCollection().getSnmpCollections().stream().filter(sc -> sc.getName().equals("sample2")).flatMap(sc -> sc.getGroups().getGroups().stream()).filter(s -> s.getName().equals("cisco-memory-pool")).findFirst();
Assert.assertTrue(group.isPresent());
Assert.assertEquals(3, group.get().getMibObjs().size());
}
use of org.opennms.netmgt.config.datacollection.SystemDef in project opennms by OpenNMS.
the class DataCollectionConfigParser method parseCollection.
/**
* Update/Validate SNMP collection.
*
* @param collection
*/
public void parseCollection(SnmpCollection collection) {
if (collection.getIncludeCollections().size() > 0) {
parseExternalResources();
checkCollection(collection);
// Add systemDefs and dependencies
for (IncludeCollection include : collection.getIncludeCollections()) {
if (include.getDataCollectionGroup() != null) {
// Include All system definitions from a specific datacollection group
addDatacollectionGroup(collection, include.getDataCollectionGroup(), include.getExcludeFilters());
} else {
if (include.getSystemDef() == null) {
throwException("You must specify at least the data collection group name or system definition name for the include-collection attribute", null);
} else {
// Include One system definition
SystemDef systemDef = getSystemDef(include.getSystemDef());
if (systemDef == null) {
throwException("Can't find system definition " + include.getSystemDef(), null);
}
addSystemDef(collection, systemDef, null);
}
}
}
} else {
LOG.info("parse: SNMP collection {} doesn't have any external reference.", collection.getName());
}
}
use of org.opennms.netmgt.config.datacollection.SystemDef in project opennms by OpenNMS.
the class DataCollectionConfigParser method addDatacollectionGroup.
/**
* Add all system definitions defined on a specific data collection group, into a SNMP collection.
*
* @param collection the target SNMP collection object.
* @param dataCollectionGroupName the data collection group name.
* @param excludeList the list of regular expression to exclude certain system definitions.
*/
private void addDatacollectionGroup(SnmpCollection collection, String dataCollectionGroupName, List<String> excludeList) {
DatacollectionGroup group = externalGroupsMap.get(dataCollectionGroupName);
if (group == null) {
throwException("Group " + dataCollectionGroupName + " does not exist.", null);
}
LOG.debug("addDatacollectionGroup: adding all definitions from group {} to snmp-collection {}", group.getName(), collection.getName());
for (SystemDef systemDef : group.getSystemDefs()) {
if (shouldAdd(systemDef.getName(), excludeList)) {
addSystemDef(collection, systemDef, group.getName());
}
}
}
use of org.opennms.netmgt.config.datacollection.SystemDef in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDao method getMibObjProperties.
@Override
public List<MibObjProperty> getMibObjProperties(final String cName, final String aSysoid, final String anAddress) {
LOG.debug("getMibObjProperties: collection: {} sysoid: {} address: {}", cName, aSysoid, anAddress);
if (aSysoid == null) {
LOG.debug("getMibObjProperties: aSysoid parameter is NULL...");
return new ArrayList<>();
}
final SnmpCollection collection = getSnmpCollection(getContainer(), cName);
if (collection == null) {
return Collections.emptyList();
}
final Systems systems = collection.getSystems();
if (systems == null) {
return Collections.emptyList();
}
final List<SystemDef> systemList = new ArrayList<>();
for (final SystemDef system : systems.getSystemDefs()) {
if (systemDefMatches(system, aSysoid, anAddress)) {
systemList.add(system);
}
}
final List<MibObjProperty> mibProperties = new ArrayList<>();
for (final SystemDef system : systemList) {
for (final String grpName : system.getCollect().getIncludeGroups()) {
processGroupForProperties(cName, grpName, mibProperties);
}
}
return mibProperties;
}
Aggregations