use of org.opennms.netmgt.collectd.SnmpCollectionAgent 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.SnmpCollectionAgent in project opennms by OpenNMS.
the class ThresholdingVisitorIT method runFileSystemDataTestWithCollectionSetBuilder.
private void runFileSystemDataTestWithCollectionSetBuilder(ThresholdingVisitor visitor, int resourceId, String fs, long value, long max) throws Exception {
SnmpCollectionAgent agent = createCollectionAgent();
NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
// Creating Generic ResourceType
org.opennms.netmgt.config.datacollection.ResourceType indexResourceType = createIndexResourceType(agent, "hrStorageIndex");
GenericTypeResource genericResource = new GenericTypeResource(nodeResource, indexResourceType, Integer.toString(resourceId));
// Creating strings.properties file
ResourcePath path = ResourcePath.get("snmp", "1", "hrStorageIndex", Integer.toString(resourceId));
m_resourceStorageDao.setStringAttribute(path, "hrStorageType", ".1.3.6.1.2.1.25.2.1.4");
m_resourceStorageDao.setStringAttribute(path, "hrStorageDescr", fs);
// Build the collection set
CollectionSet collectionSet = new CollectionSetBuilder(agent).withNumericAttribute(genericResource, "hd-usage", "hrStorageUsed", value, AttributeType.GAUGE).withNumericAttribute(genericResource, "hd-usage", "hrStorageSize", max, AttributeType.GAUGE).withNumericAttribute(genericResource, "hd-usage", "hrStorageAllocUnits", 1, AttributeType.GAUGE).build();
// Run Visitor
collectionSet.visit(visitor);
EasyMock.verify(agent);
}
use of org.opennms.netmgt.collectd.SnmpCollectionAgent in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testBug3554_withMockFilterDao.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration-bug3554.xml
* - test-thresholds-bug3554.xml
*/
@Test
public void testBug3554_withMockFilterDao() throws Exception {
initFactories("/threshd-configuration-bug3554.xml", "/test-thresholds-bug3554.xml");
// Visitor with Mock FavoriteFilterDao
ThresholdingVisitor visitor = createVisitor();
visitor.visitCollectionSet(createAnonymousCollectionSet(new Date().getTime()));
// Do nothing, just to check visitor
// real value = (46000 - 10000)/300 = 120
runInterfaceResource(visitor, "127.0.0.1", "eth0", 10000000l, 1, 10000, 46000);
// Do nothing, just to check visitor
runGaugeDataTest(visitor, 12000);
// Do nothing, just to check visitor
SnmpCollectionAgent agent = createCollectionAgent();
GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "ciscoEnvMonTemperatureStatusIndex");
SnmpCollectionResource resource = new GenericIndexResource(resourceType, "ciscoEnvMonTemperatureStatusIndex", new SnmpInstId(45));
resource.visit(visitor);
EasyMock.verify(agent);
}
use of org.opennms.netmgt.collectd.SnmpCollectionAgent in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testNMS5115.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds-NMS5115.xml
*
* The idea is to be able to use any numeric metric inside the resource filters. NMS-5115 is a valid use case for this.
*/
@Test
public void testNMS5115() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-NMS5115.xml");
addEvent(EventConstants.LOW_THRESHOLD_EVENT_UEI, "127.0.0.1", "SNMP", 1, null, null, 5.0, "node", "node", "memAvailSwap / memTotalSwap * 100.0", null, null, m_anticipator, m_anticipatedEvents);
ThresholdingVisitor visitor = createVisitor();
SnmpCollectionAgent agent = createCollectionAgent();
NodeResourceType resourceType = createNodeResourceType(agent);
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
addAttributeToCollectionResource(resource, resourceType, "memAvailSwap", "gauge", "0", 5);
addAttributeToCollectionResource(resource, resourceType, "memTotalSwap", "gauge", "0", 100);
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.collectd.SnmpCollectionAgent in project opennms by OpenNMS.
the class ThresholdingVisitorIT method runGaugeDataTest.
private void runGaugeDataTest(ThresholdingVisitor visitor, long value) {
SnmpCollectionAgent agent = createCollectionAgent();
NodeResourceType resourceType = createNodeResourceType(agent);
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
addAttributeToCollectionResource(resource, resourceType, "freeMem", "gauge", "0", value);
resource.visit(visitor);
EasyMock.verify(agent);
}
Aggregations