Search in sources :

Example 6 with CollectionAttribute

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

the class CollectionResourceWrapperIT method testGetGaugeValue.

@Test
public void testGetGaugeValue() throws Exception {
    // Create Resource
    SnmpCollectionAgent agent = createCollectionAgent();
    SnmpCollectionResource resource = createNodeResource(agent);
    // Add Gauge Attribute
    Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
    SnmpAttribute attribute = addAttributeToCollectionResource(resource, "myGauge", AttributeType.GAUGE, "0", "100");
    attributes.put(attribute.getName(), attribute);
    // Create Wrapper
    CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
    // Get gauge value 3 times
    Assert.assertEquals(Double.valueOf(100.0), wrapper.getAttributeValue("myGauge"));
    Assert.assertEquals(Double.valueOf(100.0), wrapper.getAttributeValue("myGauge"));
    Assert.assertEquals(Double.valueOf(100.0), wrapper.getAttributeValue("myGauge"));
    EasyMock.verify(agent);
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) Test(org.junit.Test)

Example 7 with CollectionAttribute

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

the class BasePersisterTest method testPersistStringAttributeWithParentDirectory.

@Test
public void testPersistStringAttributeWithParentDirectory() throws Exception {
    initPersister();
    File nodeDir = m_fileAnticipator.tempDir(getSnmpRrdDirectory(), m_node.getId().toString());
    m_fileAnticipator.expecting(nodeDir, RrdResourceAttributeUtils.STRINGS_PROPERTIES_FILE_NAME);
    CollectionAttribute attribute = buildStringAttribute();
    m_persister.persistStringAttribute(attribute);
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) File(java.io.File) Test(org.junit.Test)

Example 8 with CollectionAttribute

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

the class BasePersisterTest method testPersistStringAttributeWithExistingPropertiesFile.

@Test
public void testPersistStringAttributeWithExistingPropertiesFile() throws Exception {
    initPersister();
    File nodeDir = m_fileAnticipator.tempDir(getSnmpRrdDirectory(), m_node.getId().toString());
    m_fileAnticipator.tempFile(nodeDir, RrdResourceAttributeUtils.STRINGS_PROPERTIES_FILE_NAME, "#just a test");
    CollectionAttribute attribute = buildStringAttribute();
    m_persister.persistStringAttribute(attribute);
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) File(java.io.File) Test(org.junit.Test)

Example 9 with CollectionAttribute

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

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

the class LatencyThresholdingSet method applyThresholds.

/*
     * Apply thresholds definitions for specified service using attributesMap as current values.
     * Return a list of events to be send if some thresholds must be triggered or be rearmed.
     */
/** {@inheritDoc} */
public List<Event> applyThresholds(String svcName, Map<String, Double> attributes) {
    LatencyCollectionResource latencyResource = new LatencyCollectionResource(svcName, m_hostAddress, m_location);
    LatencyCollectionAttributeType latencyType = new LatencyCollectionAttributeType();
    Map<String, CollectionAttribute> attributesMap = new HashMap<String, CollectionAttribute>();
    for (final Entry<String, Double> entry : attributes.entrySet()) {
        final String ds = entry.getKey();
        attributesMap.put(ds, new LatencyCollectionAttribute(latencyResource, latencyType, ds, entry.getValue()));
    }
    //The timestamp is irrelevant; latency is never a COUNTER (which is the only reason the date is used).  
    //Yes, we have to know a little too much about the implementation details of CollectionResourceWrapper to say that, but
    // we have little choice
    CollectionResourceWrapper resourceWrapper = new CollectionResourceWrapper(new Date(), m_nodeId, m_hostAddress, m_serviceName, m_repository, latencyResource, attributesMap, m_resourceStorageDao);
    return Collections.unmodifiableList(applyThresholds(resourceWrapper, attributesMap));
}
Also used : LatencyCollectionAttribute(org.opennms.netmgt.poller.LatencyCollectionAttribute) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) LatencyCollectionAttribute(org.opennms.netmgt.poller.LatencyCollectionAttribute) LatencyCollectionResource(org.opennms.netmgt.poller.LatencyCollectionResource) HashMap(java.util.HashMap) LatencyCollectionAttributeType(org.opennms.netmgt.poller.LatencyCollectionAttributeType) Date(java.util.Date)

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