Search in sources :

Example 11 with AttributeGroupType

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

the class CollectionSetDTO method buildCollectionResources.

private Set<CollectionResource> buildCollectionResources() {
    final Set<CollectionResource> collectionResources = new LinkedHashSet<>();
    for (CollectionResourceDTO entry : this.collectionResources) {
        final Resource resource = entry.getResource();
        final AbstractCollectionResource collectionResource = CollectionSetBuilder.toCollectionResource(resource, agent);
        for (Attribute<?> attribute : entry.getAttributes()) {
            final AttributeGroupType groupType = new AttributeGroupType(attribute.getGroup(), AttributeGroupType.IF_TYPE_ALL);
            final AbstractCollectionAttributeType attributeType = new AbstractCollectionAttributeType(groupType) {

                @Override
                public AttributeType getType() {
                    return attribute.getType();
                }

                @Override
                public String getName() {
                    return attribute.getName();
                }

                @Override
                public void storeAttribute(CollectionAttribute collectionAttribute, Persister persister) {
                    if (AttributeType.STRING.equals(attribute.getType())) {
                        persister.persistStringAttribute(collectionAttribute);
                    } else {
                        persister.persistNumericAttribute(collectionAttribute);
                    }
                }

                @Override
                public String toString() {
                    return attribute.toString();
                }
            };
            collectionResource.addAttribute(new AbstractCollectionAttribute(attributeType, collectionResource) {

                @Override
                public String getMetricIdentifier() {
                    return attribute.getName();
                }

                @Override
                public Number getNumericValue() {
                    return attribute.getNumericValue();
                }

                @Override
                public String getStringValue() {
                    return attribute.getStringValue();
                }

                @Override
                public boolean shouldPersist(ServiceParameters params) {
                    return !(Boolean.FALSE.equals(disableCounterPersistence) && AttributeType.COUNTER.equals(attribute.getType()));
                }

                @Override
                public String toString() {
                    return String.format("Attribute[%s:%s]", getMetricIdentifier(), attribute.getValue());
                }
            });
        }
        collectionResources.add(collectionResource);
    }
    return collectionResources;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) AbstractCollectionResource(org.opennms.netmgt.collection.support.AbstractCollectionResource) AbstractCollectionAttribute(org.opennms.netmgt.collection.support.AbstractCollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) AbstractCollectionResource(org.opennms.netmgt.collection.support.AbstractCollectionResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) AbstractCollectionAttribute(org.opennms.netmgt.collection.support.AbstractCollectionAttribute) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) Persister(org.opennms.netmgt.collection.api.Persister) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) AbstractCollectionResource(org.opennms.netmgt.collection.support.AbstractCollectionResource) AbstractCollectionAttributeType(org.opennms.netmgt.collection.support.AbstractCollectionAttributeType)

Example 12 with AttributeGroupType

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

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

the class ThresholdingVisitorIT method addAttributeToCollectionResource.

private static void addAttributeToCollectionResource(SnmpCollectionResource resource, ResourceType type, String attributeName, String attributeType, String attributeInstance, long value) {
    MibObject object = createMibObject(attributeType, attributeName, attributeInstance);
    SnmpAttributeType objectType = new NumericAttributeType(type, "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    SnmpValue snmpValue = attributeType.equals("counter") ? SnmpUtils.getValueFactory().getCounter32(value) : SnmpUtils.getValueFactory().getGauge32(value);
    resource.setAttributeValue(objectType, snmpValue);
}
Also used : NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType)

Example 14 with AttributeGroupType

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

the class CollectionResourceWrapperIT method addAttributeToCollectionResource.

private SnmpAttribute addAttributeToCollectionResource(SnmpCollectionResource resource, String attributeName, AttributeType attributeType, String attributeInstance, String value) {
    MibObject object = createMibObject(attributeType, attributeName, attributeInstance);
    SnmpAttributeType objectType = null;
    SnmpValue snmpValue = null;
    if (AttributeType.STRING.equals(attributeType)) {
        objectType = new SnmpAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)) {

            @Override
            public AttributeType getType() {
                return AttributeType.STRING;
            }

            @Override
            public void storeAttribute(CollectionAttribute attribute, Persister persister) {
                persister.persistStringAttribute(attribute);
            }
        };
        snmpValue = SnmpUtils.getValueFactory().getOctetString(value.getBytes());
    } else {
        objectType = new NumericAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
        long v = Long.parseLong(value);
        snmpValue = AttributeType.COUNTER.equals(attributeType) ? SnmpUtils.getValueFactory().getCounter32(v) : SnmpUtils.getValueFactory().getGauge32(v);
    }
    resource.setAttributeValue(objectType, snmpValue);
    return new SnmpAttribute(resource, objectType, snmpValue);
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) AttributeType(org.opennms.netmgt.collection.api.AttributeType) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType) NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) Persister(org.opennms.netmgt.collection.api.Persister) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType)

Example 15 with AttributeGroupType

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

the class CollectionResourceWrapperIT method addAttributeToCollectionResource.

private SnmpAttribute addAttributeToCollectionResource(SnmpCollectionResource resource, String attributeName, AttributeType attributeType, String attributeInstance, BigInteger value) {
    MibObject object = createMibObject(attributeType, attributeName, attributeInstance);
    SnmpAttributeType objectType = new NumericAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    SnmpValue snmpValue = SnmpUtils.getValueFactory().getCounter64(value);
    resource.setAttributeValue(objectType, snmpValue);
    return new SnmpAttribute(resource, objectType, snmpValue);
}
Also used : NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType)

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