use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method addAttributeToCollectionResource.
private SnmpAttribute addAttributeToCollectionResource(SnmpCollectionResource resource, String attributeName, AttributeType attributeType, String attributeInstance, String value) {
MibObject object = createMibObject(attributeType, attributeName, attributeInstance);
SnmpAttributeType objectType = null;
SnmpValue snmpValue = null;
if (AttributeType.STRING.equals(attributeType)) {
objectType = new SnmpAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)) {
@Override
public AttributeType getType() {
return AttributeType.STRING;
}
@Override
public void storeAttribute(CollectionAttribute attribute, Persister persister) {
persister.persistStringAttribute(attribute);
}
};
snmpValue = SnmpUtils.getValueFactory().getOctetString(value.getBytes());
} else {
objectType = new NumericAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
long v = Long.parseLong(value);
snmpValue = AttributeType.COUNTER.equals(attributeType) ? SnmpUtils.getValueFactory().getCounter32(v) : SnmpUtils.getValueFactory().getGauge32(v);
}
resource.setAttributeValue(objectType, snmpValue);
return new SnmpAttribute(resource, objectType, snmpValue);
}
use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method addAttributeToCollectionResource.
private SnmpAttribute addAttributeToCollectionResource(SnmpCollectionResource resource, String attributeName, AttributeType attributeType, String attributeInstance, BigInteger value) {
MibObject object = createMibObject(attributeType, attributeName, attributeInstance);
SnmpAttributeType objectType = new NumericAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
SnmpValue snmpValue = SnmpUtils.getValueFactory().getCounter64(value);
resource.setAttributeValue(objectType, snmpValue);
return new SnmpAttribute(resource, objectType, snmpValue);
}
use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method createMibObject.
private MibObject createMibObject(AttributeType type, String alias, String instance) {
MibObject mibObject = new MibObject();
mibObject.setOid(".1.1.1.1");
mibObject.setAlias(alias);
mibObject.setType(type.toString());
mibObject.setInstance(instance);
mibObject.setMaxval(null);
mibObject.setMinval(null);
return mibObject;
}
use of org.opennms.netmgt.config.datacollection.MibObject in project opennms by OpenNMS.
the class SnmpAttributeTest method testPersisting.
@Ignore
@SuppressWarnings("unchecked")
private void testPersisting(String matchValue, SnmpValue snmpValue) throws Exception {
OnmsNode node = new OnmsNode();
node.setId(3);
OnmsIpInterface ipInterface = new OnmsIpInterface();
ipInterface.setId(1);
ipInterface.setNode(node);
ipInterface.setIpAddress(InetAddressUtils.addr("192.168.1.1"));
// It used to be 3, but I think it is more correct to use getStoreDir from DefaultCollectionAgentService on DefaultCollectionAgent (NMS-7516)
expect(m_ipInterfaceDao.load(1)).andReturn(ipInterface).times(7);
expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".myLittleEasyMockedStrategyAndMe").anyTimes();
expect(m_rrdStrategy.createDefinition(isA(String.class), isA(String.class), isA(String.class), anyInt(), isAList(RrdDataSource.class), isAList(String.class))).andReturn(new Object());
m_rrdStrategy.createFile(isA(Object.class));
expect(m_rrdStrategy.openFile(isA(String.class))).andReturn(new Object());
m_rrdStrategy.updateFile(isA(Object.class), isA(String.class), matches(".*:" + matchValue));
m_rrdStrategy.closeFile(isA(Object.class));
m_mocks.replayAll();
SnmpCollectionAgent agent = DefaultCollectionAgent.create(ipInterface.getId(), m_ipInterfaceDao, new MockPlatformTransactionManager());
OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), new MockDataCollectionConfig(), m_locationAwareSnmpClient);
NodeResourceType resourceType = new NodeResourceType(agent, snmpCollection);
NodeInfo nodeInfo = resourceType.getNodeInfo();
MibObject mibObject = new MibObject();
mibObject.setOid(".1.3.6.1.4.1.12238.55.9997.4.1.2.9.116.101.109.112.95.117.108.107.111");
mibObject.setInstance("1");
mibObject.setAlias("temp_ulko");
mibObject.setType("gauge");
NumericAttributeType attributeType = new NumericAttributeType(resourceType, snmpCollection.getName(), mibObject, new AttributeGroupType("foo", AttributeGroupType.IF_TYPE_IGNORE));
attributeType.storeResult(new SnmpCollectionSet(agent, snmpCollection, m_locationAwareSnmpClient), null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), snmpValue));
RrdRepository repository = createRrdRepository();
repository.setRraList(Collections.singletonList("RRA:AVERAGE:0.5:1:2016"));
RrdPersisterFactory persisterFactory = new RrdPersisterFactory();
persisterFactory.setRrdStrategy(m_rrdStrategy);
persisterFactory.setResourceStorageDao(m_resourceStorageDao);
CollectionSetVisitor persister = persisterFactory.createPersister(new ServiceParameters(Collections.emptyMap()), repository);
final AtomicInteger count = new AtomicInteger(0);
nodeInfo.visit(new CollectionSetVisitorWrapper(persister) {
@Override
public void visitAttribute(CollectionAttribute attribute) {
super.visitAttribute(attribute);
count.incrementAndGet();
}
});
assertEquals(1, count.get());
}
use of org.opennms.netmgt.config.datacollection.MibObject 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();
}
Aggregations