Search in sources :

Example 11 with CollectionAttribute

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

the class CollectCommand method printCollectionSet.

private void printCollectionSet(CollectionSet collectionSet) {
    AtomicBoolean didPrintAttribute = new AtomicBoolean(false);
    collectionSet.visit(new AbstractCollectionSetVisitor() {

        @Override
        public void visitResource(CollectionResource resource) {
            System.out.printf("%s\n", resource);
        }

        @Override
        public void visitGroup(AttributeGroup group) {
            System.out.printf("\tGroup: %s\n", group.getName());
        }

        @Override
        public void visitAttribute(CollectionAttribute attribute) {
            System.out.printf("\t\t%s\n", attribute);
            didPrintAttribute.set(true);
        }
    });
    if (!didPrintAttribute.get()) {
        System.out.println("(Empty collection set)");
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) AttributeGroup(org.opennms.netmgt.collection.api.AttributeGroup) AbstractCollectionSetVisitor(org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor)

Example 12 with CollectionAttribute

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

the class CollectionSetUtils method getAttributesByName.

public static Map<String, CollectionAttribute> getAttributesByName(CollectionSet collectionSet) {
    final Map<String, CollectionAttribute> attributesByName = Maps.newHashMap();
    collectionSet.visit(new AbstractCollectionSetVisitor() {

        @Override
        public void visitAttribute(CollectionAttribute attribute) {
            attributesByName.put(attribute.getName(), attribute);
        }
    });
    return attributesByName;
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) AbstractCollectionSetVisitor(org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor)

Example 13 with CollectionAttribute

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

the class CollectionSetUtils method getAttributesByNameByGroup.

public static Map<String, Map<String, CollectionAttribute>> getAttributesByNameByGroup(CollectionSet collectionSet) {
    final Map<String, Map<String, CollectionAttribute>> attributesByNameByGroup = Maps.newHashMap();
    collectionSet.visit(new AbstractCollectionSetVisitor() {

        private String groupName = null;

        private Map<String, CollectionAttribute> attributesByName = Maps.newHashMap();

        @Override
        public void visitGroup(AttributeGroup group) {
            groupName = group.getName();
        }

        @Override
        public void visitAttribute(CollectionAttribute attribute) {
            attributesByName.put(attribute.getName(), attribute);
        }

        @Override
        public void completeGroup(AttributeGroup group) {
            attributesByNameByGroup.put(groupName, attributesByName);
            attributesByName = Maps.newHashMap();
        }
    });
    return attributesByNameByGroup;
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) AttributeGroup(org.opennms.netmgt.collection.api.AttributeGroup) Map(java.util.Map) AbstractCollectionSetVisitor(org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor)

Example 14 with CollectionAttribute

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

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

the class GroupPersister method visitGroup.

/** {@inheritDoc} */
@Override
public void visitGroup(AttributeGroup group) {
    pushShouldPersist(group);
    if (shouldPersist()) {
        Map<String, String> dsNamesToRrdNames = new LinkedHashMap<String, String>();
        for (CollectionAttribute a : group.getAttributes()) {
            if (a.getType().isNumeric()) {
                dsNamesToRrdNames.put(a.getName(), group.getName());
            }
        }
        setBuilder(createBuilder(group.getResource(), group.getName(), group.getGroupType().getAttributeTypes()));
        ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(getRepository(), group.getResource().getPath());
        m_resourceStorageDao.updateMetricToResourceMappings(path, dsNamesToRrdNames);
    }
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) ResourcePath(org.opennms.netmgt.model.ResourcePath) LinkedHashMap(java.util.LinkedHashMap)

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