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 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 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 ThresholdingVisitorIT method createCollectionAgent.
private static SnmpCollectionAgent createCollectionAgent() {
SnmpCollectionAgent agent = EasyMock.createMock(SnmpCollectionAgent.class);
EasyMock.expect(agent.getNodeId()).andReturn(1).anyTimes();
EasyMock.expect(agent.getStorageResourcePath()).andReturn(ResourcePath.get(String.valueOf(1))).anyTimes();
EasyMock.expect(agent.getHostAddress()).andReturn("127.0.0.1").anyTimes();
EasyMock.expect(agent.getSnmpInterfaceInfo((IfResourceType) EasyMock.anyObject())).andReturn(new HashSet<IfInfo>()).anyTimes();
EasyMock.expect(agent.getAttributeNames()).andReturn(Collections.emptySet()).anyTimes();
EasyMock.expect(agent.getAddress()).andReturn(InetAddrUtils.getLocalHostAddress()).anyTimes();
EasyMock.expect(agent.isStoreByForeignSource()).andReturn(false).anyTimes();
EasyMock.expect(agent.getNodeLabel()).andReturn("test").anyTimes();
EasyMock.expect(agent.getForeignSource()).andReturn(null).anyTimes();
EasyMock.expect(agent.getForeignId()).andReturn(null).anyTimes();
EasyMock.expect(agent.getLocationName()).andReturn(null).anyTimes();
EasyMock.expect(agent.getSysObjectId()).andReturn(null).anyTimes();
EasyMock.expect(agent.getSavedSysUpTime()).andReturn(0L).anyTimes();
EasyMock.replay(agent);
return agent;
}
use of org.opennms.netmgt.collectd.SnmpCollectionAgent in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testThresholdsFiltersOnNodeResourceWithCollectionSetBuilder.
/**
* Similar to {@link #testThresholdsFiltersOnNodeResource()}, but
* we generate the collection set using the CollectionSetBuilder instead
* of using SnmpCollector specific types.
*/
@Test
public void testThresholdsFiltersOnNodeResourceWithCollectionSetBuilder() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-5.xml");
ThresholdingVisitor visitor = createVisitor();
// Adding Expected Thresholds
addHighThresholdEvent(1, 30, 25, 50, "/home", "node", "(hda1_hrStorageUsed/hda1_hrStorageSize)*100", null, null);
addHighThresholdEvent(1, 50, 45, 60, "/opt", "node", "(hda2_hrStorageUsed/hda2_hrStorageSize)*100", null, null);
// Creating Node ResourceType
SnmpCollectionAgent agent = createCollectionAgent();
NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
CollectionSet collectionSet = new CollectionSetBuilder(agent).withNumericAttribute(nodeResource, "hd-usage", "hda1_hrStorageUsed", 50, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda1_hrStorageSize", 100, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda2_hrStorageUsed", 60, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda2_hrStorageSize", 100, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda3_hrStorageUsed", 70, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda3_hrStorageSize", 100, AttributeType.GAUGE).build();
// Creating strings.properties file
ResourcePath path = ResourcePath.get("snmp", "1");
m_resourceStorageDao.setStringAttribute(path, "hda1_hrStorageDescr", "/home");
m_resourceStorageDao.setStringAttribute(path, "hda2_hrStorageDescr", "/opt");
m_resourceStorageDao.setStringAttribute(path, "hda3_hrStorageDescr", "/usr");
// Run Visitor and Verify Events
collectionSet.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
Aggregations