/** * Returns a copy of this ThresholdEntity object. * * NOTE: The m_lowThreshold and m_highThreshold member variables are not * actually cloned...the returned ThresholdEntity object will simply contain * references to the same Threshold objects as the original * ThresholdEntity object. * * All state will be lost, particularly instances, so it's not a true clone by any stretch of the imagination * * @return a {@link org.opennms.netmgt.threshd.ThresholdEntity} object. */ @Override public ThresholdEntity clone() { ThresholdEntity clone = new ThresholdEntity(); for (ThresholdEvaluatorState thresholdItem : getThresholdEvaluatorStates(null)) { clone.addThreshold(thresholdItem.getThresholdConfig()); } return clone; }
private void delete(ThresholdResourceType type) { final Map<String,Set<ThresholdEntity>> entityMap = type.getThresholdMap(); for (final Entry<String, Set<ThresholdEntity>> entry : entityMap.entrySet()) { for (final ThresholdEntity e : entry.getValue()) { e.delete(); } } }
/** * Evaluates the threshold in light of the provided datasource value and * create any events for thresholds. * * Semi-deprecated method; only used for old Thresholding code (threshd and friends) * Implemented in terms of the other method with the same name and the extra param * * @param values * map of values (by datasource name) to evaluate against the threshold (might be an expression) * @param date * Date to use in created events * @return List of events */ public List<Event> evaluateAndCreateEvents(Map<String, Double> values, Date date) { return evaluateAndCreateEvents(null, values, date); }
/** * Merges the configuration and update states using parameter entity as a reference. * * @param entity a {@link org.opennms.netmgt.threshd.ThresholdEntity} object. */ public void merge(ThresholdEntity entity) { if (getThresholdConfig().equals(entity.getThresholdConfig()) == false) { sendRearmForTriggeredStates(); getThresholdConfig().merge(entity.getThresholdConfig()); } }
/** * Get datasource name * * @return a {@link java.lang.String} object. */ public String getDataSourceExpression() { if (hasThresholds()) { return getThresholdConfig().getDatasourceExpression(); } else { throw new IllegalStateException("No thresholds have been added."); } }
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; LOG.warn("fillThresholdStateMap: Could not parse threshold expression", e); if (newConfig != null && newConfig.equals(entity.getThresholdConfig())) { found = true; continue; entity.delete(); thresholdIterator.remove();
public void testThresholdEntityRequiredDataSources() throws Exception { ThresholdEntity entity=new ThresholdEntity(); expression.setExpression("(hrStorageSize-hrStorageUsed)*hrStorageAllocationUnits"); BaseThresholdDefConfigWrapper wrapper=BaseThresholdDefConfigWrapper.getConfigWrapper(expression); assertEquals(3, wrapper.getRequiredDatasources().size()); for (String ds : new String[] { "hrStorageSize", "hrStorageUsed", "hrStorageAllocationUnits" }) { assertTrue("Could not find expected variable: " + ds, wrapper.getRequiredDatasources().contains(ds)); } entity.addThreshold(wrapper); Collection<String> dataSources=entity.getRequiredDatasources(); final StringBuilder dsStringBuffer = new StringBuilder(); for (String dataSource : dataSources) { dsStringBuffer.append(dataSource).append(" "); } String dsString = dsStringBuffer.toString().trim(); assertTrue("Required data sources should contain hrStorageSize: " + dsString, dataSources.contains("hrStorageSize")); assertTrue("Required data sources should contain hrStorageUsed: " + dsString, dataSources.contains("hrStorageUsed")); assertTrue("Required data sources should contain hrStorageAllocationUnits: " + dsString, dataSources.contains("hrStorageAllocationUnits")); }
/** * This method is responsible for returning a String object which represents * the content of this ThresholdEntity. Primarily used for debugging * purposes. * * @return String which represents the content of this ThresholdEntity */ @Override public String toString() { if (!hasThresholds()) { return ""; } final StringBuilder buffer = new StringBuilder("{"); buffer.append("evaluator=").append(this.getThresholdConfig().getType()); buffer.append(", dsName=").append(this.getDataSourceExpression()); buffer.append(", dsType=").append(this.getDatasourceType()); buffer.append(", evaluators=["); for (ThresholdEvaluatorState item : getThresholdEvaluatorStates(null)) { buffer.append("{ds=").append(item.getThresholdConfig().getDatasourceExpression()); buffer.append(", value=").append(item.getThresholdConfig().getValue()); buffer.append(", rearm=").append(item.getThresholdConfig().getRearm()); buffer.append(", trigger=").append(item.getThresholdConfig().getTrigger()); buffer.append("}"); } buffer.append("]}"); return buffer.toString(); }
if (passedThresholdFilters(resourceWrapper, thresholdEntity)) { LOG.info("applyThresholds: Processing threshold {} : {} on resource {}", key, thresholdEntity, resourceWrapper); Collection<String> requiredDatasources = thresholdEntity.getThresholdConfig().getRequiredDatasources(); final Map<String, Double> values = new HashMap<String,Double>(); boolean valueMissing = false; boolean relaxed = thresholdEntity.getThresholdConfig().getBasethresholddef().getRelaxed(); for(final String ds : requiredDatasources) { final Double dsValue = resourceWrapper.getAttributeValue(ds); resourceWrapper.setDsLabel(thresholdEntity.getDatasourceLabel()); try { List<Event> thresholdEvents = thresholdEntity.evaluateAndCreateEvents(resourceWrapper, values, date); eventsList.addAll(thresholdEvents); } catch (Exception e) {
public boolean hasThresholds(final String resourceTypeName, final String attributeName) { boolean ok = false; synchronized(m_thresholdGroups) { for (ThresholdGroup group : m_thresholdGroups) { Map<String,Set<ThresholdEntity>> entityMap = getEntityMap(group, resourceTypeName); if (entityMap != null) { for (final Entry<String, Set<ThresholdEntity>> entry : entityMap.entrySet()) { final Set<ThresholdEntity> value = entry.getValue(); for (final ThresholdEntity thresholdEntity : value) { final Collection<String> requiredDatasources = thresholdEntity.getRequiredDatasources(); if (requiredDatasources.contains(attributeName)) { ok = true; LOG.debug("hasThresholds: {}@{}? {}", resourceTypeName, attributeName, ok); } else { LOG.trace("hasThresholds: {}@{}? {}", resourceTypeName, attributeName, ok); } } } } } } return ok; }
if (getThresholdEvaluatorStates(instance).size() > 0) { dsValue=getThresholdConfig().evaluate(values); } else { throw new IllegalStateException("No thresholds have been added."); for (ThresholdEvaluatorState item : getThresholdEvaluatorStates(instance)) { Status status = item.evaluate(dsValue); Event event = item.getEventForState(status, date, dsValue, resource);
/** * <p>addThreshold</p> * * @param threshold a {@link org.opennms.netmgt.threshd.BaseThresholdDefConfigWrapper} object. */ public void addThreshold(BaseThresholdDefConfigWrapper threshold) { ThresholdEvaluator evaluator = getEvaluatorForThreshold(threshold); //Get the default list of evaluators (the null key) List<ThresholdEvaluatorState> defaultList=m_thresholdEvaluatorStates.get(null); for (ThresholdEvaluatorState item : defaultList) { if (threshold.getType().equals(item.getThresholdConfig().getType())) { throw new IllegalStateException(threshold.getType() + " threshold already set."); } } defaultList.add(evaluator.getThresholdEvaluatorState(threshold)); }
final List<ResourceFilter> filters = thresholdEntity.getThresholdConfig().getBasethresholddef().getResourceFilters(); if (filters.size() == 0) return true; final FilterOperator operator = thresholdEntity.getThresholdConfig().getBasethresholddef().getFilterOperator(); boolean andResult = true; for (ResourceFilter f : filters) {
/** * Get datasource Label * * @return a {@link java.lang.String} object. */ public String getDatasourceLabel() { if (hasThresholds()) { return getThresholdConfig().getDsLabel().orElse(null); } else { return null; } }
/** * Get datasource type * * @return a {@link java.lang.String} object. */ public String getDatasourceType() { if (hasThresholds()) { return getThresholdConfig().getDsType(); } else { throw new IllegalStateException("No thresholds have been added."); } }
/** * Returns the names of the dataousrces required to evaluate this threshold entity * * @return Collection of the names of datasources */ public Collection<String> getRequiredDatasources() { if (hasThresholds()) { final Set<String> dataSources = new HashSet<String>(); dataSources.addAll(getThresholdConfig().getRequiredDatasources()); dataSources.addAll(getThresholdConfig().getFilterDatasources()); return dataSources; } else { throw new IllegalStateException("No thresholds have been added."); } } /**