use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDao method processObjectList.
/**
* Takes a list of MibObj objects iterates over them
* creating corresponding MibObject objects and adding them to the supplied
* MibObject list.
* @param groupName TODO
* @param groupIfType TODO
* @param objectList
* List of MibObject objects parsed from
* 'datacollection-config.xml'
* @param mibObjectList
* List of MibObject objects currently being built
*/
private void processObjectList(final String groupName, final String groupIfType, final List<MibObj> objectList, final List<MibObject> mibObjectList) {
for (final MibObj mibObj : objectList) {
// Create a MibObject from the XML MibObj
final MibObject aMibObject = new MibObject();
aMibObject.setGroupName(groupName);
aMibObject.setGroupIfType(groupIfType);
aMibObject.setOid(mibObj.getOid());
aMibObject.setAlias(mibObj.getAlias());
aMibObject.setType(mibObj.getType());
aMibObject.setInstance(mibObj.getInstance());
aMibObject.setMaxval(mibObj.getMaxval());
aMibObject.setMinval(mibObj.getMinval());
final ResourceType resourceType = getConfiguredResourceTypes().get(mibObj.getInstance());
if (resourceType != null) {
aMibObject.setResourceType(resourceType);
}
// Add the MIB object provided it isn't already in the list
if (!mibObjectList.contains(aMibObject)) {
mibObjectList.add(aMibObject);
}
}
}
use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.
the class ThresholdingVisitorIT method runCounterWrapTest.
/*
* Parameter expectedValue should be around 200:
* Initial counter value is 20000 below limit.
* Next value is 40000, so the difference will be 60000.
* Counters are treated as rates so 60000/300 is 200.
*/
private void runCounterWrapTest(double bits, double expectedValue) throws Exception {
Integer ifIndex = 1;
Long ifSpeed = 10000000l;
String ifName = "wlan0";
initFactories("/threshd-configuration.xml", "/test-thresholds-bug3194.xml");
addHighThresholdEvent(1, 100, 90, expectedValue, ifName, "1", "ifOutOctets", ifName, ifIndex.toString());
ThresholdingVisitor visitor = createVisitor();
// Creating Interface Resource Type
SnmpIfData ifData = createSnmpIfData("127.0.0.1", ifName, ifSpeed, ifIndex, true);
SnmpCollectionAgent agent = createCollectionAgent();
IfResourceType resourceType = createInterfaceResourceType(agent);
// Creating Data Source
MibObject object = createMibObject("counter", "ifOutOctets", "ifIndex");
SnmpAttributeType objectType = new NumericAttributeType(resourceType, "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
long timestamp = new Date().getTime();
// Step 1 - Initialize Counter
visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp));
BigDecimal n = new BigDecimal(Math.pow(2, bits) - 20000);
SnmpValue snmpValue1 = SnmpUtils.getValueFactory().getCounter64(n.toBigInteger());
SnmpCollectionResource resource1 = new IfInfo(resourceType, agent, ifData);
resource1.setAttributeValue(objectType, snmpValue1);
resource1.visit(visitor);
// Step 2 - Wrap Counter
visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp + 300000));
SnmpValue snmpValue2 = SnmpUtils.getValueFactory().getCounter64(new BigInteger("40000"));
SnmpCollectionResource resource2 = new IfInfo(resourceType, agent, ifData);
resource2.setAttributeValue(objectType, snmpValue2);
resource2.visit(visitor);
// Verify Events
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.
the class ThresholdingVisitorIT method addAttributeToCollectionResource.
private static void addAttributeToCollectionResource(SnmpCollectionResource resource, ResourceType type, String attributeName, String attributeType, String attributeInstance, long value) {
MibObject object = createMibObject(attributeType, attributeName, attributeInstance);
SnmpAttributeType objectType = new NumericAttributeType(type, "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
SnmpValue snmpValue = attributeType.equals("counter") ? SnmpUtils.getValueFactory().getCounter32(value) : SnmpUtils.getValueFactory().getGauge32(value);
resource.setAttributeValue(objectType, snmpValue);
}
use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.
the class DataCollectionConfigFactoryTest method testSetInstance.
@Test
public void testSetInstance() throws IOException {
initDataCollectionFactory(m_xml);
assertEquals(m_rrdRepository.getAbsolutePath(), DataCollectionConfigFactory.getInstance().getRrdPath());
assertEquals(0, DataCollectionConfigFactory.getInstance().getMibObjectList("default", ".1.9.9.9.9", "127.0.0.1", 0).size());
for (MibObject object : DataCollectionConfigFactory.getInstance().getMibObjectList("default", ".1.3.6.1.4.1.200", "127.0.0.1", 0)) {
assertEquals("Invalid MibObject: " + object, "ifIndex", object.getInstance());
}
assertArrayEquals(new String[0], DataCollectionConfigFactory.getInstance().getConfiguredResourceTypes().keySet().toArray(new String[0]));
}
use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.
the class DataCollectionConfigFactoryTest method testValidResourceType.
@Test
public void testValidResourceType() throws IOException {
String modifiedXml = m_xml.replaceFirst("ifIndex", "brocadeIndex").replaceFirst("<groups", m_brocadeXmlFragment + "<groups");
initDataCollectionFactory(modifiedXml);
assertEquals(m_rrdRepository.getAbsolutePath(), DataCollectionConfigFactory.getInstance().getRrdPath());
assertEquals(0, DataCollectionConfigFactory.getInstance().getMibObjectList("default", ".1.9.9.9.9", "127.0.0.1", 0).size());
List<MibObject> mibObjects = DataCollectionConfigFactory.getInstance().getMibObjectList("default", ".1.3.6.1.4.1.200", "127.0.0.1", 0);
// Make sure that the first value was edited as intended
MibObject first = mibObjects.remove(0);
assertEquals("Invalid MibObject: " + first, "brocadeIndex", first.getInstance());
for (MibObject object : mibObjects) {
assertEquals("Invalid MibObject: " + object, "ifIndex", object.getInstance());
}
assertArrayEquals(new String[] { "brocadeIndex" }, DataCollectionConfigFactory.getInstance().getConfiguredResourceTypes().keySet().toArray(new String[0]));
}
Aggregations