Search in sources :

Example 1 with Basethresholddef

use of org.opennms.netmgt.config.threshd.Basethresholddef in project opennms by OpenNMS.

the class ThresholdingConfigFactory method getThresholds.

/**
     * Retrieves a Collection object consisting of all the
     * org.opennms.netmgt.config.Threshold objects which make up the specified
     * thresholding group.
     *
     * @param groupName
     *            Group name to lookup
     * @return Collection consisting of all the Threshold objects for the
     *         specified group..
     * @throws java.lang.IllegalArgumentException
     *             if group name does not exist in the group map.
     */
public Collection<Basethresholddef> getThresholds(String groupName) {
    Group group = getGroup(groupName);
    Collection<Basethresholddef> result = new ArrayList<Basethresholddef>();
    result.addAll(group.getThresholds());
    result.addAll(group.getExpressions());
    return result;
}
Also used : Group(org.opennms.netmgt.config.threshd.Group) ArrayList(java.util.ArrayList) Basethresholddef(org.opennms.netmgt.config.threshd.Basethresholddef)

Example 2 with Basethresholddef

use of org.opennms.netmgt.config.threshd.Basethresholddef in project opennms by OpenNMS.

the class DefaultThresholdsDao method fillThresholdStateMap.

private void fillThresholdStateMap(String groupName, String typeName, Map<String, Set<ThresholdEntity>> thresholdMap) {
    boolean merge = !thresholdMap.isEmpty();
    for (Basethresholddef thresh : getThresholdingConfigFactory().getThresholds(groupName)) {
        // See if map entry already exists for this datasource; if not, create a new one.
        if (thresh.getDsType().equals(typeName)) {
            try {
                BaseThresholdDefConfigWrapper wrapper = BaseThresholdDefConfigWrapper.getConfigWrapper(thresh);
                Set<ThresholdEntity> thresholdEntitySet = thresholdMap.get(wrapper.getDatasourceExpression());
                // Found set for this DS type?
                if (thresholdEntitySet == null) {
                    // Nope, create a new set
                    thresholdEntitySet = new LinkedHashSet<ThresholdEntity>();
                    thresholdMap.put(wrapper.getDatasourceExpression(), thresholdEntitySet);
                }
                try {
                    ThresholdEntity thresholdEntity = new ThresholdEntity();
                    thresholdEntity.addThreshold(wrapper);
                    if (merge) {
                        boolean updated = false;
                        for (ThresholdEntity e : thresholdEntitySet) {
                            if (thresholdEntity.getThresholdConfig().equals(e.getThresholdConfig())) {
                                e.merge(thresholdEntity);
                                updated = true;
                            }
                        }
                        if (// Does not exist!
                        !updated)
                            thresholdEntitySet.add(thresholdEntity);
                    } else {
                        thresholdEntitySet.add(thresholdEntity);
                    }
                } catch (IllegalStateException e) {
                    LOG.warn("fillThresholdStateMap: Encountered duplicate {} for datasource {}", thresh.getType(), wrapper.getDatasourceExpression(), e);
                }
            } catch (ThresholdExpressionException e) {
                LOG.warn("fillThresholdStateMap: Could not parse threshold expression", e);
            }
        }
    }
    // Search for deleted configuration
    if (merge) {
        LOG.debug("fillThresholdStateMap(merge): checking if definitions that are no longer exist for group {} using type {}", groupName, typeName);
        for (final Entry<String, Set<ThresholdEntity>> entry : thresholdMap.entrySet()) {
            final Set<ThresholdEntity> value = entry.getValue();
            for (final Iterator<ThresholdEntity> thresholdIterator = value.iterator(); thresholdIterator.hasNext(); ) {
                final ThresholdEntity entity = thresholdIterator.next();
                boolean found = false;
                for (final Basethresholddef thresh : getThresholdingConfigFactory().getThresholds(groupName)) {
                    BaseThresholdDefConfigWrapper newConfig = null;
                    try {
                        newConfig = BaseThresholdDefConfigWrapper.getConfigWrapper(thresh);
                    } catch (ThresholdExpressionException e) {
                        LOG.warn("fillThresholdStateMap: Could not parse threshold expression", e);
                    }
                    if (newConfig != null && newConfig.equals(entity.getThresholdConfig())) {
                        found = true;
                        continue;
                    }
                }
                if (!found) {
                    LOG.info("fillThresholdStateMap(merge): deleting entity {}", entity);
                    entity.delete();
                    thresholdIterator.remove();
                }
            }
        }
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Basethresholddef(org.opennms.netmgt.config.threshd.Basethresholddef)

Example 3 with Basethresholddef

use of org.opennms.netmgt.config.threshd.Basethresholddef in project opennms by OpenNMS.

the class DefaultThresholdsDao method get.

private ThresholdGroup get(String name, ThresholdGroup group) {
    boolean merge = group != null;
    ThresholdGroup newGroup = new ThresholdGroup(name);
    File rrdRepository = new File(getThresholdingConfigFactory().getRrdRepository(name));
    newGroup.setRrdRepository(rrdRepository);
    ThresholdResourceType nodeType = getThresholdResourceType(name, "node", merge ? group.getNodeResourceType() : null);
    newGroup.setNodeResourceType(nodeType);
    ThresholdResourceType ifType = getThresholdResourceType(name, "if", merge ? group.getIfResourceType() : null);
    newGroup.setIfResourceType(ifType);
    for (Basethresholddef thresh : getThresholdingConfigFactory().getThresholds(name)) {
        final String id = thresh.getDsType();
        if (!(id.equals("if") || id.equals("node") || newGroup.getGenericResourceTypeMap().containsKey(id))) {
            ThresholdResourceType genericType = getThresholdResourceType(name, id, merge ? group.getGenericResourceTypeMap().get(id) : null);
            if (genericType.getThresholdMap().size() > 0) {
                LOG.info("Adding {}::{} with {} elements", name, id, genericType.getThresholdMap().size());
                newGroup.getGenericResourceTypeMap().put(id, genericType);
            }
        }
    }
    return newGroup;
}
Also used : Basethresholddef(org.opennms.netmgt.config.threshd.Basethresholddef) File(java.io.File)

Aggregations

Basethresholddef (org.opennms.netmgt.config.threshd.Basethresholddef)3 File (java.io.File)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 Group (org.opennms.netmgt.config.threshd.Group)1