use of org.opennms.netmgt.mock.MockDataCollectionConfig in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method testNumericFields.
@Test
public void testNumericFields() throws Exception {
SnmpCollectionAgent agent = createCollectionAgent();
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
ResourceType rt = new ResourceType();
rt.setName("dskIndex");
rt.setLabel("Disk Table Index (UCD-SNMP MIB)");
StorageStrategy strategy = new StorageStrategy();
strategy.setClazz("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
strategy.addParameter(new Parameter("sibling-column-name", "ns-dskPath"));
strategy.addParameter(new Parameter("replace-first", "s/^-$/_root_fs/"));
strategy.addParameter(new Parameter("replace-all", "s/^-//"));
strategy.addParameter(new Parameter("replace-all", "s/\\s//"));
strategy.addParameter(new Parameter("replace-all", "s/:\\\\.*//"));
rt.setStorageStrategy(strategy);
PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
pstrategy.setClazz("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy");
rt.setPersistenceSelectorStrategy(pstrategy);
GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, collection, rt);
SnmpCollectionResource resource = new GenericIndexResource(resourceType, resourceType.getName(), new SnmpInstId(100));
SnmpAttribute total = addAttributeToCollectionResource(resource, "ns-dskTotal", AttributeType.GAUGE, "dskIndex", "10000");
SnmpAttribute used = addAttributeToCollectionResource(resource, "ns-dskUsed", AttributeType.GAUGE, "dskIndex", "5000");
SnmpAttribute label = addAttributeToCollectionResource(resource, "ns-dskPath", AttributeType.STRING, "dskIndex", "/opt");
Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
attributes.put(used.getName(), used);
attributes.put(total.getName(), total);
attributes.put(label.getName(), label);
CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
Assert.assertEquals("opt", wrapper.getInstanceLabel());
Assert.assertEquals(new Double("10000.0"), wrapper.getAttributeValue(total.getName()));
Assert.assertEquals("10000.0", wrapper.getFieldValue(total.getName()));
}
use of org.opennms.netmgt.mock.MockDataCollectionConfig 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.mock.MockDataCollectionConfig 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.mock.MockDataCollectionConfig 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.mock.MockDataCollectionConfig in project opennms by OpenNMS.
the class BasePersisterTest method buildStringAttribute.
private SnmpAttribute buildStringAttribute() {
EasyMock.expect(m_ifDao.load(m_intf.getId())).andReturn(m_intf).anyTimes();
m_easyMockUtils.replayAll();
SnmpCollectionAgent agent = DefaultCollectionAgent.create(m_intf.getId(), m_ifDao, m_transMgr);
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
NodeResourceType resourceType = new NodeResourceType(agent, collection);
SnmpCollectionResource 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);
SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
return new SnmpAttribute(resource, attributeType, SnmpUtils.getValueFactory().getOctetString("foo".getBytes()));
}
Aggregations