Search in sources :

Example 21 with SnmpCollectionAgent

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);
}
Also used : NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType) Date(java.util.Date) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) BigInteger(java.math.BigInteger) IfInfo(org.opennms.netmgt.collectd.IfInfo) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource)

Example 22 with SnmpCollectionAgent

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);
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Example 23 with SnmpCollectionAgent

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);
}
Also used : SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) GenericIndexResource(org.opennms.netmgt.collectd.GenericIndexResource) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) Date(java.util.Date) Test(org.junit.Test)

Example 24 with SnmpCollectionAgent

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);
}
Also used : NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) NodeInfo(org.opennms.netmgt.collectd.NodeInfo) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) Test(org.junit.Test)

Example 25 with SnmpCollectionAgent

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);
}
Also used : NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) NodeInfo(org.opennms.netmgt.collectd.NodeInfo) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource)

Aggregations

SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)30 Test (org.junit.Test)22 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)22 HashMap (java.util.HashMap)13 Date (java.util.Date)10 IfResourceType (org.opennms.netmgt.collectd.IfResourceType)10 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)10 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)9 NodeInfo (org.opennms.netmgt.collectd.NodeInfo)8 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)8 MibObject (org.opennms.netmgt.config.datacollection.MibObject)7 BigInteger (java.math.BigInteger)6 IfInfo (org.opennms.netmgt.collectd.IfInfo)6 SnmpAttributeType (org.opennms.netmgt.collectd.SnmpAttributeType)6 SnmpIfData (org.opennms.netmgt.collectd.SnmpIfData)6 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)6 GenericIndexResource (org.opennms.netmgt.collectd.GenericIndexResource)5 GenericIndexResourceType (org.opennms.netmgt.collectd.GenericIndexResourceType)5 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)5 OnmsSnmpCollection (org.opennms.netmgt.collectd.OnmsSnmpCollection)5