Search in sources :

Example 6 with Group

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

the class ThresholdController method finishExpressionEdit.

private ModelAndView finishExpressionEdit(HttpServletRequest request) throws ServletException {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    ModelAndView modelAndView;
    String groupName = request.getParameter("groupName");
    String submitAction = request.getParameter("submitAction");
    Group group = configFactory.getGroup(groupName);
    String expressionIndexString = request.getParameter("expressionIndex");
    if (expressionIndexString == null) {
        throw new ServletException("expressionIndex parameter required to modify or delete a threshold expression");
    }
    int expressionIndex = WebSecurityUtils.safeParseInt(expressionIndexString);
    Expression expression = group.getExpressions().get(expressionIndex);
    if (SAVE_BUTTON_TITLE.equals(submitAction)) {
        this.commonFinishEdit(request, expression);
        final String expDef = request.getParameter("expression");
        final String filterOperator = request.getParameter("filterOperator");
        if (expDef == null || expDef.equals("")) {
            throw new ServletException("expression content cannot be null or empty string");
        }
        expression.setExpression(expDef);
        expression.setFilterOperator(filterOperator == null ? null : FilterOperator.valueOf(filterOperator.toUpperCase()));
        saveChanges();
    } else if (CANCEL_BUTTON_TITLE.equals(submitAction)) {
        String isNew = request.getParameter("isNew");
        if ("true".equals(isNew)) {
            // It was a new Threshold, but the user hit cancel.  Remove the new threshold from the group
            group.removeExpression(expression);
        } else {
            List<ResourceFilter> filters = getFilterList(request, false);
            if (filters != null) {
                expression.setResourceFilters(filters);
            }
        }
    } else {
        return finishThresholdFilterEdit(request, expression);
    }
    // Remove Filters from Session
    setFilterList(request, null);
    // and got back to the editGroup page
    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) Expression(org.opennms.netmgt.config.threshd.Expression) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) List(java.util.List) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Example 7 with Group

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

the class ThresholdingConfigFactory method initGroupMap.

/**
 * Build map of org.opennms.netmgt.config.threshd.Group objects
 * indexed by group name.
 *
 * This is parsed and built at initialization for
 * faster processing at run-timne.
 */
private void initGroupMap() {
    Map<String, Group> groupMap = new HashMap<String, Group>();
    for (Group g : m_config.getGroups()) {
        groupMap.put(g.getName(), g);
    }
    m_groupMap = groupMap;
}
Also used : Group(org.opennms.netmgt.config.threshd.Group) HashMap(java.util.HashMap)

Example 8 with Group

use of org.opennms.netmgt.config.threshd.Group 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 9 with Group

use of org.opennms.netmgt.config.threshd.Group 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 10 with Group

use of org.opennms.netmgt.config.threshd.Group 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)

Aggregations

Group (org.opennms.netmgt.config.threshd.Group)10 ThresholdingConfigFactory (org.opennms.netmgt.config.ThresholdingConfigFactory)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 ServletException (javax.servlet.ServletException)5 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Expression (org.opennms.netmgt.config.threshd.Expression)2 Threshold (org.opennms.netmgt.config.threshd.Threshold)2 File (java.io.File)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 Basethresholddef (org.opennms.netmgt.config.threshd.Basethresholddef)1