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.getType()).andReturn(NetworkInterface.TYPE_INET).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 testThresholdsFiltersOnNodeResource.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds-5.xml
*/
@Test
public void testThresholdsFiltersOnNodeResource() 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();
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
NodeResourceType resourceType = new NodeResourceType(agent, collection);
// 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");
// Creating Resource
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
addAttributeToCollectionResource(resource, resourceType, "hda1_hrStorageUsed", "gauge", "node", 50);
addAttributeToCollectionResource(resource, resourceType, "hda1_hrStorageSize", "gauge", "node", 100);
addAttributeToCollectionResource(resource, resourceType, "hda2_hrStorageUsed", "gauge", "node", 60);
addAttributeToCollectionResource(resource, resourceType, "hda2_hrStorageSize", "gauge", "node", 100);
addAttributeToCollectionResource(resource, resourceType, "hda3_hrStorageUsed", "gauge", "node", 70);
addAttributeToCollectionResource(resource, resourceType, "hda3_hrStorageSize", "gauge", "node", 100);
// Run Visitor and Verify Events
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.collectd.SnmpCollectionAgent in project opennms by OpenNMS.
the class ThresholdingVisitorIT method runInterfaceResource.
private void runInterfaceResource(ThresholdingVisitor visitor, String ipAddress, String ifName, Long ifSpeed, Integer ifIndex, long v1, long v2) {
SnmpIfData ifData = createSnmpIfData(ipAddress, ifName, ifSpeed, ifIndex, true);
SnmpCollectionAgent agent = createCollectionAgent();
IfResourceType resourceType = createInterfaceResourceType(agent);
// Step 1
visitor.visitCollectionSet(createAnonymousCollectionSet(visitor.getCollectionTimestamp().getTime()));
SnmpCollectionResource resource = new IfInfo(resourceType, agent, ifData);
addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", v1);
addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", v1);
resource.visit(visitor);
// Step 2 - Increment Counters
visitor.visitCollectionSet(createAnonymousCollectionSet(visitor.getCollectionTimestamp().getTime() + 300000));
resource = new IfInfo(resourceType, agent, ifData);
addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", v2);
addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", v2);
resource.visit(visitor);
EasyMock.verify(agent);
}
use of org.opennms.netmgt.collectd.SnmpCollectionAgent in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testDisabledCollection.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds-bug3428.xml
*
* Updated to reflect the fact that counter are treated as rates.
*
* This is related with the cutomer support ticket number 300
*/
@Test
public void testDisabledCollection() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-bug3428.xml");
Integer ifIndex = 1;
Long ifSpeed = 100000000l;
String ifName = "wlan0";
addHighThresholdEvent(1, 90, 50, 120, ifName, ifIndex.toString(), "ifInOctets", ifName, ifIndex.toString());
// Create interface resource with data collection disabled
SnmpIfData ifData = createSnmpIfData("127.0.0.1", ifName, ifSpeed, ifIndex, false);
SnmpCollectionAgent agent = createCollectionAgent();
IfResourceType resourceType = createInterfaceResourceType(agent);
ThresholdingVisitor visitor = createVisitor();
// Step 1 (should be ignored)
SnmpCollectionResource resource = new IfInfo(resourceType, agent, ifData);
addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", 10000);
addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", 10000);
resource.visit(visitor);
// Step 2 (should be ignored) - Increment Counters; real value = (46000 - 10000)/300 = 120
resource = new IfInfo(resourceType, agent, ifData);
addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", 46000);
addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", 46000);
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(1);
}
use of org.opennms.netmgt.collectd.SnmpCollectionAgent in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testIgnoreAliasedResources.
/*
* 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 testIgnoreAliasedResources() 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 = "#";
// equals to storeByIfAlias = false
ThresholdingVisitor visitor = createVisitor();
SnmpIfData ifData = createSnmpIfData("127.0.0.1", ifName, ifSpeed, ifIndex, true);
SnmpCollectionAgent agent = createCollectionAgent();
IfResourceType resourceType = createInterfaceResourceType(agent);
// Step 1
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
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