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