Search in sources :

Example 1 with Group

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

the class ThresholdingConfigFactory method init.

/**
 * Load the config from the default config file and create the singleton
 * instance of this factory.
 *
 * @exception java.io.IOException
 *                Thrown if the specified config file cannot be read
 * @throws java.io.IOException if any.
 */
public static synchronized void init() throws IOException {
    if (m_loaded) {
        // to reload, reload() will need to be called
        return;
    }
    File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.THRESHOLDING_CONF_FILE_NAME);
    LOG.debug("init: config file path: {}", cfgFile.getPath());
    ThresholdingConfigFactory tcf = new ThresholdingConfigFactory(cfgFile.getPath());
    for (String groupName : tcf.getGroupNames()) {
        Group g = tcf.getGroup(groupName);
        for (org.opennms.netmgt.config.threshd.Threshold threshold : g.getThresholds()) {
            if (threshold.getDsName().length() > ConfigFileConstants.RRD_DS_MAX_SIZE) {
                throw new IllegalStateException(String.format("ds-name '%s' in group '%s' is greater than %d characters", threshold.getDsName(), groupName, ConfigFileConstants.RRD_DS_MAX_SIZE));
            }
        }
    }
    m_singleton = tcf;
    m_loaded = true;
}
Also used : Group(org.opennms.netmgt.config.threshd.Group) File(java.io.File)

Example 2 with Group

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

the class ThresholdingConfigFactory method getThresholds.

/**
 * Retrieves a Collection object consisting of all the
 * org.opennms.netmgt.config.Threshold objects which make up the specified
 * thresholding group.
 *
 * @param groupName
 *            Group name to lookup
 * @return Collection consisting of all the Threshold objects for the
 *         specified group..
 * @throws java.lang.IllegalArgumentException
 *             if group name does not exist in the group map.
 */
public Collection<Basethresholddef> getThresholds(String groupName) {
    Group group = getGroup(groupName);
    Collection<Basethresholddef> result = new ArrayList<>();
    result.addAll(group.getThresholds());
    result.addAll(group.getExpressions());
    return result;
}
Also used : Group(org.opennms.netmgt.config.threshd.Group) ArrayList(java.util.ArrayList) Basethresholddef(org.opennms.netmgt.config.threshd.Basethresholddef)

Example 3 with Group

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

the class ThresholdController method finishThresholdEdit.

private ModelAndView finishThresholdEdit(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 thresholdIndexString = request.getParameter("thresholdIndex");
    if (thresholdIndexString == null) {
        throw new ServletException("thresholdIndex parameter required to modify or delete a threshold");
    }
    int thresholdIndex = WebSecurityUtils.safeParseInt(thresholdIndexString);
    // TODO: NMS-4249, maybe a try/catch and add default on exception?
    Threshold threshold = group.getThresholds().get(thresholdIndex);
    if (SAVE_BUTTON_TITLE.equals(submitAction)) {
        this.commonFinishEdit(request, threshold);
        final String dsName = request.getParameter("dsName");
        final String filterOperator = request.getParameter("filterOperator");
        if (dsName == null || dsName.equals("")) {
            throw new ServletException("ds-name cannot be null or empty string");
        }
        threshold.setDsName(dsName);
        threshold.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.removeThreshold(threshold);
        } else {
            List<ResourceFilter> filters = getFilterList(request, false);
            if (filters != null) {
                threshold.setResourceFilters(filters);
            }
        }
    } else {
        return finishThresholdFilterEdit(request, threshold);
    }
    // Remove Filters from Session
    setFilterList(request, null);
    // and got back to the editGroup page
    modelAndView = new ModelAndView("admin/thresholds/editGroup");
    modelAndView.addObject("group", group);
    return modelAndView;
}
Also used : ServletException(javax.servlet.ServletException) Group(org.opennms.netmgt.config.threshd.Group) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) List(java.util.List) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory) Threshold(org.opennms.netmgt.config.threshd.Threshold)

Example 4 with Group

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

the class ThresholdController method gotoGroupList.

private ModelAndView gotoGroupList() throws ServletException {
    // Otherwise we'll be dealing with questions on the mailing lists for the rest of our lives
    try {
        ThresholdingConfigFactory.reload();
    } catch (Throwable e) {
        throw new ServletException("Could not reload ThresholdingConfigFactory because " + e.getMessage(), e);
    }
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    ModelAndView modelAndView = new ModelAndView("admin/thresholds/list");
    Map<String, Group> groupMap = new TreeMap<String, Group>();
    for (String aName : configFactory.getGroupNames()) {
        groupMap.put(aName, configFactory.getGroup(aName));
    }
    modelAndView.addObject("groupMap", groupMap);
    return modelAndView;
}
Also used : ServletException(javax.servlet.ServletException) Group(org.opennms.netmgt.config.threshd.Group) ModelAndView(org.springframework.web.servlet.ModelAndView) TreeMap(java.util.TreeMap) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Example 5 with Group

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

the class ThresholdController method gotoNewThreshold.

private ModelAndView gotoNewThreshold(String groupName) {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    final Group group = configFactory.getGroup(groupName);
    final List<Threshold> thresholds = group.getThresholds();
    // We're assuming that adding a threshold 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 thresholdIndex = thresholds.size();
    // Check if last threshold has dsName. If not, we assume that is a new definition (not saved yet on thresholds.xml)
    Threshold threshold = null;
    if (thresholdIndex > 0) {
        threshold = thresholds.get(thresholdIndex - 1);
        if (threshold.getDsName() == null || threshold.getDsName().equals("")) {
            thresholdIndex--;
        } else {
            threshold = null;
        }
    }
    // create a new threshold object
    if (threshold == null) {
        threshold = new Threshold();
        // Set the two default values which need to be set for the UI to work properly
        threshold.setDsType("node");
        threshold.setType(ThresholdType.HIGH);
        // Default to 1 - 0 will give an error, so we may as well be helpful
        threshold.setTrigger(1);
        group.addThreshold(threshold);
    }
    // Double check the guess index, just in case:
    if (threshold != thresholds.get(thresholdIndex)) {
        // Ok, our guesses on indexing were completely wrong.  Failover and check each threshold in the group
        for (int i = 0; i < thresholds.size(); i++) {
            if (threshold == thresholds.get(i)) {
                thresholdIndex = i;
                // out of the for loop
                break;
            }
        }
    }
    ModelAndView modelAndView;
    modelAndView = new ModelAndView("admin/thresholds/editThreshold");
    modelAndView.addObject("threshold", threshold);
    modelAndView.addObject("thresholdIndex", thresholdIndex);
    modelAndView.addObject("groupName", groupName);
    modelAndView.addObject("isNew", true);
    addStandardEditingBits(modelAndView);
    return modelAndView;
}
Also used : Group(org.opennms.netmgt.config.threshd.Group) ModelAndView(org.springframework.web.servlet.ModelAndView) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory) Threshold(org.opennms.netmgt.config.threshd.Threshold)

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