use of org.opennms.netmgt.config.threshd.Threshold in project opennms by OpenNMS.
the class ThresholdEvaluatorAbsoluteChangeTest method testEvaluateTwiceNoTrigger.
@Test
public void testEvaluateTwiceNoTrigger() {
Threshold threshold = new Threshold();
threshold.setType(ThresholdType.ABSOLUTE_CHANGE);
threshold.setDsName("ds-name");
threshold.setDsType("node");
threshold.setValue(0.9);
threshold.setRearm(0.5);
threshold.setTrigger(3);
ThresholdConfigWrapper wrapper = new ThresholdConfigWrapper(threshold);
ThresholdEvaluatorStateAbsoluteChange evaluator = new ThresholdEvaluatorStateAbsoluteChange(wrapper);
assertEquals("should not trigger", Status.NO_CHANGE, evaluator.evaluate(10.0));
assertEquals("should not trigger", Status.NO_CHANGE, evaluator.evaluate(10.0));
}
use of org.opennms.netmgt.config.threshd.Threshold in project opennms by OpenNMS.
the class ThresholdEvaluatorAbsoluteChangeTest method testGetEventForStateCustomUEIS.
@Test
public void testGetEventForStateCustomUEIS() {
String triggeredUEI = "uei.opennms.org/custom/absoluteChangeThresholdTriggered";
Threshold threshold = new Threshold();
threshold.setType(ThresholdType.ABSOLUTE_CHANGE);
threshold.setDsName("ds-name");
threshold.setDsType("node");
threshold.setValue(99.0);
threshold.setRearm(95.0);
threshold.setTrigger(1);
threshold.setTriggeredUEI(triggeredUEI);
ThresholdConfigWrapper wrapper = new ThresholdConfigWrapper(threshold);
ThresholdEvaluatorStateAbsoluteChange item = new ThresholdEvaluatorStateAbsoluteChange(wrapper);
Event event = item.getEventForState(Status.TRIGGERED, new Date(), 100.0, null);
assertEquals("UEI should be the " + triggeredUEI, triggeredUEI, event.getUei());
}
use of org.opennms.netmgt.config.threshd.Threshold in project opennms by OpenNMS.
the class ThresholdEvaluatorAbsoluteChangeTest method testEvaluateTwiceTriggerHighAbove.
@Test
public void testEvaluateTwiceTriggerHighAbove() {
Threshold threshold = new Threshold();
threshold.setType(ThresholdType.ABSOLUTE_CHANGE);
threshold.setDsName("ds-name");
threshold.setDsType("node");
threshold.setValue(1.0);
threshold.setRearm(0.5);
threshold.setTrigger(3);
ThresholdConfigWrapper wrapper = new ThresholdConfigWrapper(threshold);
ThresholdEvaluatorStateAbsoluteChange evaluator = new ThresholdEvaluatorStateAbsoluteChange(wrapper);
assertEquals("should not trigger", Status.NO_CHANGE, evaluator.evaluate(10.0));
assertEquals("should trigger", Status.TRIGGERED, evaluator.evaluate(12.0));
}
use of org.opennms.netmgt.config.threshd.Threshold 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;
}
use of org.opennms.netmgt.config.threshd.Threshold 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;
}
Aggregations