use of org.opennms.netmgt.config.datacollection.MibObj in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDao method validateResourceTypes.
private void validateResourceTypes(final Collection<SnmpCollection> snmpCollections, final Set<String> allowedResourceTypes) {
final String configuredString;
if (allowedResourceTypes.size() == 0) {
configuredString = "(none)";
} else {
configuredString = StringUtils.join(allowedResourceTypes, ", ");
}
final String allowableValues = "any positive number, 'ifIndex', or any of the configured resourceTypes: " + configuredString;
for (final SnmpCollection collection : snmpCollections) {
final Groups groups = collection.getGroups();
if (groups != null) {
for (final Group group : groups.getGroups()) {
for (final MibObj mibObj : group.getMibObjs()) {
final String instance = mibObj.getInstance();
if (instance == null)
continue;
if (MibObject.INSTANCE_IFINDEX.equals(instance))
continue;
if (allowedResourceTypes.contains(instance))
continue;
try {
// Check to see if the value is a non-negative integer
if (Integer.parseInt(instance.trim()) >= 0) {
continue;
}
} catch (NumberFormatException e) {
}
// XXX this should be a better exception
throw new IllegalArgumentException("instance '" + instance + "' invalid in mibObj definition for OID '" + mibObj.getOid() + "' in collection '" + collection.getName() + "' for group '" + group.getName() + "'. Allowable instance values: " + allowableValues);
}
}
}
}
}
use of org.opennms.netmgt.config.datacollection.MibObj in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDaoIT method compareContent.
private void compareContent(DatacollectionConfig refObj, DatacollectionConfig newObj) {
Set<String> resourceTypes = new HashSet<>();
Set<String> systemDefs = new HashSet<>();
Set<String> groups = new HashSet<>();
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);
}
}
use of org.opennms.netmgt.config.datacollection.MibObj 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.MibObj 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.MibObj in project opennms by OpenNMS.
the class MibObjField method addHandler.
/**
* Adds the handler.
*/
private void addHandler() {
MibObj obj = new MibObj();
obj.setOid(".1.1.1.1");
obj.setInstance("0");
obj.setType("gauge");
obj.setAlias("test");
table.select(container.addOnmsBean(obj));
}
Aggregations