Search in sources :

Example 6 with SnmpCollectionResource

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

the class BasePersisterTest method buildStringAttribute.

private SnmpAttribute buildStringAttribute() {
    EasyMock.expect(m_ifDao.load(m_intf.getId())).andReturn(m_intf).anyTimes();
    m_easyMockUtils.replayAll();
    SnmpCollectionAgent agent = DefaultCollectionAgent.create(m_intf.getId(), m_ifDao, m_transMgr);
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    NodeResourceType resourceType = new NodeResourceType(agent, collection);
    SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
    MibObject mibObject = new MibObject();
    mibObject.setOid(".1.1.1.1");
    mibObject.setAlias("mibObjectAlias");
    mibObject.setType("string");
    mibObject.setInstance("0");
    mibObject.setMaxval(null);
    mibObject.setMinval(null);
    SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    return new SnmpAttribute(resource, attributeType, SnmpUtils.getValueFactory().getOctetString("foo".getBytes()));
}
Also used : NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType) StringAttributeType(org.opennms.netmgt.collectd.StringAttributeType) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) NodeInfo(org.opennms.netmgt.collectd.NodeInfo) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) MibObject(org.opennms.netmgt.config.datacollection.MibObject) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection)

Example 7 with SnmpCollectionResource

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

the class ThresholdingVisitorIT method testBug2746.

/*
     * This bug has not been replicated, but this code covers the apparent scenario, and can be adapted to match
     * any scenario which can actually replicate the reported issue
     * 
     * This test uses this files from src/test/resources:
     * - threshd-configuration.xml
     * - test-thresholds-bug2746.xml
     */
@Test
public void testBug2746() throws Exception {
    initFactories("/threshd-configuration.xml", "/test-thresholds-bug2746.xml");
    ThresholdingVisitor visitor = createVisitor();
    SnmpCollectionAgent agent = createCollectionAgent();
    NodeResourceType resourceType = createNodeResourceType(agent);
    MibObject mibObject = createMibObject("gauge", "bug2746", "0");
    SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "default", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    // Add Events
    addHighThresholdEvent(1, 50, 40, 60, "node", "node", "bug2746", null, null);
    // Step 1 : Execute visitor
    SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(20));
    resource.visit(visitor);
    // Step 2 : Repeat a couple of times with the same value, to replicate a steady state
    resource.visit(visitor);
    resource.visit(visitor);
    resource.visit(visitor);
    // Step 3 : Trigger
    resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(60));
    resource.visit(visitor);
    // Step 4 : Don't rearm, but do drop
    resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(45));
    resource.visit(visitor);
    // Step 5 : Shouldn't trigger again
    resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(55));
    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) Test(org.junit.Test)

Example 8 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 9 with SnmpCollectionResource

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

the class ThresholdingVisitorIT method testResourceCounterData.

/*
     * This test uses this files from src/test/resources:
     * - threshd-configuration.xml
     * - test-thresholds.xml
     * 
     * Updated to reflect the fact that counter are treated as rates (counter wrap is not checked here anymore).
     */
@Test
public void testResourceCounterData() throws Exception {
    initFactories("/threshd-configuration.xml", "/test-thresholds-counters.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, 10, 5, 15, "node", "node", "myCounter", null, null);
    addHighRearmEvent(1, 10, 5, 2, "node", "node", "myCounter", null, null);
    long baseDate = new Date().getTime();
    // Step 0: Visit a CollectionSet with a timestamp, so that the thresholder knows how when the collection was held 
    // Normally visiting the CollectionSet would end up visiting the resources, but we're fudging that for the test
    visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
    // Collect Step 1 : Initialize counter cache.
    SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(1000));
    resource.visit(visitor);
    // Collect Step 2 : Trigger. (last-current)/step => (5500-1000)/300=15
    visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 300000));
    resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500));
    resource.visit(visitor);
    // Collect Step 3 : Rearm. (last-current)/step => (6100-5500)/300=2
    visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 600000));
    resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(6100));
    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 10 with SnmpCollectionResource

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

the class ThresholdingVisitorIT method testZeroIntervalResourceCounterData.

@Test
public void testZeroIntervalResourceCounterData() throws Exception {
    initFactories("/threshd-configuration.xml", "/test-thresholds-counters.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, 10, 5, 15, "node", "node", "myCounter", null, null);
    addHighRearmEvent(1, 10, 5, 2, "node", "node", "myCounter", null, null);
    long baseDate = new Date().getTime();
    // Step 0: Visit a CollectionSet with a timestamp, so that the thresholder knows how when the collection was held 
    // Normally visiting the CollectionSet would end up visiting the resources, but we're fudging that for the test
    visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
    // Collect Step 1 : Initialize counter cache.
    SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(1000));
    resource.visit(visitor);
    // Collect Step 1.5 : Send a new data point with the same timestamp as before and a
    // different value. This should not trigger a threshold violation because the time
    // interval is zero. It should also not reset the cached value for the attribute
    // because the time interval is zero.
    visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
    resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500));
    resource.visit(visitor);
    // Collect Step 2 : Trigger. (last-current)/step => (5500-1000)/300=15
    visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 300000));
    resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500));
    resource.visit(visitor);
    // Collect Step 3 : Rearm. (last-current)/step => (6100-5500)/300=2
    visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 600000));
    resource = new NodeInfo(resourceType, agent);
    resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(6100));
    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)

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