Search in sources :

Example 16 with CollectionResource

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

the class CollectCommand method printCollectionSet.

private static 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 17 with CollectionResource

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

the class ObjectNameStorageStrategyTest method testGetResourceNameFromIndex2.

@Test
public void testGetResourceNameFromIndex2() {
    ResourcePath parentResource = ResourcePath.get("1");
    CollectionResource resource = new MockCollectionResource(parentResource, "java.lang:type=MemoryPool,name=Survivor Space", "");
    List<org.opennms.netmgt.collection.api.Parameter> params = new ArrayList<>();
    Parameter p = new Parameter("index-format", "${domain}");
    params.add(p);
    ObjectNameStorageStrategy instance = new ObjectNameStorageStrategy();
    instance.setParameters(params);
    String expResult = "java.lang";
    String result = instance.getResourceNameFromIndex(resource);
    assertEquals(expResult, result);
    params.clear();
    p.setValue("${type}");
    params.add(p);
    instance.setParameters(params);
    expResult = "MemoryPool";
    result = instance.getResourceNameFromIndex(resource);
    assertEquals(expResult, result);
    params.clear();
    p.setValue("${name}");
    params.add(p);
    instance.setParameters(params);
    expResult = "Survivor Space";
    result = instance.getResourceNameFromIndex(resource);
    assertEquals(expResult, result);
    params.clear();
    p.setValue("${domain}:type=${type},name=${name}");
    params.add(p);
    instance.setParameters(params);
    expResult = "java.lang:type=MemoryPool,name=Survivor Space";
    result = instance.getResourceNameFromIndex(resource);
    assertEquals(expResult, result);
}
Also used : ObjectNameStorageStrategy(org.opennms.netmgt.collection.support.ObjectNameStorageStrategy) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) ArrayList(java.util.ArrayList) Parameter(org.opennms.netmgt.config.datacollection.Parameter) Test(org.junit.Test)

Example 18 with CollectionResource

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

the class SnmpCollectionSet method visit.

/**
 * {@inheritDoc}
 */
@Override
public void visit(CollectionSetVisitor visitor) {
    visitor.visitCollectionSet(this);
    for (CollectionResource resource : getResources()) {
        resource.visit(visitor);
    }
    visitor.completeCollectionSet(this);
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource)

Example 19 with CollectionResource

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

the class AbstractXmlCollectionHandler method fillCollectionSet.

/**
 * Fill collection set.
 *
 * @param agent the agent
 * @param collectionSet the collection set
 * @param source the source
 * @param doc the doc
 * @throws XPathExpressionException the x path expression exception
 * @throws ParseException the parse exception
 */
protected void fillCollectionSet(CollectionAgent agent, CollectionSetBuilder builder, XmlSource source, Document doc) throws XPathExpressionException, ParseException {
    NamespaceContext nc = new DocumentNamespaceResolver(doc);
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(nc);
    for (XmlGroup group : source.getXmlGroups()) {
        LOG.debug("fillCollectionSet: getting resources for XML group {} using XPATH {}", group.getName(), group.getResourceXpath());
        Date timestamp = getTimeStamp(doc, xpath, group);
        NodeList resourceList = (NodeList) xpath.evaluate(group.getResourceXpath(), doc, XPathConstants.NODESET);
        for (int j = 0; j < resourceList.getLength(); j++) {
            Node resource = resourceList.item(j);
            String resourceName = getResourceName(xpath, group, resource);
            final Resource collectionResource = getCollectionResource(agent, resourceName, group.getResourceType(), timestamp);
            LOG.debug("fillCollectionSet: processing resource {}", collectionResource);
            for (XmlObject object : group.getXmlObjects()) {
                String value = (String) xpath.evaluate(object.getXpath(), resource, XPathConstants.STRING);
                builder.withAttribute(collectionResource, group.getName(), object.getName(), value, object.getDataType());
            }
            processXmlResource(builder, collectionResource, resourceName, group.getName());
        }
    }
    LOG.debug("fillCollectionSet: finishing collection set with {} resources and {} attributes on {}", builder.getNumResources(), builder.getNumAttributes(), agent);
}
Also used : XPath(javax.xml.xpath.XPath) XmlGroup(org.opennms.protocols.xml.config.XmlGroup) NamespaceContext(javax.xml.namespace.NamespaceContext) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) OnmsNode(org.opennms.netmgt.model.OnmsNode) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) XmlObject(org.opennms.protocols.xml.config.XmlObject) Date(java.util.Date)

Example 20 with CollectionResource

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

Aggregations

CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)22 Test (org.junit.Test)8 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)6 ResourcePath (org.opennms.netmgt.model.ResourcePath)6 ArrayList (java.util.ArrayList)5 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)5 HashMap (java.util.HashMap)4 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)4 RrdPersistOperationBuilder (org.opennms.netmgt.collection.persistence.rrd.RrdPersistOperationBuilder)4 ObjectNameStorageStrategy (org.opennms.netmgt.collection.support.ObjectNameStorageStrategy)4 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)4 Parameter (org.opennms.netmgt.config.datacollection.Parameter)4 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)4 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)4 AttributeGroup (org.opennms.netmgt.collection.api.AttributeGroup)3 AbstractCollectionSetVisitor (org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor)3 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)3 Resource (org.opennms.netmgt.collection.support.builder.Resource)3 MibObject (org.opennms.netmgt.config.datacollection.MibObject)3 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)3