Search in sources :

Example 1 with SnmpCollectionResource

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

the class ThresholdingVisitorIT method runFileSystemDataTest.

private void runFileSystemDataTest(ThresholdingVisitor visitor, int resourceId, String fs, long value, long max) throws Exception {
    SnmpCollectionAgent agent = createCollectionAgent();
    // Creating Generic ResourceType
    GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "hrStorageIndex");
    // 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);
    // Creating Resource
    SnmpInstId inst = new SnmpInstId(resourceId);
    SnmpCollectionResource resource = new GenericIndexResource(resourceType, "hrStorageIndex", inst);
    addAttributeToCollectionResource(resource, resourceType, "hrStorageUsed", "gauge", "hrStorageIndex", value);
    addAttributeToCollectionResource(resource, resourceType, "hrStorageSize", "gauge", "hrStorageIndex", max);
    addAttributeToCollectionResource(resource, resourceType, "hrStorageAllocUnits", "gauge", "hrStorageIndex", 1);
    // Run Visitor
    resource.visit(visitor);
    EasyMock.verify(agent);
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) 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)

Example 2 with SnmpCollectionResource

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

the class ThresholdingVisitorIT method testBug3193.

/*
     * This test uses this files from src/test/resources:
     * - threshd-configuration.xml
     * - test-thresholds-bug3193.xml
     * 
     * Updated to reflect the fact that counter are treated as rates.
     */
@Test
public void testBug3193() throws Exception {
    initFactories("/threshd-configuration.xml", "/test-thresholds-bug3193.xml");
    ThresholdingVisitor visitor = createVisitor();
    SnmpCollectionAgent agent = createCollectionAgent();
    NodeResourceType resourceType = createNodeResourceType(agent);
    MibObject mibObject = createMibObject("counter", "myCounter", "0");
    SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "default", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    // Add Events
    addHighThresholdEvent(1, 100, 90, 110, "node", "node", "myCounter", null, null);
    addHighThresholdEvent(1, 70, 60, 80, "node", "node", "myCounter - 30", null, null);
    addHighRearmEvent(1, 100, 90, 40, "node", "node", "myCounter", null, null);
    addHighRearmEvent(1, 70, 60, 10, "node", "node", "myCounter - 30", null, null);
    long baseDate = new Date().getTime();
    // Collect Step 1 : First Data: Last should be NaN
    visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
    SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(2000));
    resource.visit(visitor);
    // Collect Step 2 : First Value: (last-current)/step => (20000-2000)/300=60
    visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 300000));
    resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(20000));
    resource.visit(visitor);
    // Collect Step 3 : Second Value: (last-current)/step => (53000-20000)/300=110 => Trigger
    visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 600000));
    resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(53000));
    resource.visit(visitor);
    // Collect Step 3 : Third Value (last-current)/step => (65000-53000)/300=40 => Rearm
    visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 900000));
    resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(65000));
    resource.visit(visitor);
    EasyMock.verify(agent);
    verifyEvents(0);
}
Also used : NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) NodeInfo(org.opennms.netmgt.collectd.NodeInfo) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) Date(java.util.Date) Test(org.junit.Test)

Example 3 with SnmpCollectionResource

use of org.opennms.netmgt.collectd.SnmpCollectionResource 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);
}
Also used : NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) ResourcePath(org.opennms.netmgt.model.ResourcePath) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) NodeInfo(org.opennms.netmgt.collectd.NodeInfo) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) Test(org.junit.Test)

Example 4 with SnmpCollectionResource

use of org.opennms.netmgt.collectd.SnmpCollectionResource 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);
}
Also used : IfResourceType(org.opennms.netmgt.collectd.IfResourceType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) IfInfo(org.opennms.netmgt.collectd.IfInfo) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource)

Example 5 with SnmpCollectionResource

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

Aggregations

SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)22 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)22 Test (org.junit.Test)17 HashMap (java.util.HashMap)10 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)10 Date (java.util.Date)9 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)9 NodeInfo (org.opennms.netmgt.collectd.NodeInfo)8 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)8 IfResourceType (org.opennms.netmgt.collectd.IfResourceType)6 SnmpAttributeType (org.opennms.netmgt.collectd.SnmpAttributeType)6 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)6 MibObject (org.opennms.netmgt.config.datacollection.MibObject)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 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)5 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)5 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)5