Search in sources :

Example 1 with ThresholdingConfigFactory

use of org.opennms.netmgt.config.ThresholdingConfigFactory 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 ThresholdingConfigFactory

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

the class ThresholdController method saveChanges.

private void saveChanges() throws ServletException {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    try {
        configFactory.saveCurrent();
        EventBuilder ebldr = createEventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_UEI);
        ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Threshd");
        ebldr.addParam(EventConstants.PARM_CONFIG_FILE_NAME, "thresholds.xml");
        sendNotifEvent(ebldr.getEvent());
    } catch (Throwable e) {
        throw new ServletException("Could not save the changes to the threshold because " + e.getMessage(), e);
    }
    if (eventConfChanged) {
        try {
            m_eventConfDao.saveCurrent();
            sendNotifEvent(createEventBuilder(EventConstants.EVENTSCONFIG_CHANGED_EVENT_UEI).getEvent());
        } catch (Throwable e) {
            throw new ServletException("Could not save the changes to the event configuration because " + e.getMessage(), e);
        }
        eventConfChanged = false;
    }
}
Also used : ServletException(javax.servlet.ServletException) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Example 3 with ThresholdingConfigFactory

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

the class ThresholdController method gotoEditExpression.

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

Example 4 with ThresholdingConfigFactory

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

the class LatencyThresholdingSetIT 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 5 with ThresholdingConfigFactory

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

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