Search in sources :

Example 6 with CollectionResource

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

the class RrdPersistOperationBuilderTest method testCommitWithDeclaredAttributeAndNullValue.

@Test
public void testCommitWithDeclaredAttributeAndNullValue() throws Exception {
    RrdRepository repository = createRrdRepository();
    SnmpCollectionAgent agent = getCollectionAgent();
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    NodeResourceType resourceType = new NodeResourceType(agent, collection);
    CollectionResource resource = new NodeInfo(resourceType, agent);
    MibObject mibObject = new MibObject();
    mibObject.setOid(".1.1.1.1");
    mibObject.setAlias("mibObjectAlias");
    mibObject.setType("string");
    mibObject.setInstance("0");
    mibObject.setMaxval(null);
    mibObject.setMinval(null);
    SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection, m_locationAwareSnmpClient);
    SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes())));
    RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false);
    builder.declareAttribute(attributeType);
    builder.setAttributeValue(attributeType, null);
    builder.commit();
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) RrdPersistOperationBuilder(org.opennms.netmgt.collection.persistence.rrd.RrdPersistOperationBuilder) HashMap(java.util.HashMap) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) Test(org.junit.Test)

Example 7 with CollectionResource

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

the class RrdPersistOperationBuilderTest method testCommitWithDeclaredAttributeAndValue.

@Test
public void testCommitWithDeclaredAttributeAndValue() throws Exception {
    File nodeDir = m_fileAnticipator.expecting(getSnmpRrdDirectory(), m_node.getId().toString());
    m_fileAnticipator.expecting(nodeDir, "rrdName" + m_rrdStrategy.getDefaultFileExtension());
    m_fileAnticipator.expecting(nodeDir, "rrdName" + ".meta");
    RrdRepository repository = createRrdRepository();
    SnmpCollectionAgent agent = getCollectionAgent();
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    NodeResourceType resourceType = new NodeResourceType(agent, collection);
    CollectionResource resource = new NodeInfo(resourceType, agent);
    MibObject mibObject = new MibObject();
    mibObject.setOid(".1.1.1.1");
    mibObject.setAlias("mibObjectAlias");
    mibObject.setType("counter");
    mibObject.setInstance("0");
    mibObject.setMaxval(null);
    mibObject.setMinval(null);
    SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection, m_locationAwareSnmpClient);
    SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes())));
    RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false);
    builder.declareAttribute(attributeType);
    builder.setAttributeValue(attributeType, 6.022E23d);
    builder.commit();
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) RrdPersistOperationBuilder(org.opennms.netmgt.collection.persistence.rrd.RrdPersistOperationBuilder) HashMap(java.util.HashMap) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) MibObject(org.opennms.netmgt.config.datacollection.MibObject) File(java.io.File) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) Test(org.junit.Test)

Example 8 with CollectionResource

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

the class RrdPersistOperationBuilderTest method testCommitWithNoDeclaredAttributes.

@Test
public void testCommitWithNoDeclaredAttributes() throws Exception {
    RrdRepository repository = createRrdRepository();
    SnmpCollectionAgent agent = getCollectionAgent();
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    NodeResourceType resourceType = new NodeResourceType(agent, collection);
    CollectionResource resource = new NodeInfo(resourceType, agent);
    RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false);
    builder.commit();
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) RrdPersistOperationBuilder(org.opennms.netmgt.collection.persistence.rrd.RrdPersistOperationBuilder) HashMap(java.util.HashMap) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) Test(org.junit.Test)

Example 9 with CollectionResource

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

the class CollectableService method wrapResourcesWithTimekeeper.

public static CollectionSetVisitor wrapResourcesWithTimekeeper(CollectionSetVisitor visitor, TimeKeeper timeKeeper) {
    // Wrap the given visitor and intercept the calls to visit the resources
    final CollectionSetVisitor wrappedVisitor = new CollectionSetVisitorWrapper(visitor) {

        private CollectionResource wrappedResource;

        private CollectionAttribute wrappedAttribute;

        private AttributeGroup wrappedGroup;

        @Override
        public void visitResource(CollectionResource resource) {
            // Wrap the given resource and return the custom timekeeper
            wrappedResource = new CollectionResourceWrapper(resource) {

                @Override
                public TimeKeeper getTimeKeeper() {
                    return timeKeeper;
                }
            };
            visitor.visitResource(wrappedResource);
        }

        @Override
        public void completeResource(CollectionResource resource) {
            visitor.completeResource(wrappedResource);
        }

        @Override
        public void visitAttribute(CollectionAttribute attribute) {
            // Wrap the given attribute and return the custom resource
            wrappedAttribute = new CollectionAttributeWrapper(attribute) {

                @Override
                public CollectionResource getResource() {
                    return wrappedResource;
                }
            };
            visitor.visitAttribute(wrappedAttribute);
        }

        @Override
        public void completeAttribute(CollectionAttribute attribute) {
            visitor.completeAttribute(wrappedAttribute);
        }

        @Override
        public void visitGroup(AttributeGroup group) {
            // Wrap the given attribute group and return the custom resource
            wrappedGroup = new AttributeGroupWrapper(group) {

                @Override
                public CollectionResource getResource() {
                    return wrappedResource;
                }
            };
            visitor.visitGroup(wrappedGroup);
        }

        @Override
        public void completeGroup(AttributeGroup group) {
            visitor.completeGroup(wrappedGroup);
        }
    };
    return wrappedVisitor;
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) AttributeGroupWrapper(org.opennms.netmgt.collection.support.AttributeGroupWrapper) ConstantTimeKeeper(org.opennms.netmgt.collection.support.ConstantTimeKeeper) TimeKeeper(org.opennms.netmgt.collection.api.TimeKeeper) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) AttributeGroup(org.opennms.netmgt.collection.api.AttributeGroup) CollectionAttributeWrapper(org.opennms.netmgt.collection.support.CollectionAttributeWrapper) CollectionSetVisitorWrapper(org.opennms.netmgt.collection.support.CollectionSetVisitorWrapper) CollectionResourceWrapper(org.opennms.netmgt.collection.support.CollectionResourceWrapper)

Example 10 with CollectionResource

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

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