use of org.opennms.netmgt.collection.api.AttributeType 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);
}
Aggregations