Status status = item.evaluate(dsValue); Event event = item.getEventForState(status, date, dsValue, resource); if (event != null) { events.add(event);
private void sendRearmForTriggeredStates() { for (String instance : m_thresholdEvaluatorStates.keySet()) { for (ThresholdEvaluatorState state : m_thresholdEvaluatorStates.get(instance)) { if (state.isTriggered()) { Event e = state.getEventForState(Status.RE_ARMED, new Date(), Double.NaN, null); Parm p = new Parm(); p.setParmName("reason"); Value v = new Value(); v.setContent("Configuration has been changed"); p.setValue(v); e.addParm(p); LOG.info("sendRearmForTriggeredStates: sending rearm for {}", e); ThresholdingEventProxyFactory.getFactory().getProxy().add(e); state.clearState(); } } } }
/** * Returns the evaluator states *for the given instance. * * @param instance The key to use to identify the instance to get states for. Can be null to get the default instance * @return a {@link java.util.List} object. */ public List<ThresholdEvaluatorState> getThresholdEvaluatorStates(String instance) { List<ThresholdEvaluatorState> result= m_thresholdEvaluatorStates.get(instance); if(result==null) { //There is no set of evaluators for this instance; create a list by copying the base ones List<ThresholdEvaluatorState> defaultList=m_thresholdEvaluatorStates.get(null); //Create the new list result=new LinkedList<ThresholdEvaluatorState>(); for(ThresholdEvaluatorState state: defaultList) { result.add(state.getCleanClone()); } //Store the new list with the instance as the key m_thresholdEvaluatorStates.put(instance == null ? null : instance.intern(), result); } return result; }
@Test public void testEvaluateHighTriggerTwiceNoRetrigger() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.HIGH); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(2); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThresholdEvaluatorState item = new ThresholdEvaluatorStateHighLow(wrapper); Status status = item.evaluate(100.0); assertEquals("first threshold evaluation status", Status.NO_CHANGE, status); status = item.evaluate(100.0); assertEquals("second threshold evaluation status", Status.TRIGGERED, status); status = item.evaluate(100.0); assertEquals("third threshold evaluation status", Status.NO_CHANGE, status); status = item.evaluate(100.0); assertEquals("fourth threshold evaluation status", Status.NO_CHANGE, status); }
/** * <p>getThresholdConfig</p> * * @return a {@link org.opennms.netmgt.threshd.BaseThresholdDefConfigWrapper} object. */ public BaseThresholdDefConfigWrapper getThresholdConfig() { return m_thresholdEvaluatorStates.get(null).get(0).getThresholdConfig(); }
@Test public void testEvaluateHighTriggerRearmTriggerAgain() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.HIGH); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(1); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThresholdEvaluatorState item = new ThresholdEvaluatorStateHighLow(wrapper); Status status = item.evaluate(100.0); assertEquals("first threshold evaluation status", Status.TRIGGERED, status); status = item.evaluate(0.0); assertEquals("second threshold evaluation status", Status.RE_ARMED, status); status = item.evaluate(100.0); assertEquals("third threshold evaluation status", Status.TRIGGERED, status); }
/** * 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(); }
@Test public void testEvaluateHighTriggerRearm() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.HIGH); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(1); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThresholdEvaluatorState item = new ThresholdEvaluatorStateHighLow(wrapper); Status status = item.evaluate(100.0); assertEquals("first threshold evaluation status", Status.TRIGGERED, status); status = item.evaluate(0.0); assertEquals("second threshold evaluation status", Status.RE_ARMED, status); }
/** * <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)); }
@Test public void testEvaluateHighTriggerTwice() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.HIGH); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(2); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThresholdEvaluatorState item = new ThresholdEvaluatorStateHighLow(wrapper); Status status = item.evaluate(100.0); assertEquals("first threshold evaluation status", Status.NO_CHANGE, status); status = item.evaluate(100.0); assertEquals("second threshold evaluation status", Status.TRIGGERED, status); }
/** * 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; }
@Test public void testEvaluateHighNoTrigger() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.HIGH); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(101.0); threshold.setRearm(0.5); threshold.setTrigger(1); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThresholdEvaluatorState item = new ThresholdEvaluatorStateHighLow(wrapper); Status status = item.evaluate(100.0); assertEquals("threshold evaluation status", Status.NO_CHANGE, status); }
@Test public void testEvaluateHighNoTriggerTwice() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.HIGH); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(2); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThresholdEvaluatorState item = new ThresholdEvaluatorStateHighLow(wrapper); Status status = item.evaluate(100.0); assertEquals("threshold evaluation status", Status.NO_CHANGE, status); }
@Test public void testEvaluateHighTriggerOnce() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.HIGH); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(1); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThresholdEvaluatorState item = new ThresholdEvaluatorStateHighLow(wrapper); Status status = item.evaluate(100.0); assertEquals("threshold evaluation status", Status.TRIGGERED, status); }
@Test public void testEvaluateLowTriggerOnce() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.LOW); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(1); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThresholdEvaluatorState item = new ThresholdEvaluatorStateHighLow(wrapper); Status status = item.evaluate(100.0); assertEquals("threshold evaluation status", Status.NO_CHANGE, status); }