use of org.opennms.netmgt.collectd.SnmpCollectionAgent in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method testGetCounterValueWithGap.
/**
* Per bug report NMS-4244, multiple calls to the getCounter functionality on CollectionResourceWrapper used to pay
* no mind of the actual time when samples were collected, instead assuming that it was the collection interval ago.
* When a collection cycle fails (entirely or partly) and thresholded values weren't available, the counter value
* was incorrectly calculated on the next succeeding cycle (taking the difference from the last successful
* collection and dividing by just a single collection interval.
*/
@Test
public void testGetCounterValueWithGap() throws Exception {
// we get a warning on the first getAttributeValue()
m_ignoreWarnings = true;
SnmpCollectionAgent agent = createCollectionAgent();
SnmpCollectionResource resource = createNodeResource(agent);
// Add Counter Attribute
String attributeName = "myCounter";
String attributeId = "node[1].resourceType[node].instance[null].metric[" + attributeName + "]";
Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
SnmpAttribute attribute = addAttributeToCollectionResource(resource, attributeName, AttributeType.COUNTER, "0", "1000");
attributes.put(attribute.getName(), attribute);
// We manipulate the Date objects passed to the
// CollectionResourceWrapper to simulate various collection intervals
Date baseDate = new Date();
// Get counter value - first time
CollectionResourceWrapper wrapper = createWrapper(resource, attributes, baseDate);
Assert.assertFalse(CollectionResourceWrapper.s_cache.containsKey(attributeId));
Assert.assertEquals(Double.valueOf(Double.NaN), // Last value is null
wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(Double.NaN), // Last value is null
wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(1000.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
// Increase counter
attribute = addAttributeToCollectionResource(resource, attributeName, AttributeType.COUNTER, "0", "2500");
attributes.put(attribute.getName(), attribute);
//Next wrapper is told the data was collected 5 minutes in the future (300 seconds)
wrapper = createWrapper(resource, attributes, new Date(baseDate.getTime() + 300000));
// Get counter value - second time
// Last value is 1000.0, so 2500-1000/300 = 1500/300 = 5.
Assert.assertEquals(Double.valueOf(1000.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
Assert.assertEquals(Double.valueOf(5.0), wrapper.getAttributeValue(attributeName));
//Validate that the cached counter value has been updated
Assert.assertEquals(Double.valueOf(2500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
//but that calling getAttributeValue doesn't re-calculate the rate inappropriately or update the static cache
Assert.assertEquals(Double.valueOf(5.0), wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(2500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
// Now create a collection that is missing the counter value; we're
// expecting null result and no cache updates
attributes = new HashMap<String, CollectionAttribute>();
attribute = addAttributeToCollectionResource(resource, "notMyCounter", AttributeType.COUNTER, "0", // We want a value, just not one called "myCounter"
"1000");
attributes.put(attribute.getName(), attribute);
// Next collection is 10 minutes (600 seconds) after the first.
wrapper = createWrapper(resource, attributes, new Date(baseDate.getTime() + 600000));
// No change, so we expect the cache to have (and continue to) remain
// the same, and to get no attribute value out
Assert.assertEquals(Double.valueOf(2500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
Assert.assertNull(wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(2500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
// Now if we collect successfully again, we expect the counter to be the
// change divided by two collection cycles
attributes = new HashMap<String, CollectionAttribute>();
attribute = addAttributeToCollectionResource(resource, attributeName, AttributeType.COUNTER, "0", "7300");
attributes.put(attribute.getName(), attribute);
// Next collection is 15 minutes (900 seconds) after the first.
wrapper = createWrapper(resource, attributes, new Date(baseDate.getTime() + 900000));
// Get counter value - fourth time
// Last value is 5500, but we've had two collection cycles, so
// 7300-2500/600 = 4800/600 = 8
Assert.assertEquals(Double.valueOf(2500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
Assert.assertEquals(Double.valueOf(8.0), wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(7300.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
Assert.assertEquals(Double.valueOf(8.0), wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(7300.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
Assert.assertEquals(Double.valueOf(8.0), wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(7300.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
EasyMock.verify(agent);
}
use of org.opennms.netmgt.collectd.SnmpCollectionAgent in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method testGetCounterValue.
@Test
public void testGetCounterValue() throws Exception {
// Create Resource
SnmpCollectionAgent agent = createCollectionAgent();
SnmpCollectionResource resource = createNodeResource(agent);
// Add Counter Attribute
String attributeName = "myCounter";
String attributeId = "node[1].resourceType[node].instance[null].metric[" + attributeName + "]";
Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
SnmpAttribute attribute = addAttributeToCollectionResource(resource, attributeName, AttributeType.COUNTER, "0", "1000");
attributes.put(attribute.getName(), attribute);
//We manipulate the Date objects passed to the CollectionResourceWrapper to simulate various collection intervals
Date baseDate = new Date();
// Get counter value - first time
CollectionResourceWrapper wrapper = createWrapper(resource, attributes, baseDate);
Assert.assertFalse(CollectionResourceWrapper.s_cache.containsKey(attributeId));
// Last value is null
Assert.assertEquals(Double.valueOf(Double.NaN), wrapper.getAttributeValue(attributeName));
// Last value is null
Assert.assertEquals(Double.valueOf(Double.NaN), wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(1000.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
// Increase counter
attribute = addAttributeToCollectionResource(resource, attributeName, AttributeType.COUNTER, "0", "2500");
attributes.put(attribute.getName(), attribute);
//Next wrapper is told the data was collected 5 minutes in the future (300 seconds)
wrapper = createWrapper(resource, attributes, new Date(baseDate.getTime() + 300000));
// Get counter value - second time
// Last value is 1000.0, so 2500-1000/300 = 1500/300 = 5.
Assert.assertEquals(Double.valueOf(1000.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
Assert.assertEquals(Double.valueOf(5.0), wrapper.getAttributeValue(attributeName));
//Validate that the cached counter value has been updated
Assert.assertEquals(Double.valueOf(2500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
//but that calling getAttributeValue doesn't re-calculate the rate inappropriately
Assert.assertEquals(Double.valueOf(5.0), wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(2500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
Assert.assertEquals(Double.valueOf(5.0), wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(2500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
// Increase counter
attribute = addAttributeToCollectionResource(resource, attributeName, AttributeType.COUNTER, "0", "5500");
attributes.put(attribute.getName(), attribute);
//Next wrapper is told the data was collected 10 minutes in the future (600 seconds), or after the first collection
wrapper = createWrapper(resource, attributes, new Date(baseDate.getTime() + 600000));
// Get counter value - third time
// Last value is 2500.0, so 5500-2500/300 = 3000/300 = 10;
Assert.assertEquals(Double.valueOf(2500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
Assert.assertEquals(Double.valueOf(10.0), wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(5500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
Assert.assertEquals(Double.valueOf(10.0), wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(5500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
Assert.assertEquals(Double.valueOf(10.0), wrapper.getAttributeValue(attributeName));
Assert.assertEquals(Double.valueOf(5500.0), CollectionResourceWrapper.s_cache.get(attributeId).getValue());
}
use of org.opennms.netmgt.collectd.SnmpCollectionAgent in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method testGetGaugeValue.
@Test
public void testGetGaugeValue() throws Exception {
// Create Resource
SnmpCollectionAgent agent = createCollectionAgent();
SnmpCollectionResource resource = createNodeResource(agent);
// Add Gauge Attribute
Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
SnmpAttribute attribute = addAttributeToCollectionResource(resource, "myGauge", AttributeType.GAUGE, "0", "100");
attributes.put(attribute.getName(), attribute);
// Create Wrapper
CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
// Get gauge value 3 times
Assert.assertEquals(Double.valueOf(100.0), wrapper.getAttributeValue("myGauge"));
Assert.assertEquals(Double.valueOf(100.0), wrapper.getAttributeValue("myGauge"));
Assert.assertEquals(Double.valueOf(100.0), wrapper.getAttributeValue("myGauge"));
EasyMock.verify(agent);
}
use of org.opennms.netmgt.collectd.SnmpCollectionAgent in project opennms by OpenNMS.
the class BasePersisterTest method buildStringAttribute.
private SnmpAttribute buildStringAttribute() {
EasyMock.expect(m_ifDao.load(m_intf.getId())).andReturn(m_intf).anyTimes();
m_easyMockUtils.replayAll();
SnmpCollectionAgent agent = DefaultCollectionAgent.create(m_intf.getId(), m_ifDao, m_transMgr);
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
NodeResourceType resourceType = new NodeResourceType(agent, collection);
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
MibObject mibObject = new MibObject();
mibObject.setOid(".1.1.1.1");
mibObject.setAlias("mibObjectAlias");
mibObject.setType("string");
mibObject.setInstance("0");
mibObject.setMaxval(null);
mibObject.setMinval(null);
SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
return new SnmpAttribute(resource, attributeType, SnmpUtils.getValueFactory().getOctetString("foo".getBytes()));
}
use of org.opennms.netmgt.collectd.SnmpCollectionAgent 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);
}
Aggregations