Search in sources :

Example 1 with AttributeGroupType

use of org.opennms.netmgt.collection.api.AttributeGroupType 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 2 with AttributeGroupType

use of org.opennms.netmgt.collection.api.AttributeGroupType in project opennms by OpenNMS.

the class CiscoQoSPropertyExtender method getTargetAttribute.

/* (non-Javadoc)
     * @see org.opennms.netmgt.collectd.SnmpPropertyExtender#getTargetAttribute(java.util.List, org.opennms.netmgt.collectd.SnmpCollectionResource, org.opennms.netmgt.config.datacollection.MibObjProperty)
     */
@Override
public SnmpAttribute getTargetAttribute(List<CollectionAttribute> sourceAttributes, SnmpCollectionResource targetResource, MibObjProperty property) {
    final String targetProperty = property.getParameterValue(PARAM_TARGET_PROPERTY);
    if (targetProperty == null) {
        LOG.error("CiscoQoS getTargetAttribute: parameter {} is required. Expected values: policyName, classMapName, interfaceAlias, interfaceName", PARAM_TARGET_PROPERTY);
        return null;
    }
    AttributeGroupType groupType = targetResource.getGroupType(property.getGroupName());
    if (groupType == null) {
        LOG.error("CiscoQoS getTargetAttribute: can't find the attribute type name associated with the property {}", property);
        return null;
    }
    String oidIndex = targetResource.getInstance();
    String[] indexes = oidIndex.split("\\.");
    if (indexes.length < 2) {
        LOG.warn("CiscoQoS getTargetAttribute: Malformed Cisco QoS Object Index {} for {}", oidIndex, targetResource);
        return null;
    }
    final Map<String, String> parentIndices = getAttributeMap(sourceAttributes, property.getParameterValue(TYPE_QOS_PARENT_INDEX, TYPE_QOS_PARENT_INDEX), property.getParameterValue(OBJ_QOS_PARENT_INDEX, OBJ_QOS_PARENT_INDEX));
    if (parentIndices.isEmpty()) {
        LOG.warn("CiscoQoS getTargetAttribute: Can't find parent indexes {} for type {}", OBJ_QOS_CONF_INDEX, TYPE_QOS_PARENT_INDEX);
        return null;
    }
    final Map<String, String> configTypes = getAttributeMap(sourceAttributes, property.getParameterValue(TYPE_QOS_CONF_TYPE, TYPE_QOS_CONF_TYPE), property.getParameterValue(OBJ_QOS_CONF_TYPE, OBJ_QOS_CONF_TYPE));
    if (configTypes.isEmpty()) {
        LOG.warn("CiscoQoS getTargetAttribute: Can't find config types {} for type {}", OBJ_QOS_CONF_TYPE, TYPE_QOS_CONF_TYPE);
        return null;
    }
    String policyIndex = indexes[0];
    String objectsIndex = indexes[1];
    String parentIndex = objectsIndex;
    String searchIndex = null;
    boolean found = false;
    do {
        searchIndex = policyIndex + '.' + parentIndex;
        parentIndex = parentIndices.get(searchIndex);
        String type = configTypes.get(searchIndex);
        // Is a policy
        found = "1".equals(type);
        LOG.debug("CiscoQoS getTargetAttribute: parent index for {} is {}, is a policy? {}", searchIndex, parentIndex, found);
    } while (!found || parentIndex == null);
    LOG.debug("CiscoQoS getTargetAttribute: retrieving policy config index for {}", searchIndex);
    String targetValue = null;
    final String confIndex_TP = property.getParameterValue(TYPE_QOS_CONF_INDEX, TYPE_QOS_CONF_INDEX);
    final String confIndex_ID = property.getParameterValue(OBJ_QOS_CONF_INDEX, OBJ_QOS_CONF_INDEX);
    final String intfIndex_TP = property.getParameterValue(TYPE_QOS_INTF_INDEX, TYPE_QOS_INTF_INDEX);
    final String intfIndex_ID = property.getParameterValue(OBJ_QOS_INTF_INDEX, OBJ_QOS_INTF_INDEX);
    switch(targetProperty) {
        case PARAM_POLICY_NAME:
            String policyConfigIndex = getAttributeValue(sourceAttributes, searchIndex, confIndex_TP, confIndex_ID);
            if (policyConfigIndex == null) {
                LOG.warn("CiscoQoS getTargetAttribute: Can't find policy for index {}", searchIndex);
                return null;
            }
            final String policyName_TP = property.getParameterValue(TYPE_QOS_POLICY_NAME, TYPE_QOS_POLICY_NAME);
            final String policyName_ID = property.getParameterValue(OBJ_QOS_POLICY_NAME, OBJ_QOS_POLICY_NAME);
            LOG.debug("CiscoQoS getTargetAttribute: found policy config index {}", policyConfigIndex);
            String policyName = getAttributeValue(sourceAttributes, policyConfigIndex, policyName_TP, policyName_ID);
            if (policyName == null) {
                LOG.warn("CiscoQoS getTargetAttribute: Can't find policy name using index {} for resource {} using {}::{}", policyConfigIndex, targetResource, policyName_TP, policyName_ID);
                return null;
            }
            LOG.debug("CiscoQoS getTargetAttribute: policyIndex={}, policyConfigIndex={}, policyName={}", policyIndex, policyConfigIndex, policyName);
            targetValue = policyName;
            break;
        case PARAM_CLASSMAP_NAME:
            String classMapCfgIndex = getAttributeValue(sourceAttributes, oidIndex, confIndex_TP, confIndex_ID);
            if (classMapCfgIndex == null) {
                LOG.warn("CiscoQoS getTargetAttribute: Can't find class-map config index for resource {}", targetResource);
                return null;
            }
            final String classMapName_TP = property.getParameterValue(TYPE_QOS_CLASS_NAME, TYPE_QOS_CLASS_NAME);
            final String classMapName_ID = property.getParameterValue(OBJ_QOS_CLASS_NAME, OBJ_QOS_CLASS_NAME);
            String classMapName = getAttributeValue(sourceAttributes, classMapCfgIndex, classMapName_TP, classMapName_ID);
            if (classMapName == null) {
                LOG.warn("CiscoQoS getTargetAttribute: Can't find class-map name using index {} for resource {} using {}::{}", classMapCfgIndex, targetResource, classMapName_TP, classMapName_ID);
                return null;
            }
            LOG.debug("CiscoQoS getTargetAttribute: classMapCfgIndex={}, classMapName={}", classMapCfgIndex, classMapName);
            targetValue = classMapName;
            break;
        case PARAM_INTERFACE__NAME:
            String interfaceIndex = getAttributeValue(sourceAttributes, policyIndex, intfIndex_TP, intfIndex_ID);
            if (interfaceIndex == null) {
                LOG.warn("CiscoQoS getTargetAttribute: Can't find interface ifIndex for resource {}", targetResource);
                return null;
            }
            final String intfName_ID = property.getParameterValue(OBJ_INTF_NAME, OBJ_INTF_NAME);
            String ifName = getAttributeValue(sourceAttributes, interfaceIndex, CollectionResource.RESOURCE_TYPE_IF, intfName_ID);
            if (ifName == null) {
                LOG.warn("CiscoQoS getTargetAttribute: Can't find ifName using ifIndex {} for resource {} using {}::{}", interfaceIndex, targetResource, CollectionResource.RESOURCE_TYPE_IF, intfName_ID);
                return null;
            }
            targetValue = ifName;
            break;
        case PARAM_INTERFACE_ALIAS:
            interfaceIndex = getAttributeValue(sourceAttributes, policyIndex, intfIndex_TP, intfIndex_ID);
            if (interfaceIndex == null) {
                LOG.warn("CiscoQoS getTargetAttribute: Can't find interface ifIndex for resource {}", targetResource);
                return null;
            }
            final String intfAlias_ID = property.getParameterValue(OBJ_INTF_ALIAS, OBJ_INTF_ALIAS);
            String ifAlias = getAttributeValue(sourceAttributes, interfaceIndex, CollectionResource.RESOURCE_TYPE_IF, intfAlias_ID);
            if (ifAlias == null) {
                LOG.warn("CiscoQoS getTargetAttribute: Can't find ifAlias using ifIndex {} for resource {} using {}::{}", interfaceIndex, targetResource, CollectionResource.RESOURCE_TYPE_IF, intfAlias_ID);
                return null;
            }
            targetValue = ifAlias;
            break;
    }
    if (targetValue == null) {
        LOG.warn("CiscoQoS getTargetAttribute: an unexpected error has happened. Check the parameters on your datacollection-configuration for the property {}", property.getAlias());
        return null;
    }
    MibPropertyAttributeType type = new MibPropertyAttributeType(targetResource.getResourceType(), property, groupType);
    SnmpValue value = SnmpUtils.getValueFactory().getOctetString(targetValue.getBytes());
    return new SnmpAttribute(targetResource, type, value);
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType)

Example 3 with AttributeGroupType

use of org.opennms.netmgt.collection.api.AttributeGroupType in project opennms by OpenNMS.

the class OnmsSnmpCollection method findGroup.

private AttributeGroupType findGroup(Map<String, AttributeGroupType> groupTypes, MibObject mibObject) {
    AttributeGroupType groupType = groupTypes.get(mibObject.getGroupName());
    if (groupType == null) {
        groupType = new AttributeGroupType(mibObject.getGroupName(), mibObject.getGroupIfType());
        groupTypes.put(mibObject.getGroupName(), groupType);
    }
    return groupType;
}
Also used : AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType)

Example 4 with AttributeGroupType

use of org.opennms.netmgt.collection.api.AttributeGroupType 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 5 with AttributeGroupType

use of org.opennms.netmgt.collection.api.AttributeGroupType 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)

Aggregations

AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)21 MibObject (org.opennms.netmgt.config.datacollection.MibObject)16 SnmpAttributeType (org.opennms.netmgt.collectd.SnmpAttributeType)9 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)8 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)8 Test (org.junit.Test)7 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)7 HashMap (java.util.HashMap)6 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)6 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)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 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)4 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)4 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)4 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)4 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)3