/** * Static method which takes a MIB object type (counter, counter32, * octetstring, etc...) and returns the appropriate RRD data type. If the * object type cannot be mapped to an RRD type, null is returned. RRD only * supports integer data so MIB objects of type 'octetstring' are not * supported. * * @param type - * MIB object type to be mapped. * @return RRD type string or NULL object type is not supported. */ public static RrdAttributeType mapType(AttributeType type) { if (AttributeType.COUNTER.equals(type)) { return RrdAttributeType.COUNTER; } else if (AttributeType.STRING.equals(type)) { return null; } else { return RrdAttributeType.GAUGE; } }
/** * Static method which takes a MIB object type (counter, counter32, * octetstring, etc...) and returns the appropriate RRD data type. If the * object type cannot be mapped to an RRD type, null is returned. RRD only * supports integer data so MIB objects of type 'octetstring' are not * supported. * * @param type - * MIB object type to be mapped. * @return RRD type string or NULL object type is not supported. */ public static RrdAttributeType mapType(AttributeType type) { if (AttributeType.COUNTER.equals(type)) { return RrdAttributeType.COUNTER; } else if (AttributeType.STRING.equals(type)) { return null; } else { return RrdAttributeType.GAUGE; } }
@Override public boolean shouldPersist(ServiceParameters params) { return !(Boolean.FALSE.equals(disableCounterPersistence) && AttributeType.COUNTER.equals(attribute.getType())); }
public List<CollectionAttribute> getStringAttributes() { return m_groups.values().stream() .flatMap(g -> g.getAttributes().stream()) .filter(a -> a.getAttributeType() instanceof NumericCollectionAttributeType == false || AttributeType.STRING.equals(a.getAttributeType().getType())) .collect(Collectors.toList()); }
@Override public void visitAttribute(CollectionAttribute attribute) { if (AttributeType.STRING.equals(attribute.getType()) && attributeName.equals(attribute.getName())) attributeValue = attribute.getStringValue(); } }
@Override public void storeAttribute(CollectionAttribute collectionAttribute, Persister persister) { if (AttributeType.STRING.equals(attribute.getType())) { persister.persistStringAttribute(collectionAttribute); } else { persister.persistNumericAttribute(collectionAttribute); } }
if (!AttributeType.COUNTER.equals(m_attributes.get(ds).getType())) { LOG.debug("getAttributeValue: id={}, value= {}", id, current); return current;
/** {@inheritDoc} */ @Override public void persistNumericAttribute(CollectionAttribute attribute) { boolean shouldIgnorePersist = isIgnorePersist() && AttributeType.COUNTER.equals(attribute.getType()); LOG.debug("Persisting {} {}", attribute, (shouldIgnorePersist ? ". Ignoring value because of sysUpTime changed." : "")); Number value = shouldIgnorePersist ? Double.NaN : attribute.getNumericValue(); m_builder.setAttributeValue(attribute.getAttributeType(), value); m_builder.setAttributeMetadata(attribute.getMetricIdentifier(), attribute.getName()); }
if (AttributeType.COUNTER.equals(getType())) { // See NMS-7839: for RRDtool the raw counter value must be an integer. return Long.valueOf(getValue().toString());
@Override public void visitAttribute(CollectionAttribute attribute) { if (attribute.getType().equals(AttributeType.STRING)) { CollectionSetProtos.StringAttribute.Builder attributeBuilder = CollectionSetProtos.StringAttribute .newBuilder(); attributeBuilder.setValue(attribute.getStringValue()); attributeBuilder.setName(attribute.getName()); collectionSetResourceBuilder.addString(attributeBuilder); } else { CollectionSetProtos.NumericAttribute.Builder attributeBuilder = CollectionSetProtos.NumericAttribute .newBuilder(); attributeBuilder.setGroup(lastGroupName); attributeBuilder.setName(attribute.getName()); attributeBuilder.setValue(attribute.getNumericValue().longValue()); attributeBuilder.setType((attribute.getType() == AttributeType.GAUGE) ? Type.GAUGE : Type.COUNTER); collectionSetResourceBuilder.addNumeric(attributeBuilder); } }
@Override public void visitAttribute(CollectionAttribute attribute) { if (attribute.getType().equals(AttributeType.STRING)) { CollectionSetProtos.StringAttribute.Builder attributeBuilder = CollectionSetProtos.StringAttribute .newBuilder(); attributeBuilder.setValue(attribute.getStringValue()); attributeBuilder.setName(attribute.getName()); collectionSetResourceBuilder.addString(attributeBuilder); } else { CollectionSetProtos.NumericAttribute.Builder attributeBuilder = CollectionSetProtos.NumericAttribute .newBuilder(); attributeBuilder.setGroup(lastGroupName); attributeBuilder.setName(attribute.getName()); attributeBuilder.setValue(attribute.getNumericValue().longValue()); attributeBuilder.setType((attribute.getType() == AttributeType.GAUGE) ? Type.GAUGE : Type.COUNTER); collectionSetResourceBuilder.addNumeric(attributeBuilder); } }
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); }