use of org.opennms.netmgt.collection.api.AttributeGroupType in project opennms by OpenNMS.
the class RegExPropertyExtender method getTargetAttribute.
/* (non-Javadoc)
* @see org.opennms.netmgt.collectd.SnmpPropertyExtender#getTargetAttribute(java.util.List, org.opennms.netmgt.collectd.SnmpCollectionResource, org.opennms.netmgt.config.datacollection.MibObjProperty)
*/
@Override
public SnmpAttribute getTargetAttribute(List<CollectionAttribute> sourceAttributes, SnmpCollectionResource targetResource, MibObjProperty property) {
final String sourceType = property.getParameterValue(SOURCE_TYPE);
if (StringUtils.isBlank(sourceType)) {
LOG.warn("Cannot execute the RegEx property extender because: missing parameter {}", SOURCE_TYPE);
return null;
}
final String sourceAlias = property.getParameterValue(SOURCE_ALIAS);
if (StringUtils.isBlank(sourceAlias)) {
LOG.warn("Cannot execute the RegEx property extender because: missing parameter {}", SOURCE_ALIAS);
return null;
}
final String indexPattern = property.getParameterValue(INDEX_PATTERN);
if (StringUtils.isBlank(indexPattern)) {
LOG.warn("Cannot execute the RegEx property extender because: missing parameter {}", INDEX_PATTERN);
return null;
}
Pattern p = Pattern.compile(indexPattern);
Matcher m = p.matcher(targetResource.getInstance());
Optional<CollectionAttribute> target = null;
if (m.find()) {
final String index = m.group(1);
target = sourceAttributes.stream().filter(a -> matches(sourceType, sourceAlias, index, a)).findFirst();
}
if (target != null && target.isPresent()) {
AttributeGroupType groupType = targetResource.getGroupType(property.getGroupName());
if (groupType != null) {
MibPropertyAttributeType type = new MibPropertyAttributeType(targetResource.getResourceType(), property, groupType);
SnmpValue value = SnmpUtils.getValueFactory().getOctetString(target.get().getStringValue().getBytes());
return new SnmpAttribute(targetResource, type, value);
}
}
return null;
}
Aggregations