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;
}
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;
}
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);
}
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);
}
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));
}
Aggregations