use of org.opennms.netmgt.collection.api.CollectionAttribute in project opennms by OpenNMS.
the class MockCollectionResource method visit.
@Override
public void visit(CollectionSetVisitor visitor) {
for (Entry<String, String> entry : attributes.entrySet()) {
final CollectionResource resource = this;
final String attrName = entry.getKey();
final String attrValue = entry.getValue();
CollectionAttribute attribute = new CollectionAttribute() {
@Override
public CollectionResource getResource() {
return resource;
}
@Override
public String getStringValue() {
return attrValue;
}
@Override
public Double getNumericValue() {
try {
return Double.parseDouble(attrValue);
} catch (NumberFormatException | NullPointerException e) {
return null;
}
}
@Override
public String getName() {
return attrName;
}
@Override
public void storeAttribute(Persister persister) {
}
@Override
public boolean shouldPersist(ServiceParameters params) {
return true;
}
@Override
public CollectionAttributeType getAttributeType() {
return null;
}
@Override
public void visit(CollectionSetVisitor visitor) {
}
@Override
public AttributeType getType() {
return AttributeType.STRING;
}
@Override
public String getMetricIdentifier() {
return "MOCK_" + getName();
}
};
visitor.visitAttribute(attribute);
}
}
use of org.opennms.netmgt.collection.api.CollectionAttribute in project opennms by OpenNMS.
the class HexStringAttributeType method storeAttribute.
@Override
public void storeAttribute(CollectionAttribute attribute, Persister persister) {
CollectionAttribute attributeToPersist = attribute;
if (attribute instanceof SnmpAttribute) {
// When storing SNMP attributes alter the getStringValue() value method
// so that the hex string is returned instead of the display string
attributeToPersist = new SnmpAttributeWrapper((SnmpAttribute) attribute);
}
persister.persistStringAttribute(attributeToPersist);
}
use of org.opennms.netmgt.collection.api.CollectionAttribute 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;
}
use of org.opennms.netmgt.collection.api.CollectionAttribute in project opennms by OpenNMS.
the class AliasedGroup method visit.
/** {@inheritDoc} */
@Override
public void visit(CollectionSetVisitor visitor) {
visitor.visitGroup(this);
for (CollectionAttribute attr : getAttributes()) {
AliasedAttribute aliased = new AliasedAttribute(getResource(), (SnmpAttribute) attr);
LOG.debug("visiting at aliased = {}", aliased);
aliased.visit(visitor);
}
visitor.completeGroup(this);
}
Aggregations