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;
}
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();
}
}
}
}
}
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;
}
Aggregations