use of org.opennms.netmgt.config.datacollection.Group in project opennms by OpenNMS.
the class JsmiMibParserTest method testNameCutter.
/**
* Test name cutter
*
* @throws Exception the exception
*/
@Test
public void testNameCutter() throws Exception {
if (parser.parseMib(new File(MIB_DIR, "Clavister-MIB.mib"))) {
DatacollectionGroup dcGroup = parser.getDataCollection();
Assert.assertNotNull(dcGroup);
System.out.println(JaxbUtils.marshal(dcGroup));
int count = 0;
for (final Group group : dcGroup.getGroups()) {
for (final MibObj mo : group.getMibObjs()) {
if (mo.getAlias().length() > 19) {
// Character restriction.
count++;
}
}
}
// Without the name-cutter the number will be 80.
Assert.assertEquals(0, count);
} else {
Assert.fail("The Clavister-MIB.mib file couldn't be parsed successfully.");
}
}
use of org.opennms.netmgt.config.datacollection.Group in project opennms by OpenNMS.
the class JsmiMibParser method getGroup.
/**
* Gets the group.
*
* @param data the data collection group object
* @param groupName the group name
* @param resourceType the resource type
* @return the group
*/
protected Group getGroup(DatacollectionGroup data, String groupName, String resourceType) {
for (Group group : data.getGroups()) {
if (group.getName().equals(groupName))
return group;
}
Group group = new Group();
group.setName(groupName);
group.setIfType(resourceType == null ? "ignore" : "all");
if (resourceType != null) {
ResourceType type = new ResourceType();
type.setName(resourceType);
type.setLabel(resourceType);
type.setResourceLabel("${index}");
// To avoid requires opennms-services
type.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy"));
type.setStorageStrategy(new StorageStrategy(IndexStorageStrategy.class.getName()));
data.addResourceType(type);
}
data.addGroup(group);
return group;
}
use of org.opennms.netmgt.config.datacollection.Group in project opennms by OpenNMS.
the class JsmiMibParserTest method testGenerateDataCollection.
/**
* Test generate data collection.
*
* @throws Exception the exception
*/
@Test
public void testGenerateDataCollection() throws Exception {
if (parser.parseMib(new File(MIB_DIR, "IF-MIB.txt"))) {
DatacollectionGroup dcGroup = parser.getDataCollection();
Assert.assertNotNull(dcGroup);
System.out.println(JaxbUtils.marshal(dcGroup));
Assert.assertEquals(5, dcGroup.getResourceTypes().size());
Assert.assertEquals(7, dcGroup.getGroups().size());
Group mibGroup = null;
for (Group g : dcGroup.getGroups()) {
if (g.getName().equals("ifTable"))
mibGroup = g;
}
Assert.assertNotNull(mibGroup);
Assert.assertEquals(22, mibGroup.getMibObjs().size());
for (MibObj mo : mibGroup.getMibObjs()) {
Assert.assertEquals("ifEntry", mo.getInstance());
Assert.assertTrue(mo.getOid().startsWith(".1.3.6.1.2.1.2.2.1"));
Assert.assertTrue(mo.getType().matches("^(?i)(counter|gauge|timeticks|integer|octetstring|string)?\\d*$"));
}
} else {
Assert.fail("The IF-MIB.txt file couldn't be parsed successfully.");
}
}
use of org.opennms.netmgt.config.datacollection.Group in project opennms by OpenNMS.
the class DataCollectionConfigFile method doVisit.
private void doVisit(Groups groups, DataCollectionVisitor visitor) {
for (Iterator<Group> it = groups.getGroups().iterator(); it.hasNext(); ) {
Group group = it.next();
doVisit(group, visitor);
}
}
use of org.opennms.netmgt.config.datacollection.Group in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDaoIT method compareContent.
private void compareContent(DatacollectionConfig refObj, DatacollectionConfig newObj) {
Set<String> resourceTypes = new HashSet<String>();
Set<String> systemDefs = new HashSet<String>();
Set<String> groups = new HashSet<String>();
for (SnmpCollection collection : refObj.getSnmpCollections()) {
for (SystemDef sd : collection.getSystems().getSystemDefs()) {
systemDefs.add(sd.getName());
for (String group : sd.getCollect().getIncludeGroups()) {
groups.add(group);
}
}
for (Group g : collection.getGroups().getGroups()) {
if (groups.contains(g.getName())) {
for (MibObj mo : g.getMibObjs()) {
String i = mo.getInstance();
if (!i.matches("\\d+") && !i.equals("ifIndex"))
resourceTypes.add(mo.getInstance());
}
}
}
}
for (SnmpCollection collection : newObj.getSnmpCollections()) {
for (Group g : collection.getGroups().getGroups()) {
for (MibObj mo : g.getMibObjs()) {
String i = mo.getInstance();
if (!i.matches("\\d+") && !i.equals("ifIndex"))
resourceTypes.remove(mo.getInstance());
}
}
for (SystemDef sd : collection.getSystems().getSystemDefs()) {
systemDefs.remove(sd.getName());
for (String group : sd.getCollect().getIncludeGroups()) {
groups.remove(group);
}
}
}
if (systemDefs.size() > 0) {
Assert.fail("There are un-configured system definitions on the new datacollection: " + systemDefs);
}
if (groups.size() > 0) {
Assert.fail("There are un-configured groups on the new datacollection: " + groups);
}
if (resourceTypes.size() > 0) {
Assert.fail("There are un-configured resourceTypes on the new datacollection: " + resourceTypes);
}
}
Aggregations