use of org.opennms.netmgt.config.datacollection.Group in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDao method processGroupForProperties.
private void processGroupForProperties(final String cName, final String groupName, final List<MibObjProperty> mibObjProperties) {
final Map<String, Group> groupMap = getCollectionGroupMap(getContainer()).get(cName);
final Group group = groupMap.get(groupName);
if (group == null) {
LOG.warn("processGroupForProperties: unable to retrieve group information for group name '{}': check DataCollection.xml file.", groupName);
return;
}
for (final String includeGroup : group.getIncludeGroups()) {
processGroupForProperties(cName, includeGroup, mibObjProperties);
}
// Set the group at run time.
group.getProperties().forEach(p -> p.setGroupName(groupName));
mibObjProperties.addAll(group.getProperties());
}
use of org.opennms.netmgt.config.datacollection.Group in project opennms by OpenNMS.
the class JsmiMibParser method getDataCollection.
/* (non-Javadoc)
* @see org.opennms.features.vaadin.mibcompiler.api.MibParser#getDataCollection()
*/
@Override
public DatacollectionGroup getDataCollection() {
if (module == null) {
return null;
}
LOG.info("Generating data collection configuration for {}", module.getId());
DatacollectionGroup dcGroup = new DatacollectionGroup();
dcGroup.setName(module.getId());
NameCutter cutter = new NameCutter();
try {
for (SmiVariable v : module.getVariables()) {
String groupName = getGroupName(v);
String resourceType = getResourceType(v);
Group group = getGroup(dcGroup, groupName, resourceType);
// FIXME what if it is not a primitive type, like in ENTITY-SENSOR-MIB ?
String typeName = getMetricType(v.getType().getPrimitiveType());
if (typeName != null) {
// RRDtool/JRobin DS size restriction.
String alias = cutter.trimByCamelCase(v.getId(), 19);
MibObj mibObj = new MibObj();
mibObj.setOid('.' + v.getOidStr());
mibObj.setInstance(resourceType == null ? "0" : resourceType);
mibObj.setAlias(alias);
mibObj.setType(typeName);
group.addMibObj(mibObj);
if (typeName.equals("string") && resourceType != null) {
for (ResourceType rs : dcGroup.getResourceTypes()) {
if (rs.getName().equals(resourceType) && rs.getResourceLabel().equals("${index}")) {
rs.setResourceLabel("${" + v.getId() + "} (${index})");
}
}
}
}
}
} catch (Throwable e) {
String errors = e.getMessage();
if (errors == null || errors.trim().equals(""))
errors = "An unknown error accured when generating data collection objects from the MIB " + module.getId();
LOG.error("Data Collection parsing error: {}", errors, e);
errorHandler.addError(errors);
return null;
}
return dcGroup;
}
use of org.opennms.netmgt.config.datacollection.Group 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.Group 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());
}
Aggregations