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