Search in sources :

Example 1 with AliasedResource

use of org.opennms.netmgt.collectd.AliasedResource 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);
}
Also used : BigInteger(java.math.BigInteger) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) AliasedResource(org.opennms.netmgt.collectd.AliasedResource) IfInfo(org.opennms.netmgt.collectd.IfInfo) Test(org.junit.Test)

Example 2 with AliasedResource

use of org.opennms.netmgt.collectd.AliasedResource in project opennms by OpenNMS.

the class ThresholdingVisitorIT method testBug3664.

/*
     * 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 testBug3664() 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 = "#";
    String label = domain + "/" + ifAlias;
    addHighThresholdEvent(1, 90, 50, 120, label, "Unknown", "ifOutOctets", label, ifIndex.toString());
    addHighThresholdEvent(1, 90, 50, 120, label, "Unknown", "ifInOctets", label, ifIndex.toString());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("thresholding-enabled", "true");
    params.put("storeByIfAlias", "true");
    ThresholdingVisitor visitor = createVisitor(params);
    SnmpIfData ifData = createSnmpIfData("127.0.0.1", ifName, ifSpeed, ifIndex, true);
    SnmpCollectionAgent agent = createCollectionAgent();
    IfResourceType resourceType = createInterfaceResourceType(agent);
    long timestamp = new Date().getTime();
    // Step 1
    visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp));
    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
    visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp + 300000));
    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);
}
Also used : SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) Date(java.util.Date) BigInteger(java.math.BigInteger) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) AliasedResource(org.opennms.netmgt.collectd.AliasedResource) MibObject(org.opennms.netmgt.config.datacollection.MibObject) IfInfo(org.opennms.netmgt.collectd.IfInfo) Test(org.junit.Test)

Aggregations

BigInteger (java.math.BigInteger)2 Test (org.junit.Test)2 AliasedResource (org.opennms.netmgt.collectd.AliasedResource)2 IfInfo (org.opennms.netmgt.collectd.IfInfo)2 IfResourceType (org.opennms.netmgt.collectd.IfResourceType)2 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)2 SnmpIfData (org.opennms.netmgt.collectd.SnmpIfData)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 MibObject (org.opennms.netmgt.config.datacollection.MibObject)1