Search in sources :

Example 6 with Status

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);
}
Also used : Status(org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status) ThresholdEvaluatorStateHighLow(org.opennms.netmgt.threshd.ThresholdEvaluatorHighLow.ThresholdEvaluatorStateHighLow) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Example 7 with 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);
}
Also used : Status(org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status) ThresholdEvaluatorStateHighLow(org.opennms.netmgt.threshd.ThresholdEvaluatorHighLow.ThresholdEvaluatorStateHighLow) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Example 8 with 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);
}
Also used : Status(org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status) ThresholdEvaluatorStateHighLow(org.opennms.netmgt.threshd.ThresholdEvaluatorHighLow.ThresholdEvaluatorStateHighLow) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Example 9 with 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;
}
Also used : Status(org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status) Event(org.opennms.netmgt.xml.event.Event) LinkedList(java.util.LinkedList)

Example 10 with Status

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());
}
Also used : Status(org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status) ThresholdEvaluatorStateHighLow(org.opennms.netmgt.threshd.ThresholdEvaluatorHighLow.ThresholdEvaluatorStateHighLow) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Aggregations

Status (org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status)12 Test (org.junit.Test)11 Threshold (org.opennms.netmgt.config.threshd.Threshold)11 ThresholdEvaluatorStateHighLow (org.opennms.netmgt.threshd.ThresholdEvaluatorHighLow.ThresholdEvaluatorStateHighLow)11 LinkedList (java.util.LinkedList)1 Event (org.opennms.netmgt.xml.event.Event)1