/** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if ( this == obj ) { return true; } if (obj instanceof BaseThresholdDefConfigWrapper) { final BaseThresholdDefConfigWrapper that = (BaseThresholdDefConfigWrapper)obj; return Objects.equals(this.getType(), that.getType()) && Objects.equals(this.getDsType(), that.getDsType()) && Objects.equals(this.getDatasourceExpression(), that.getDatasourceExpression()) && Objects.equals(this.getDsLabel(), that.getDsLabel()) && Objects.equals(this.getTriggeredUEI(), that.getTriggeredUEI()) && Objects.equals(this.getRearmedUEI(), that.getRearmedUEI()) && Objects.equals(this.getValue(), that.getValue()) && Objects.equals(this.getRearm(), that.getRearm()) && Objects.equals(this.getTrigger(), that.getTrigger()) && Objects.equals(this.getBasethresholddef().getFilterOperator(), that.getBasethresholddef().getFilterOperator()) && Objects.equals(this.getBasethresholddef().getRelaxed(), that.getBasethresholddef().getRelaxed()) && Objects.equals(this.getBasethresholddef().getResourceFilters(), that.getBasethresholddef().getResourceFilters()); } return false; }
public void setThresholdConfig(BaseThresholdDefConfigWrapper thresholdConfig) { Assert.notNull(thresholdConfig.getType(), "threshold must have a 'type' value set"); Assert.notNull(thresholdConfig.getDatasourceExpression(), "threshold must have a 'ds-name' value set"); Assert.notNull(thresholdConfig.getDsType(), "threshold must have a 'ds-type' value set"); Assert.isTrue(thresholdConfig.hasValue(), "threshold must have a 'value' value set"); Assert.isTrue(thresholdConfig.hasRearm(), "threshold must have a 'rearm' value set"); Assert.isTrue(thresholdConfig.hasTrigger(), "threshold must have a 'trigger' value set"); m_thresholdConfig = thresholdConfig; }
private ThresholdEvaluator getEvaluatorForThreshold(BaseThresholdDefConfigWrapper threshold) { for (ThresholdEvaluator evaluator : getThresholdEvaluators()) { if (evaluator.supportsType(threshold.getType())) { return evaluator; } } String message = "Threshold type '" + threshold.getType() + "' for "+ threshold.getDatasourceExpression() + " is not supported"; LOG.warn(message); throw new IllegalArgumentException(message); }
/** * 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(); }
BaseThresholdDefConfigWrapper wrapper=BaseThresholdDefConfigWrapper.getConfigWrapper(thresh); Set<ThresholdEntity> thresholdEntitySet = thresholdMap.get(wrapper.getDatasourceExpression()); thresholdMap.put(wrapper.getDatasourceExpression(), thresholdEntitySet); boolean updated = false; for (ThresholdEntity e : thresholdEntitySet) { if (thresholdEntity.getThresholdConfig().equals(e.getThresholdConfig())) { e.merge(thresholdEntity); updated = true; LOG.warn("fillThresholdStateMap: Encountered duplicate {} for datasource {}", thresh.getType(), wrapper.getDatasourceExpression(), e); 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;
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")); }
private Event createBasicEvent(String uei, Date date, double dsValue, CollectionResourceWrapper resource) { Map<String,String> params = new HashMap<String,String>(); params.put("threshold", Double.toString(getThresholdConfig().getValue())); params.put("trigger", Integer.toString(getThresholdConfig().getTrigger())); params.put("rearm", Double.toString(getThresholdConfig().getRearm())); return createBasicEvent(uei, date, dsValue, resource, params); }
/** * 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."); } } /**
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);
protected boolean isRearmExceeded(double dsValue) { if (ThresholdType.HIGH.equals(getThresholdConfig().getType())) { return dsValue <= getThresholdConfig().getRearm(); } else if (ThresholdType.LOW.equals(getThresholdConfig().getType())) { return dsValue >= getThresholdConfig().getRearm(); } else { throw new IllegalStateException("This thresholding strategy can only be used for thresholding types of 'high' and 'low'."); } }
/** * 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()); } }
EventBuilder bldr = new EventBuilder(uei, "OpenNMS.Threshd." + getThresholdConfig().getDatasourceExpression(), date); bldr.addParam("ds", getThresholdConfig().getDatasourceExpression()); final String descr = getThresholdConfig().getBasethresholddef().getDescription().orElse(getThresholdConfig().getDatasourceExpression()); bldr.addParam("description", descr);
/** * <p>merge</p> * * @param threshold a {@link org.opennms.netmgt.threshd.BaseThresholdDefConfigWrapper} object. */ public void merge(BaseThresholdDefConfigWrapper threshold) { m_baseDef = threshold.getBasethresholddef(); }
/** * 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 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."); } }
/** * 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."); } }
dsValue=getThresholdConfig().evaluate(values); } else { throw new IllegalStateException("No thresholds have been added.");
public void setThresholdConfig(BaseThresholdDefConfigWrapper thresholdConfig) { Assert.notNull(thresholdConfig.getType(), "threshold must have a 'type' value set"); Assert.notNull(thresholdConfig.getDatasourceExpression(), "threshold must have a 'ds-name' value set"); Assert.notNull(thresholdConfig.getDsType(), "threshold must have a 'ds-type' value set"); Assert.isTrue(thresholdConfig.hasValue(), "threshold must have a 'value' value set"); Assert.isTrue(thresholdConfig.hasRearm(), "threshold must have a 'rearm' value set"); Assert.isTrue(thresholdConfig.hasTrigger(), "threshold must have a 'trigger' value set"); Assert.isTrue(TYPE.equals(thresholdConfig.getType()), "threshold for ds-name '" + thresholdConfig.getDatasourceExpression() + "' has type of '" + thresholdConfig.getType() + "', but this evaluator only supports thresholds with a 'type' value of '" + TYPE + "'"); Assert.isTrue(!Double.isNaN(thresholdConfig.getValue()), "threshold must have a 'value' value that is a number"); Assert.isTrue(thresholdConfig.getValue() != Double.POSITIVE_INFINITY && thresholdConfig.getValue() != Double.NEGATIVE_INFINITY, "threshold must have a 'value' value that is not positive or negative infinity"); m_thresholdConfig = thresholdConfig; }
/** * Returns the names of the datasources required from the resource filters * * @return Collection of the names of datasources */ public List<String> getFilterDatasources() { final List<String> dataSources = new ArrayList<>(); for (ResourceFilter s : getBasethresholddef().getResourceFilters()) { dataSources.add(s.getField()); } return dataSources; }
public void setThresholdConfig(BaseThresholdDefConfigWrapper thresholdConfig) { Assert.notNull(thresholdConfig.getType(), "threshold must have a 'type' value set"); Assert.notNull(thresholdConfig.getDatasourceExpression(), "threshold must have a 'ds-name' value set"); Assert.notNull(thresholdConfig.getDsType(), "threshold must have a 'ds-type' value set"); Assert.isTrue(thresholdConfig.hasValue(), "threshold must have a 'value' value set"); Assert.isTrue(thresholdConfig.hasRearm(), "threshold must have a 'rearm' value set"); Assert.isTrue(thresholdConfig.hasTrigger(), "threshold must have a 'trigger' value set"); Assert.isTrue(TYPE.equals(thresholdConfig.getType()), "threshold for ds-name '" + thresholdConfig.getDatasourceExpression() + "' has type of '" + thresholdConfig.getType() + "', but this evaluator only supports thresholds with a 'type' value of '" + TYPE + "'"); Assert.isTrue(!Double.isNaN(thresholdConfig.getValue()), "threshold must have a 'value' value that is a number"); Assert.isTrue(thresholdConfig.getValue() != Double.POSITIVE_INFINITY && thresholdConfig.getValue() != Double.NEGATIVE_INFINITY, "threshold must have a 'value' value that is not positive or negative infinity"); Assert.isTrue(thresholdConfig.getValue() != 1.0, "threshold must not be unity (1.0)"); m_thresholdConfig = thresholdConfig; setMultiplier(thresholdConfig.getValue()); }