Search in sources :

Example 21 with CollectionResource

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

the class RrdPersistOperationBuilderTest method testCommitWithDeclaredAttribute.

@Test
public void testCommitWithDeclaredAttribute() 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.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 22 with CollectionResource

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

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