/** {@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()); }
/** * Gets the attribute map. * * @param sourceAttributes the source attributes * @param type the resource type * @param objName the object name * @return the attribute map */ private Map<String, String> getAttributeMap(List<CollectionAttribute> sourceAttributes, String type, String objName) { Map<String,String> attributes = new HashMap<String,String>(); sourceAttributes.stream().filter(a -> objName.equals(a.getAttributeType().getName()) && type.equals(a.getResource().getResourceTypeName())).forEach(a -> attributes.put(a.getResource().getInstance(), a.getStringValue())); return attributes; }
/** {@inheritDoc} */ @Override public boolean shouldPersist(ServiceParameters params) { return m_wrapped.shouldPersist(params); }
@Override public void visitAttribute(CollectionAttribute attribute) { if (AttributeType.STRING.equals(attribute.getType()) && attributeName.equals(attribute.getName())) attributeValue = attribute.getStringValue(); } }
/** * Add/Update required attributes for thresholds on m_attributeMap. * This is used because {@link CollectionResource} does not have direct reference to their attributes. * (The way to get attribute is against {@link AttributeGroup} object contained on {@link CollectionResource} * implementations). */ @Override public void visitAttribute(CollectionAttribute attribute) { if (m_thresholdingSet.hasThresholds(attribute)) { String name = attribute.getName(); m_attributesMap.put(name, attribute); LOG.debug("visitAttribute: storing value {} for attribute named {}", attribute.getNumericValue() != null ? attribute.getNumericValue() : attribute.getStringValue(), name); } }
@Override public void visitAttribute(CollectionAttribute attribute) { pushShouldPersist(attribute); if (shouldPersist()) { setBuilder(createBuilder(attribute.getResource(), attribute.getName(), Collections.singleton(attribute.getAttributeType()))); storeAttribute(attribute); } }
private void addGroupToBuilder(CollectionSetBuilder builder, Resource resource, AttributeGroup group) { for (CollectionAttribute attribute : group.getAttributes()) { String value; if(!attribute.shouldPersist(params)){ continue; } else if (attribute.getAttributeType() instanceof HexStringAttributeType) { value = ((SnmpAttribute) attribute).getValue().toHexString(); } else { value = attribute.getStringValue(); } builder.withAttribute(resource, group.getName(), attribute.getName(), value, attribute.getType()); } } }
@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); } }
/** {@inheritDoc} */ @Override public void persistStringAttribute(CollectionAttribute attribute) { LOG.debug("Persisting {}", attribute); CollectionResource resource = attribute.getResource(); String value = attribute.getStringValue(); if (value == null) { LOG.info("No data collected for attribute {}. Skipping.", attribute); return; } try { ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(m_repository, resource.getPath()); persistStringAttribute(path, attribute.getName(), value); } catch(PersistException e) { LOG.error("Unable to save string attribute {}.", attribute, e); } }
/** * <p>hasThresholds</p> * * @param attribute a {@link org.opennms.netmgt.collection.api.CollectionAttribute} object. * @return a boolean. */ public boolean hasThresholds(CollectionAttribute attribute) { CollectionResource resource = attribute.getResource(); if (!isCollectionEnabled(attribute.getResource())) return false; if (resource instanceof AliasedResource && !storeByIfAlias) return false; return hasThresholds(resource.getResourceTypeName(), attribute.getName()); }
/** {@inheritDoc} */ @Override public String getName() { return m_wrapped.getName(); }
/** {@inheritDoc} */ @Override public void visitGroup(AttributeGroup group) { pushShouldPersist(group); if (shouldPersist()) { Map<String, String> dsNamesToRrdNames = new LinkedHashMap<String , String>(); for (CollectionAttribute a : group.getAttributes()) { if (a.getType().isNumeric()) { dsNamesToRrdNames.put(a.getName(), group.getName()); } } setBuilder(createBuilder(group.getResource(), group.getName(), group.getGroupType().getAttributeTypes())); ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(getRepository(), group.getResource().getPath()); m_resourceStorageDao.updateMetricToResourceMappings(path, dsNamesToRrdNames); } }
/** {@inheritDoc} */ @Override public CollectionAttributeType getAttributeType() { return m_wrapped.getAttributeType(); }
@Override public void visitGroup(AttributeGroup group) { pushShouldPersist(group); if (shouldPersist()) { final String resourceId = getResourceId(group.getResource()); final String groupId = resourceId + '/' + group.getName(); LOG.debug("visitGroup: {} = {}", groupId, group.getAttributes().size()); stats.checkNode(group.getResource().getParent().getName()); stats.checkGroup(groupId); stats.checkResource(resourceId); group.getAttributes().forEach(a -> { final String attribId = resourceId + '/' + a.getName(); if (a.getAttributeType().getType().isNumeric()) { LOG.debug("visitGroup: attribute {}", attribId); stats.checkAttribute(attribId, true); stats.markNumericSamplesMeter(); } else { stats.checkAttribute(attribId, false); } }); setBuilder(new EvaluatorPersistOperationBuilder()); } }
return null; Number numValue = m_attributes.get(ds).getNumericValue(); if (numValue == null) { LOG.info("getAttributeValue: can't find numeric value for {} on {}", ds, m_resource); if (!AttributeType.COUNTER.equals(m_attributes.get(ds).getType())) { LOG.debug("getAttributeValue: id={}, value= {}", id, current); return current;
/** {@inheritDoc} */ @Override public CollectionResource getResource() { return m_wrapped.getResource(); }
/** {@inheritDoc} */ @Override public String getStringValue() { return m_wrapped.getStringValue(); }
/** {@inheritDoc} */ @Override public AttributeType getType() { return m_wrapped.getType(); } }
/** {@inheritDoc} */ @Override public Number getNumericValue() { return m_wrapped.getNumericValue(); }
/** {@inheritDoc} */ @Override public void visitAttribute(CollectionAttribute attribute) { pushShouldPersist(attribute); if (shouldPersist()) { final RrdPersistOperationBuilder builder = createBuilder(attribute.getResource(), attribute.getName(), Collections.singleton(attribute.getAttributeType())); builder.setAttributeMetadata("GROUP", m_group); setBuilder(builder); storeAttribute(attribute); } }