use of org.opennms.netmgt.collectd.SnmpIfData 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.collectd.SnmpIfData in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testBug3664.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds-bug3664.xml
*
* Updated to reflect the fact that counter are treated as rates.
*/
@Test
public void testBug3664() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-bug3664.xml");
Integer ifIndex = 1;
Long ifSpeed = 10000000l;
String ifName = "wlan0";
String domain = "myDomain";
String ifAlias = ifName;
String ifAliasComment = "#";
String label = domain + "/" + ifAlias;
addHighThresholdEvent(1, 90, 50, 120, label, "Unknown", "ifOutOctets", label, ifIndex.toString());
addHighThresholdEvent(1, 90, 50, 120, label, "Unknown", "ifInOctets", label, ifIndex.toString());
Map<String, Object> params = new HashMap<String, Object>();
params.put("thresholding-enabled", "true");
params.put("storeByIfAlias", "true");
ThresholdingVisitor visitor = createVisitor(params);
SnmpIfData ifData = createSnmpIfData("127.0.0.1", ifName, ifSpeed, ifIndex, true);
SnmpCollectionAgent agent = createCollectionAgent();
IfResourceType resourceType = createInterfaceResourceType(agent);
long timestamp = new Date().getTime();
// Step 1
visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp));
IfInfo ifInfo = new IfInfo(resourceType, agent, ifData);
addAttributeToCollectionResource(ifInfo, resourceType, "ifInOctets", "counter", "ifIndex", 10000);
addAttributeToCollectionResource(ifInfo, resourceType, "ifOutOctets", "counter", "ifIndex", 10000);
AliasedResource resource = new AliasedResource(resourceType, domain, ifInfo, ifAliasComment, ifAlias);
resource.visit(visitor);
// Step 2 - Increment Counters
visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp + 300000));
ifInfo = new IfInfo(resourceType, agent, ifData);
addAttributeToCollectionResource(ifInfo, resourceType, "ifInOctets", "counter", "ifIndex", 46000);
addAttributeToCollectionResource(ifInfo, resourceType, "ifOutOctets", "counter", "ifIndex", 46000);
resource = new AliasedResource(resourceType, domain, ifInfo, ifAliasComment, ifAlias);
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
Aggregations