Search in sources :

Example 6 with ThresholdEvaluatorStateRelativeChange

use of org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange in project opennms by OpenNMS.

the class ThresholdEvaluatorRelativeChangeTest method testGetEventForStateTriggered.

@Test
public void testGetEventForStateTriggered() {
    Threshold threshold = new Threshold();
    threshold.setType(ThresholdType.RELATIVE_CHANGE);
    threshold.setDsName("ds-name");
    threshold.setDsType("node");
    threshold.setValue(1.1);
    threshold.setRearm(0.5);
    threshold.setTrigger(3);
    ThresholdConfigWrapper wrapper = new ThresholdConfigWrapper(threshold);
    ThresholdEvaluatorStateRelativeChange evaluator = new ThresholdEvaluatorStateRelativeChange(wrapper);
    assertEquals("should not trigger", Status.NO_CHANGE, evaluator.evaluate(8.0));
    assertEquals("should trigger", Status.TRIGGERED, evaluator.evaluate(10.0));
    // Do it once with a null instance
    Event event = evaluator.getEventForState(Status.TRIGGERED, new Date(), 10.0, null);
    assertNotNull("should have created an event", event);
    assertEquals("UEIs should be the same", EventConstants.RELATIVE_CHANGE_THRESHOLD_EVENT_UEI, event.getUei());
    assertNotNull("event should have parms", event.getParmCollection());
    parmPresentAndValueNonNull(event, "instance");
    parmPresentWithValue(event, "value", "10.0");
    parmPresentWithValue(event, "previousValue", "8.0");
    parmPresentWithValue(event, "multiplier", "1.1");
    // And again with a non-null instance
    event = evaluator.getEventForState(Status.TRIGGERED, new Date(), 10.0, new MockCollectionResourceWrapper("testInstance"));
    assertNotNull("should have created an event", event);
    assertEquals("UEIs should be the same", EventConstants.RELATIVE_CHANGE_THRESHOLD_EVENT_UEI, event.getUei());
    assertNotNull("event should have parms", event.getParmCollection());
    parmPresentWithValue(event, "instance", "testInstance");
    parmPresentWithValue(event, "value", "10.0");
    parmPresentWithValue(event, "previousValue", "8.0");
    parmPresentWithValue(event, "multiplier", "1.1");
}
Also used : Event(org.opennms.netmgt.xml.event.Event) ThresholdEvaluatorStateRelativeChange(org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange) Date(java.util.Date) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Example 7 with ThresholdEvaluatorStateRelativeChange

use of org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange in project opennms by OpenNMS.

the class ThresholdEvaluatorRelativeChangeTest method testEvaluateThriceTriggerHighFirstZero.

@Test
public void testEvaluateThriceTriggerHighFirstZero() {
    Threshold threshold = new Threshold();
    threshold.setType(ThresholdType.RELATIVE_CHANGE);
    threshold.setDsName("ds-name");
    threshold.setDsType("node");
    threshold.setValue(1.1);
    threshold.setRearm(0.5);
    threshold.setTrigger(3);
    ThresholdConfigWrapper wrapper = new ThresholdConfigWrapper(threshold);
    ThresholdEvaluatorStateRelativeChange evaluator = new ThresholdEvaluatorStateRelativeChange(wrapper);
    assertEquals("should not trigger on first evaluate", Status.NO_CHANGE, evaluator.evaluate(0.0));
    assertEquals("should not trigger on second evaluate", Status.NO_CHANGE, evaluator.evaluate(1000.0));
    assertEquals("should trigger on third evaluate", Status.TRIGGERED, evaluator.evaluate(1200.0));
}
Also used : ThresholdEvaluatorStateRelativeChange(org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Example 8 with ThresholdEvaluatorStateRelativeChange

use of org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange in project opennms by OpenNMS.

the class ThresholdEvaluatorRelativeChangeTest method testEvaluateTwiceTriggerHighAbove.

@Test
public void testEvaluateTwiceTriggerHighAbove() {
    Threshold threshold = new Threshold();
    threshold.setType(ThresholdType.RELATIVE_CHANGE);
    threshold.setDsName("ds-name");
    threshold.setDsType("node");
    threshold.setValue(1.1);
    threshold.setRearm(0.5);
    threshold.setTrigger(3);
    ThresholdConfigWrapper wrapper = new ThresholdConfigWrapper(threshold);
    ThresholdEvaluatorStateRelativeChange evaluator = new ThresholdEvaluatorStateRelativeChange(wrapper);
    assertEquals("should not trigger", Status.NO_CHANGE, evaluator.evaluate(10.0));
    assertEquals("should trigger", Status.TRIGGERED, evaluator.evaluate(12.0));
}
Also used : ThresholdEvaluatorStateRelativeChange(org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Example 9 with ThresholdEvaluatorStateRelativeChange

use of org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange in project opennms by OpenNMS.

the class ThresholdEvaluatorRelativeChangeTest method testEvaluateTwiceTriggerLowBelow.

@Test
public void testEvaluateTwiceTriggerLowBelow() {
    Threshold threshold = new Threshold();
    threshold.setType(ThresholdType.RELATIVE_CHANGE);
    threshold.setDsName("ds-name");
    threshold.setDsType("node");
    threshold.setValue(0.9);
    threshold.setRearm(0.5);
    threshold.setTrigger(3);
    ThresholdConfigWrapper wrapper = new ThresholdConfigWrapper(threshold);
    ThresholdEvaluatorStateRelativeChange evaluator = new ThresholdEvaluatorStateRelativeChange(wrapper);
    assertEquals("should not trigger", Status.NO_CHANGE, evaluator.evaluate(10.0));
    assertEquals("should trigger", Status.TRIGGERED, evaluator.evaluate(8.0));
}
Also used : ThresholdEvaluatorStateRelativeChange(org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Example 10 with ThresholdEvaluatorStateRelativeChange

use of org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange in project opennms by OpenNMS.

the class ThresholdEvaluatorRelativeChangeTest method testEvaluateTwiceNoTrigger.

@Test
public void testEvaluateTwiceNoTrigger() {
    Threshold threshold = new Threshold();
    threshold.setType(ThresholdType.RELATIVE_CHANGE);
    threshold.setDsName("ds-name");
    threshold.setDsType("node");
    threshold.setValue(0.9);
    threshold.setRearm(0.5);
    threshold.setTrigger(3);
    ThresholdConfigWrapper wrapper = new ThresholdConfigWrapper(threshold);
    ThresholdEvaluatorStateRelativeChange evaluator = new ThresholdEvaluatorStateRelativeChange(wrapper);
    assertEquals("should not trigger", Status.NO_CHANGE, evaluator.evaluate(10.0));
    assertEquals("should not trigger", Status.NO_CHANGE, evaluator.evaluate(10.0));
}
Also used : ThresholdEvaluatorStateRelativeChange(org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 ThresholdEvaluatorStateRelativeChange (org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange)19 Threshold (org.opennms.netmgt.config.threshd.Threshold)18 Date (java.util.Date)4 Event (org.opennms.netmgt.xml.event.Event)3 ThrowableAnticipator (org.opennms.test.ThrowableAnticipator)1