Search in sources :

Example 1 with MibObject

use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.

the class ThresholdingVisitorIT method createMibObject.

private static MibObject createMibObject(String type, String alias, String instance) {
    MibObject mibObject = new MibObject();
    mibObject.setOid(".1.1.1.1");
    mibObject.setAlias(alias);
    mibObject.setType(type);
    mibObject.setInstance(instance);
    mibObject.setMaxval(null);
    mibObject.setMinval(null);
    return mibObject;
}
Also used : MibObject(org.opennms.netmgt.config.datacollection.MibObject)

Example 2 with MibObject

use of org.opennms.netmgt.config.datacollection.MibObject 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 MibObject

use of org.opennms.netmgt.config.datacollection.MibObject 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 4 with MibObject

use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.

the class RrdPersistOperationBuilderTest method testCommitWithDeclaredAttributeAndNullValue.

@Test
public void testCommitWithDeclaredAttributeAndNullValue() throws Exception {
    RrdRepository repository = createRrdRepository();
    SnmpCollectionAgent agent = getCollectionAgent();
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    NodeResourceType resourceType = new NodeResourceType(agent, collection);
    CollectionResource 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);
    SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection, m_locationAwareSnmpClient);
    SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes())));
    RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false);
    builder.declareAttribute(attributeType);
    builder.setAttributeValue(attributeType, null);
    builder.commit();
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) RrdPersistOperationBuilder(org.opennms.netmgt.collection.persistence.rrd.RrdPersistOperationBuilder) HashMap(java.util.HashMap) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) Test(org.junit.Test)

Example 5 with MibObject

use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.

the class RrdPersistOperationBuilderTest method testCommitWithDeclaredAttributeAndValue.

@Test
public void testCommitWithDeclaredAttributeAndValue() throws Exception {
    File nodeDir = m_fileAnticipator.expecting(getSnmpRrdDirectory(), m_node.getId().toString());
    m_fileAnticipator.expecting(nodeDir, "rrdName" + m_rrdStrategy.getDefaultFileExtension());
    m_fileAnticipator.expecting(nodeDir, "rrdName" + ".meta");
    RrdRepository repository = createRrdRepository();
    SnmpCollectionAgent agent = getCollectionAgent();
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    NodeResourceType resourceType = new NodeResourceType(agent, collection);
    CollectionResource resource = new NodeInfo(resourceType, agent);
    MibObject mibObject = new MibObject();
    mibObject.setOid(".1.1.1.1");
    mibObject.setAlias("mibObjectAlias");
    mibObject.setType("counter");
    mibObject.setInstance("0");
    mibObject.setMaxval(null);
    mibObject.setMinval(null);
    SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection, m_locationAwareSnmpClient);
    SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes())));
    RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false);
    builder.declareAttribute(attributeType);
    builder.setAttributeValue(attributeType, 6.022E23d);
    builder.commit();
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) RrdPersistOperationBuilder(org.opennms.netmgt.collection.persistence.rrd.RrdPersistOperationBuilder) HashMap(java.util.HashMap) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) MibObject(org.opennms.netmgt.config.datacollection.MibObject) File(java.io.File) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) Test(org.junit.Test)

Aggregations

MibObject (org.opennms.netmgt.config.datacollection.MibObject)25 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)16 Test (org.junit.Test)9 SnmpAttributeType (org.opennms.netmgt.collectd.SnmpAttributeType)9 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)8 HashMap (java.util.HashMap)6 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)6 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)6 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)6 NodeInfo (org.opennms.netmgt.collectd.NodeInfo)5 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)5 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)5 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)5 Date (java.util.Date)4 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)4 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)4 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)4 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)3 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)3 RrdPersistOperationBuilder (org.opennms.netmgt.collection.persistence.rrd.RrdPersistOperationBuilder)3