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