Search in sources :

Example 11 with Threshold

use of org.opennms.netmgt.config.threshd.Threshold in project opennms by OpenNMS.

the class ThresholdEvaluatorHighLowTest method testIsTriggerCountExceededAtTriggerValueOne.

@Test
public void testIsTriggerCountExceededAtTriggerValueOne() {
    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 (and being triggered)", 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)

Example 12 with Threshold

use of org.opennms.netmgt.config.threshd.Threshold in project opennms by OpenNMS.

the class ThresholdEvaluatorHighLowTest method testConstructorThresholdNoTrigger.

@Test
public void testConstructorThresholdNoTrigger() {
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("threshold must have a 'trigger' value set"));
    Threshold threshold = new Threshold();
    threshold.setType(ThresholdType.HIGH);
    threshold.setDsName("ds-name");
    threshold.setDsType("node");
    threshold.setValue(1.0);
    threshold.setRearm(0.5);
    ThresholdConfigWrapper wrapper = new ThresholdConfigWrapper(threshold);
    try {
        new ThresholdEvaluatorStateHighLow(wrapper);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : ThresholdEvaluatorStateHighLow(org.opennms.netmgt.threshd.ThresholdEvaluatorHighLow.ThresholdEvaluatorStateHighLow) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Example 13 with Threshold

use of org.opennms.netmgt.config.threshd.Threshold in project opennms by OpenNMS.

the class ThresholdEvaluatorHighLowTest method testGetEventForStateCustomUEIS.

@Test
public void testGetEventForStateCustomUEIS() {
    String triggeredUEI = "uei.opennms.org/custom/thresholdTriggered";
    String rearmedUEI = "uei.opennms.org/custom/thresholdRearmed";
    Threshold threshold = new Threshold();
    threshold.setType(ThresholdType.HIGH);
    threshold.setDsName("ds-name");
    threshold.setDsType("node");
    threshold.setValue(99.0);
    threshold.setRearm(95.0);
    threshold.setTrigger(1);
    threshold.setTriggeredUEI(triggeredUEI);
    threshold.setRearmedUEI(rearmedUEI);
    ThresholdConfigWrapper wrapper = new ThresholdConfigWrapper(threshold);
    ThresholdEvaluatorStateHighLow item = new ThresholdEvaluatorStateHighLow(wrapper);
    Event event = item.getEventForState(Status.TRIGGERED, new Date(), 100.0, null);
    assertEquals("UEI should be the uei.opennms.org/custom/thresholdTriggered", triggeredUEI, event.getUei());
    parmPresentAndValueNonNull(event, "instance");
    event = item.getEventForState(Status.RE_ARMED, new Date(), 94.0, null);
    assertEquals("UEI should be the uei.opennms.org/custom/thresholdRearmed", rearmedUEI, event.getUei());
    parmPresentAndValueNonNull(event, "instance");
}
Also used : Event(org.opennms.netmgt.xml.event.Event) ThresholdEvaluatorStateHighLow(org.opennms.netmgt.threshd.ThresholdEvaluatorHighLow.ThresholdEvaluatorStateHighLow) Date(java.util.Date) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Example 14 with Threshold

use of org.opennms.netmgt.config.threshd.Threshold in project opennms by OpenNMS.

the class ThresholdEvaluatorHighLowTest method testIsThresholdExceededHighNotTriggeredBelow.

@Test
public void testIsThresholdExceededHighNotTriggeredBelow() {
    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("threshold should not be exceeded", item.isThresholdExceeded(98.0));
}
Also used : ThresholdEvaluatorStateHighLow(org.opennms.netmgt.threshd.ThresholdEvaluatorHighLow.ThresholdEvaluatorStateHighLow) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Example 15 with Threshold

use of org.opennms.netmgt.config.threshd.Threshold in project opennms by OpenNMS.

the class ThresholdEvaluatorHighLowTest method testIsTriggerCountExceededNotAtTriggerValueTwo.

@Test
public void testIsTriggerCountExceededNotAtTriggerValueTwo() {
    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);
    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.NO_CHANGE, status);
    assertFalse("trigger count should not be exeeded after only exceeding value once", 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

Threshold (org.opennms.netmgt.config.threshd.Threshold)68 Test (org.junit.Test)64 ThresholdEvaluatorStateHighLow (org.opennms.netmgt.threshd.ThresholdEvaluatorHighLow.ThresholdEvaluatorStateHighLow)33 ThresholdEvaluatorStateRelativeChange (org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange)18 ThresholdEvaluatorStateAbsoluteChange (org.opennms.netmgt.threshd.ThresholdEvaluatorAbsoluteChange.ThresholdEvaluatorStateAbsoluteChange)13 Status (org.opennms.netmgt.threshd.ThresholdEvaluatorState.Status)11 Date (java.util.Date)10 Event (org.opennms.netmgt.xml.event.Event)8 ThrowableAnticipator (org.opennms.test.ThrowableAnticipator)8 ModelAndView (org.springframework.web.servlet.ModelAndView)4 ThresholdingConfigFactory (org.opennms.netmgt.config.ThresholdingConfigFactory)3 ServletException (javax.servlet.ServletException)2 Group (org.opennms.netmgt.config.threshd.Group)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Expression (org.opennms.netmgt.config.threshd.Expression)1 ResourceFilter (org.opennms.netmgt.config.threshd.ResourceFilter)1