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);
}
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);
}
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);
}
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;
}
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));
}
Aggregations