Search in sources :

Example 1 with Threshold

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

the class ThresholdController method gotoEditThreshold.

private ModelAndView gotoEditThreshold(String thresholdIndexString, String groupName) throws ServletException {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    ModelAndView modelAndView;
    if (thresholdIndexString == null) {
        throw new ServletException("thresholdIndex parameter required to edit a threshold");
    }
    int thresholdIndex = WebSecurityUtils.safeParseInt(thresholdIndexString);
    Threshold threshold = configFactory.getGroup(groupName).getThresholds().get(thresholdIndex);
    modelAndView = new ModelAndView("admin/thresholds/editThreshold");
    modelAndView.addObject("threshold", threshold);
    modelAndView.addObject("thresholdIndex", thresholdIndex);
    modelAndView.addObject("groupName", groupName);
    modelAndView.addObject("isNew", false);
    addStandardEditingBits(modelAndView);
    return modelAndView;
}
Also used : ServletException(javax.servlet.ServletException) ModelAndView(org.springframework.web.servlet.ModelAndView) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory) Threshold(org.opennms.netmgt.config.threshd.Threshold)

Example 2 with Threshold

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

the class ThresholdController method finishThresholdFilterEdit.

private ModelAndView finishThresholdFilterEdit(HttpServletRequest request, Basethresholddef threshold) throws ServletException {
    boolean isExpression = threshold instanceof Expression;
    int thresholdIndex;
    if (isExpression) {
        thresholdIndex = WebSecurityUtils.safeParseInt(request.getParameter("expressionIndex"));
    } else {
        thresholdIndex = WebSecurityUtils.safeParseInt(request.getParameter("thresholdIndex"));
    }
    ModelAndView modelAndView;
    if (isExpression) {
        modelAndView = new ModelAndView("admin/thresholds/editExpression");
    } else {
        modelAndView = new ModelAndView("admin/thresholds/editThreshold");
    }
    List<ResourceFilter> saved = getFilterList(request, true);
    if (saved == null || saved.size() == 0) {
        saved = new ArrayList<ResourceFilter>(threshold.getResourceFilters());
        setFilterList(request, saved);
    }
    String stringIndex = request.getParameter("filterSelected");
    int filterIndex = stringIndex != null && !stringIndex.equals("") ? WebSecurityUtils.safeParseInt(stringIndex) - 1 : 0;
    /*
         * Save Threshold Filters on HTTP Session in order to restore the original list if user clicks on "Cancel"
         */
    String submitAction = request.getParameter("submitAction");
    if (ADDFILTER_BUTTON_TITLE.equals(submitAction)) {
        String field = request.getParameter("filterField");
        String content = request.getParameter("filterRegexp");
        if (field != null && !field.equals("") && content != null && !content.equals("")) {
            ResourceFilter filter = new ResourceFilter();
            filter.setField(field);
            filter.setContent(content);
            threshold.addResourceFilter(filter);
        }
    } else if (DELETE_BUTTON_TITLE.equals(submitAction)) {
        threshold.getResourceFilters().remove(filterIndex);
    } else if (EDIT_BUTTON_TITLE.equals(submitAction)) {
        modelAndView.addObject("filterSelected", request.getParameter("filterSelected"));
    } else if (UPDATE_BUTTON_TITLE.equals(submitAction)) {
        ResourceFilter filter = (ResourceFilter) threshold.getResourceFilters().get(filterIndex);
        filter.setField(request.getParameter("updateFilterField"));
        filter.setContent(request.getParameter("updateFilterRegexp"));
    } else if (MOVEUP_BUTTON_TITLE.equals(submitAction)) {
        moveThresholdFilter(threshold, filterIndex, filterIndex - 1);
    } else if (MOVEDOWN_BUTTON_TITLE.equals(submitAction)) {
        moveThresholdFilter(threshold, filterIndex, filterIndex + 1);
    }
    commonFinishEdit(request, threshold);
    if (isExpression) {
        ((Expression) threshold).setExpression(request.getParameter("expression"));
    } else {
        ((Threshold) threshold).setDsName(request.getParameter("dsName"));
    }
    String isNew = request.getParameter("isNew");
    if ("true".equals(isNew)) {
        modelAndView.addObject("isNew", true);
    }
    if (isExpression) {
        modelAndView.addObject("expression", threshold);
        modelAndView.addObject("expressionIndex", thresholdIndex);
    } else {
        modelAndView.addObject("threshold", threshold);
        modelAndView.addObject("thresholdIndex", thresholdIndex);
    }
    modelAndView.addObject("groupName", request.getParameter("groupName"));
    addStandardEditingBits(modelAndView);
    return modelAndView;
}
Also used : ResourceFilter(org.opennms.netmgt.config.threshd.ResourceFilter) Expression(org.opennms.netmgt.config.threshd.Expression) ModelAndView(org.springframework.web.servlet.ModelAndView) Threshold(org.opennms.netmgt.config.threshd.Threshold)

Example 3 with Threshold

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

the class ThresholdEvaluatorHighLowTest method testEvaluateHighNoTrigger.

@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);
}
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 4 with Threshold

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

the class ThresholdEvaluatorRelativeChangeTest method testConstructor.

@Test
public void testConstructor() {
    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);
    new ThresholdEvaluatorStateRelativeChange(wrapper);
}
Also used : ThresholdEvaluatorStateRelativeChange(org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange) Threshold(org.opennms.netmgt.config.threshd.Threshold) Test(org.junit.Test)

Example 5 with Threshold

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

the class ThresholdEvaluatorRelativeChangeTest method testNegativeNumberNotTriggers.

@Test
public void testNegativeNumberNotTriggers() {
    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 not trigger", Status.NO_CHANGE, evaluator.evaluate(-10.5));
}
Also used : ThresholdEvaluatorStateRelativeChange(org.opennms.netmgt.threshd.ThresholdEvaluatorRelativeChange.ThresholdEvaluatorStateRelativeChange) 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