Search in sources :

Example 11 with ThresholdingConfigFactory

use of org.opennms.netmgt.config.ThresholdingConfigFactory in project opennms by OpenNMS.

the class ThresholdingVisitorIT method initFactories.

private void initFactories(String threshd, String thresholds) throws Exception {
    LOG.info("Initialize Threshold Factories");
    ThresholdingConfigFactory.setInstance(new ThresholdingConfigFactory(getClass().getResourceAsStream(thresholds)));
    ThreshdConfigFactory.setInstance(new ThreshdConfigFactory(getClass().getResourceAsStream(threshd), "127.0.0.1", false));
}
Also used : ThreshdConfigFactory(org.opennms.netmgt.config.ThreshdConfigFactory) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Example 12 with ThresholdingConfigFactory

use of org.opennms.netmgt.config.ThresholdingConfigFactory in project opennms by OpenNMS.

the class ThresholdController method deleteThreshold.

private ModelAndView deleteThreshold(String thresholdIndexString, String groupName) throws ServletException {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    ModelAndView modelAndView;
    if (thresholdIndexString == null) {
        throw new ServletException("thresholdIndex parameter required to delete a threshold");
    }
    int thresholdIndex = WebSecurityUtils.safeParseInt(thresholdIndexString);
    Group group = configFactory.getGroup(groupName);
    group.removeThreshold(group.getThresholds().get(thresholdIndex));
    //and setup the group view again
    modelAndView = new ModelAndView("admin/thresholds/editGroup");
    modelAndView.addObject("group", configFactory.getGroup(groupName));
    saveChanges();
    return modelAndView;
}
Also used : ServletException(javax.servlet.ServletException) Group(org.opennms.netmgt.config.threshd.Group) ModelAndView(org.springframework.web.servlet.ModelAndView) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Example 13 with ThresholdingConfigFactory

use of org.opennms.netmgt.config.ThresholdingConfigFactory in project opennms by OpenNMS.

the class ThresholdController method deleteExpression.

private ModelAndView deleteExpression(String expressionIndexString, String groupName) throws ServletException {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    ModelAndView modelAndView;
    if (expressionIndexString == null) {
        throw new ServletException("expressionIndex parameter required to delete a threshold expression");
    }
    int expressionIndex = WebSecurityUtils.safeParseInt(expressionIndexString);
    Group group = configFactory.getGroup(groupName);
    group.removeExpression(group.getExpressions().get(expressionIndex));
    saveChanges();
    //and setup the group view again
    modelAndView = new ModelAndView("admin/thresholds/editGroup");
    modelAndView.addObject("group", configFactory.getGroup(groupName));
    return modelAndView;
}
Also used : ServletException(javax.servlet.ServletException) Group(org.opennms.netmgt.config.threshd.Group) ModelAndView(org.springframework.web.servlet.ModelAndView) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Example 14 with ThresholdingConfigFactory

use of org.opennms.netmgt.config.ThresholdingConfigFactory in project opennms by OpenNMS.

the class ThresholdController method gotoNewExpression.

private ModelAndView gotoNewExpression(String groupName) {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    final Group group = configFactory.getGroup(groupName);
    final List<Expression> expressions = group.getExpressions();
    //We're assuming that adding a expression puts it at the end of the current list (i.e. that the Group implementation
    // uses a simple List structure, probably ArrayList).  We can be a bit cleverer later on and check though, so we should
    int expressionIndex = expressions.size();
    //Check if last expression has expression def. If not, we assume that is a new definition (not saved yet on thresholds.xml)
    Expression expression = null;
    if (expressionIndex > 0) {
        expression = expressions.get(expressionIndex - 1);
        if (expression.getExpression() == null || expression.getExpression().equals("")) {
            expressionIndex--;
        } else {
            expression = null;
        }
    }
    // create a new expression object
    if (expression == null) {
        expression = new Expression();
        //Set the two default values which need to be set for the UI to work properly
        expression.setDsType("node");
        expression.setType(ThresholdType.HIGH);
        //Default to 1 - 0 will give an error, so we may as well be helpful
        expression.setTrigger(1);
        group.addExpression(expression);
    }
    //Double check the guess index, just in case:
    if (expression != expressions.get(expressionIndex)) {
        //Ok, our guesses on indexing were completely wrong.  Failover and check each threshold in the group
        for (int i = 0; i < expressions.size(); i++) {
            if (expression == expressions.get(i)) {
                expressionIndex = i;
                //out of the for loop
                break;
            }
        }
    }
    ModelAndView modelAndView;
    modelAndView = new ModelAndView("admin/thresholds/editExpression");
    modelAndView.addObject("expression", expression);
    modelAndView.addObject("expressionIndex", expressionIndex);
    modelAndView.addObject("groupName", groupName);
    modelAndView.addObject("isNew", true);
    addStandardEditingBits(modelAndView);
    return modelAndView;
}
Also used : Group(org.opennms.netmgt.config.threshd.Group) Expression(org.opennms.netmgt.config.threshd.Expression) ModelAndView(org.springframework.web.servlet.ModelAndView) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Example 15 with ThresholdingConfigFactory

use of org.opennms.netmgt.config.ThresholdingConfigFactory in project opennms by OpenNMS.

the class ThresholdController method gotoGroupEdit.

private ModelAndView gotoGroupEdit(String groupName) {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    ModelAndView modelAndView = new ModelAndView("admin/thresholds/editGroup");
    modelAndView.addObject("group", configFactory.getGroup(groupName));
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Aggregations

ThresholdingConfigFactory (org.opennms.netmgt.config.ThresholdingConfigFactory)15 ModelAndView (org.springframework.web.servlet.ModelAndView)10 ServletException (javax.servlet.ServletException)8 Group (org.opennms.netmgt.config.threshd.Group)7 ArrayList (java.util.ArrayList)3 Expression (org.opennms.netmgt.config.threshd.Expression)3 Threshold (org.opennms.netmgt.config.threshd.Threshold)3 File (java.io.File)2 List (java.util.List)2 Before (org.junit.Before)2 DefaultServiceCollectorRegistry (org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry)2 PollOutagesConfigFactory (org.opennms.netmgt.config.PollOutagesConfigFactory)2 ThreshdConfigFactory (org.opennms.netmgt.config.ThreshdConfigFactory)2 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 MockTransactionTemplate (org.opennms.netmgt.dao.mock.MockTransactionTemplate)2 FilterDao (org.opennms.netmgt.filter.api.FilterDao)2 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 Resource (org.springframework.core.io.Resource)2