use of org.opennms.netmgt.collectd.NumericAttributeType in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testBug2746.
/*
* This bug has not been replicated, but this code covers the apparent scenario, and can be adapted to match
* any scenario which can actually replicate the reported issue
*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds-bug2746.xml
*/
@Test
public void testBug2746() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-bug2746.xml");
ThresholdingVisitor visitor = createVisitor();
SnmpCollectionAgent agent = createCollectionAgent();
NodeResourceType resourceType = createNodeResourceType(agent);
MibObject mibObject = createMibObject("gauge", "bug2746", "0");
SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "default", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
// Add Events
addHighThresholdEvent(1, 50, 40, 60, "node", "node", "bug2746", null, null);
// Step 1 : Execute visitor
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(20));
resource.visit(visitor);
// Step 2 : Repeat a couple of times with the same value, to replicate a steady state
resource.visit(visitor);
resource.visit(visitor);
resource.visit(visitor);
// Step 3 : Trigger
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(60));
resource.visit(visitor);
// Step 4 : Don't rearm, but do drop
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(45));
resource.visit(visitor);
// Step 5 : Shouldn't trigger again
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(55));
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.collectd.NumericAttributeType in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testResourceCounterData.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds.xml
*
* Updated to reflect the fact that counter are treated as rates (counter wrap is not checked here anymore).
*/
@Test
public void testResourceCounterData() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-counters.xml");
ThresholdingVisitor visitor = createVisitor();
SnmpCollectionAgent agent = createCollectionAgent();
NodeResourceType resourceType = createNodeResourceType(agent);
MibObject mibObject = createMibObject("counter", "myCounter", "0");
SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "default", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
// Add Events
addHighThresholdEvent(1, 10, 5, 15, "node", "node", "myCounter", null, null);
addHighRearmEvent(1, 10, 5, 2, "node", "node", "myCounter", null, null);
long baseDate = new Date().getTime();
// Step 0: Visit a CollectionSet with a timestamp, so that the thresholder knows how when the collection was held
// Normally visiting the CollectionSet would end up visiting the resources, but we're fudging that for the test
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
// Collect Step 1 : Initialize counter cache.
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(1000));
resource.visit(visitor);
// Collect Step 2 : Trigger. (last-current)/step => (5500-1000)/300=15
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 300000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500));
resource.visit(visitor);
// Collect Step 3 : Rearm. (last-current)/step => (6100-5500)/300=2
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 600000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(6100));
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.collectd.NumericAttributeType in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testZeroIntervalResourceCounterData.
@Test
public void testZeroIntervalResourceCounterData() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-counters.xml");
ThresholdingVisitor visitor = createVisitor();
SnmpCollectionAgent agent = createCollectionAgent();
NodeResourceType resourceType = createNodeResourceType(agent);
MibObject mibObject = createMibObject("counter", "myCounter", "0");
SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "default", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
// Add Events
addHighThresholdEvent(1, 10, 5, 15, "node", "node", "myCounter", null, null);
addHighRearmEvent(1, 10, 5, 2, "node", "node", "myCounter", null, null);
long baseDate = new Date().getTime();
// Step 0: Visit a CollectionSet with a timestamp, so that the thresholder knows how when the collection was held
// Normally visiting the CollectionSet would end up visiting the resources, but we're fudging that for the test
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
// Collect Step 1 : Initialize counter cache.
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(1000));
resource.visit(visitor);
// Collect Step 1.5 : Send a new data point with the same timestamp as before and a
// different value. This should not trigger a threshold violation because the time
// interval is zero. It should also not reset the cached value for the attribute
// because the time interval is zero.
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500));
resource.visit(visitor);
// Collect Step 2 : Trigger. (last-current)/step => (5500-1000)/300=15
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 300000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500));
resource.visit(visitor);
// Collect Step 3 : Rearm. (last-current)/step => (6100-5500)/300=2
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 600000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(6100));
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.collectd.NumericAttributeType in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testBug3193.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds-bug3193.xml
*
* Updated to reflect the fact that counter are treated as rates.
*/
@Test
public void testBug3193() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-bug3193.xml");
ThresholdingVisitor visitor = createVisitor();
SnmpCollectionAgent agent = createCollectionAgent();
NodeResourceType resourceType = createNodeResourceType(agent);
MibObject mibObject = createMibObject("counter", "myCounter", "0");
SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "default", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
// Add Events
addHighThresholdEvent(1, 100, 90, 110, "node", "node", "myCounter", null, null);
addHighThresholdEvent(1, 70, 60, 80, "node", "node", "myCounter - 30", null, null);
addHighRearmEvent(1, 100, 90, 40, "node", "node", "myCounter", null, null);
addHighRearmEvent(1, 70, 60, 10, "node", "node", "myCounter - 30", null, null);
long baseDate = new Date().getTime();
// Collect Step 1 : First Data: Last should be NaN
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(2000));
resource.visit(visitor);
// Collect Step 2 : First Value: (last-current)/step => (20000-2000)/300=60
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 300000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(20000));
resource.visit(visitor);
// Collect Step 3 : Second Value: (last-current)/step => (53000-20000)/300=110 => Trigger
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 600000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(53000));
resource.visit(visitor);
// Collect Step 3 : Third Value (last-current)/step => (65000-53000)/300=40 => Rearm
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 900000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(65000));
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.collectd.NumericAttributeType 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);
}
Aggregations