Search in sources :

Example 1 with CollectionResource

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

the class CollectionSetUtils method flatten.

public static List<String> flatten(CollectionSet collectionSet) {
    final List<String> strings = new ArrayList<>();
    collectionSet.visit(new AbstractCollectionSetVisitor() {

        CollectionResource resource;

        AttributeGroup group;

        @Override
        public void visitResource(CollectionResource resource) {
            this.resource = resource;
        }

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

        @Override
        public void visitAttribute(CollectionAttribute attribute) {
            strings.add(String.format("%s/%s/%s[%s,%s]", resource.getPath(), group.getName(), attribute.getName(), attribute.getStringValue(), attribute.getNumericValue()));
        }
    });
    return strings;
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) ArrayList(java.util.ArrayList) AttributeGroup(org.opennms.netmgt.collection.api.AttributeGroup) AbstractCollectionSetVisitor(org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor)

Example 2 with CollectionResource

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

the class GenericTypeResourceTest method getInstanceInResourcePath.

private String getInstanceInResourcePath(String instance) {
    // Mock the ResourceType
    ResourceType rt = mock(ResourceType.class, RETURNS_DEEP_STUBS);
    when(rt.getName()).thenReturn("type");
    when(rt.getStorageStrategy().getClazz()).thenReturn(IndexStorageStrategy.class.getCanonicalName());
    when(rt.getStorageStrategy().getParameters()).thenReturn(Collections.emptyList());
    when(rt.getPersistenceSelectorStrategy().getClazz()).thenReturn(PersistAllSelectorStrategy.class.getCanonicalName());
    when(rt.getPersistenceSelectorStrategy().getParameters()).thenReturn(Collections.emptyList());
    // Create the GenericTypeResource
    NodeLevelResource nlr = new NodeLevelResource(1);
    GenericTypeResource gtr = new GenericTypeResource(nlr, rt, instance);
    // Mock the CollectionResource
    CollectionResource resource = mock(CollectionResource.class);
    when(resource.getInstance()).thenReturn(gtr.getInstance());
    // Build the resource path, and extract the instance (the last element of the path)
    ResourcePath path = gtr.getPath(resource);
    String[] elements = path.elements();
    return elements[elements.length - 1];
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) ResourceType(org.opennms.netmgt.collection.api.ResourceType) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource)

Example 3 with CollectionResource

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

the class CollectionSetDTO method visit.

@Override
public void visit(CollectionSetVisitor visitor) {
    visitor.visitCollectionSet(this);
    for (CollectionResource resource : buildCollectionResources()) {
        resource.visit(visitor);
    }
    visitor.completeCollectionSet(this);
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) AbstractCollectionResource(org.opennms.netmgt.collection.support.AbstractCollectionResource)

Example 4 with CollectionResource

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

the class XmpCollector method handleTableQuery.

/* handleScalarQuery */
// handle a tabular query, save each row in its own
// collection resource
private boolean handleTableQuery(String groupName, String resourceType, CollectionAgent agent, CollectionSetBuilder collectionSetBuilder, String[] tableInfo, XmpSession session, NodeLevelResource nodeLevelResource, XmpVar[] queryVars) throws CollectionException {
    int numColumns, numRows;
    XmpMessage reply;
    int i, j;
    XmpVar[] vars;
    String targetInstance;
    numColumns = queryVars.length;
    // make sure we have an instance or * for all rows; preserve
    // passed in value as targetInstance so we know if we are
    // are going to use targetInstance for saving results or
    // use returned instance for saving values
    // if resourceType is present, we use it as a subDir in
    // our RRD dir
    targetInstance = tableInfo[2];
    if ((tableInfo[2] == null) || (tableInfo[2].length() == 0)) {
        tableInfo[2] = new String("*");
        targetInstance = null;
    }
    LOG.debug("sending table query {},{},{} target: {}", tableInfo[0], tableInfo[1], tableInfo[2], targetInstance);
    reply = session.queryTableVars(tableInfo, 0, queryVars);
    if (reply == null) {
        LOG.warn("collect: query to {} failed, {}", agent, Xmp.errorStatusToString(session.getErrorStatus()));
        return false;
    }
    vars = reply.getMIBVars();
    // we have to go through the reply and find out how 
    // many rows we have
    // for each row: create a CollectionResource of
    //               appropriate type, instance, etc.
    //               create AttributeGroup to put 
    //               the values in 
    numRows = vars.length / numColumns;
    LOG.info("query returned valid table data for {} numRows={} numColumns={}", groupName, numRows, numColumns);
    for (i = 0; i < numRows; i++) {
        String rowInstance;
        // determine instance for this row
        // we use either the rowInstance or targetInstance for
        // naming the instance for saving RRD file; if user
        // wanted all rows (blank instance), then we will use
        // the returned instance; if user specified an instance
        // we use that instance for specifying the RRD file
        // and collection resource
        rowInstance = vars[i * numColumns].getKey();
        // instead of using '*' for the nodeTypeName, use the
        // table name so that the proper rrd file is spec'd
        final String instanceName;
        if (targetInstance != null) {
            instanceName = targetInstance;
        } else {
            instanceName = rowInstance;
        }
        // node type can be "node" for scalars or
        // "if" for network interface resources and
        // "*" for all other resource types
        final String nodeTypeName = tableInfo[1];
        final Resource resource = getResource(nodeLevelResource, nodeTypeName, resourceType, instanceName);
        LOG.debug("queryTable instance={}", rowInstance);
        for (j = 0; j < numColumns; j++) {
            final XmpVar var = vars[i * numColumns + j];
            collectionSetBuilder.withAttribute(resource, groupName, var.getObjName(), var.getValue(), getType(var));
        }
    /* for each column */
    }
    return true;
}
Also used : XmpVar(org.krupczak.xmp.XmpVar) XmpMessage(org.krupczak.xmp.XmpMessage) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource)

Example 5 with CollectionResource

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

the class NewtsPersister method visitGroup.

/** {@inheritDoc} */
@Override
public void visitGroup(AttributeGroup group) {
    pushShouldPersist(group);
    if (shouldPersist()) {
        // Set the builder before any calls to persistNumericAttribute are made
        CollectionResource resource = group.getResource();
        m_builder = new NewtsPersistOperationBuilder(m_newtsWriter, m_context, m_repository, resource, group.getName());
        if (resource.getTimeKeeper() != null) {
            m_builder.setTimeKeeper(resource.getTimeKeeper());
        }
        setBuilder(m_builder);
    }
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource)

Aggregations

CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)17 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)6 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)4 RrdPersistOperationBuilder (org.opennms.netmgt.collection.persistence.rrd.RrdPersistOperationBuilder)4 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)4 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)4 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)4 AttributeGroup (org.opennms.netmgt.collection.api.AttributeGroup)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 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)3 File (java.io.File)2 Date (java.util.Date)2 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)2 Persister (org.opennms.netmgt.collection.api.Persister)2