use of org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status in project opennms by OpenNMS.
the class ThresholdEvaluatorHighLowTest method testEvaluateHighTriggerRearmTriggerAgain.
@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);
}
use of org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status in project opennms by OpenNMS.
the class ThresholdEvaluatorHighLowTest method testEvaluateHighTriggerTwice.
@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);
}
use of org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status in project opennms by OpenNMS.
the class ThresholdEvaluatorHighLowTest method testEvaluateLowTriggerOnce.
@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);
}
use of org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status in project opennms by OpenNMS.
the class ThresholdEntity method evaluateAndCreateEvents.
/**
* Evaluates the threshold in light of the provided datasource value, for
* the named instance (or the generic instance if instance is null) and
* create any events for thresholds.
*
* @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
* @param resource a {@link org.opennms.netmgt.threshd.CollectionResourceWrapper} object.
*/
public List<Event> evaluateAndCreateEvents(CollectionResourceWrapper resource, Map<String, Double> values, Date date) {
List<Event> events = new LinkedList<Event>();
double dsValue = 0.0;
String instance = resource != null ? resource.getInstance() : null;
try {
if (getThresholdEvaluatorStates(instance).size() > 0) {
dsValue = getThresholdConfig().evaluate(values);
} else {
throw new IllegalStateException("No thresholds have been added.");
}
} catch (ThresholdExpressionException e) {
LOG.warn("Failed to evaluate: ", e);
//No events to report
return events;
}
LOG.debug("evaluate: value= {} against threshold: {}", dsValue, this);
for (ThresholdEvaluatorState item : getThresholdEvaluatorStates(instance)) {
Status status = item.evaluate(dsValue);
Event event = item.getEventForState(status, date, dsValue, resource);
if (event != null) {
events.add(event);
}
}
return events;
}
use of org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status in project opennms by OpenNMS.
the class ThresholdEvaluatorHighLowTest method testIsTriggerCountExceededNotAfterReArm.
@Test
public void testIsTriggerCountExceededNotAfterReArm() {
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);
ThresholdEvaluatorStateHighLow item = new ThresholdEvaluatorStateHighLow(wrapper);
assertFalse("trigger count should not be exeeded before exceeding value", item.isTriggerCountExceeded());
Status status = item.evaluate(100.0);
assertEquals("first threshold evaluation status", Status.TRIGGERED, status);
assertTrue("trigger count should be exeeded after exceeding value", item.isTriggerCountExceeded());
status = item.evaluate(0.0);
assertEquals("first threshold evaluation status", Status.RE_ARMED, status);
assertFalse("trigger count should be reset after being rearmed", item.isTriggerCountExceeded());
}
Aggregations