Search in sources :

Example 26 with CollectionAttribute

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

the class MockCollectionResource method visit.

@Override
public void visit(CollectionSetVisitor visitor) {
    for (Entry<String, String> entry : attributes.entrySet()) {
        final CollectionResource resource = this;
        final String attrName = entry.getKey();
        final String attrValue = entry.getValue();
        CollectionAttribute attribute = new CollectionAttribute() {

            @Override
            public CollectionResource getResource() {
                return resource;
            }

            @Override
            public String getStringValue() {
                return attrValue;
            }

            @Override
            public Double getNumericValue() {
                try {
                    return Double.parseDouble(attrValue);
                } catch (NumberFormatException | NullPointerException e) {
                    return null;
                }
            }

            @Override
            public String getName() {
                return attrName;
            }

            @Override
            public void storeAttribute(Persister persister) {
            }

            @Override
            public boolean shouldPersist(ServiceParameters params) {
                return true;
            }

            @Override
            public CollectionAttributeType getAttributeType() {
                return null;
            }

            @Override
            public void visit(CollectionSetVisitor visitor) {
            }

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

            @Override
            public String getMetricIdentifier() {
                return "MOCK_" + getName();
            }
        };
        visitor.visitAttribute(attribute);
    }
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) Persister(org.opennms.netmgt.collection.api.Persister) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters)

Example 27 with CollectionAttribute

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

the class HexStringAttributeType method storeAttribute.

@Override
public void storeAttribute(CollectionAttribute attribute, Persister persister) {
    CollectionAttribute attributeToPersist = attribute;
    if (attribute instanceof SnmpAttribute) {
        // When storing SNMP attributes alter the getStringValue() value method
        // so that the hex string is returned instead of the display string
        attributeToPersist = new SnmpAttributeWrapper((SnmpAttribute) attribute);
    }
    persister.persistStringAttribute(attributeToPersist);
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute)

Example 28 with CollectionAttribute

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

the class RegExPropertyExtender 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 sourceType = property.getParameterValue(SOURCE_TYPE);
    if (StringUtils.isBlank(sourceType)) {
        LOG.warn("Cannot execute the RegEx property extender because: missing parameter {}", SOURCE_TYPE);
        return null;
    }
    final String sourceAlias = property.getParameterValue(SOURCE_ALIAS);
    if (StringUtils.isBlank(sourceAlias)) {
        LOG.warn("Cannot execute the RegEx property extender because: missing parameter {}", SOURCE_ALIAS);
        return null;
    }
    final String indexPattern = property.getParameterValue(INDEX_PATTERN);
    if (StringUtils.isBlank(indexPattern)) {
        LOG.warn("Cannot execute the RegEx property extender because: missing parameter {}", INDEX_PATTERN);
        return null;
    }
    Pattern p = Pattern.compile(indexPattern);
    Matcher m = p.matcher(targetResource.getInstance());
    Optional<CollectionAttribute> target = null;
    if (m.find()) {
        final String index = m.group(1);
        target = sourceAttributes.stream().filter(a -> matches(sourceType, sourceAlias, index, a)).findFirst();
    }
    if (target != null && target.isPresent()) {
        AttributeGroupType groupType = targetResource.getGroupType(property.getGroupName());
        if (groupType != null) {
            MibPropertyAttributeType type = new MibPropertyAttributeType(targetResource.getResourceType(), property, groupType);
            SnmpValue value = SnmpUtils.getValueFactory().getOctetString(target.get().getStringValue().getBytes());
            return new SnmpAttribute(targetResource, type, value);
        }
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Matcher(java.util.regex.Matcher) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType)

Example 29 with CollectionAttribute

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

the class AliasedGroup method visit.

/** {@inheritDoc} */
@Override
public void visit(CollectionSetVisitor visitor) {
    visitor.visitGroup(this);
    for (CollectionAttribute attr : getAttributes()) {
        AliasedAttribute aliased = new AliasedAttribute(getResource(), (SnmpAttribute) attr);
        LOG.debug("visiting at aliased  = {}", aliased);
        aliased.visit(visitor);
    }
    visitor.completeGroup(this);
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute)

Aggregations

CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)29 Test (org.junit.Test)15 HashMap (java.util.HashMap)10 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)9 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)8 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)8 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)6 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)5 Parameter (org.opennms.netmgt.config.datacollection.Parameter)5 PersistenceSelectorStrategy (org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)5 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)5 StorageStrategy (org.opennms.netmgt.config.datacollection.StorageStrategy)5 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 Date (java.util.Date)4 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)4 AttributeType (org.opennms.netmgt.collection.api.AttributeType)4 AbstractCollectionSetVisitor (org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor)4 Resource (org.opennms.netmgt.collection.support.builder.Resource)4