use of org.opennms.netmgt.config.threshd.FilterOperator in project opennms by OpenNMS.
the class ThresholdingSet method passedThresholdFilters.
/**
* <p>passedThresholdFilters</p>
*
* @param resource a {@link org.opennms.netmgt.threshd.CollectionResourceWrapper} object.
* @param thresholdEntity a {@link org.opennms.netmgt.threshd.ThresholdEntity} object.
* @return a boolean.
*/
protected boolean passedThresholdFilters(CollectionResourceWrapper resource, ThresholdEntity thresholdEntity) {
// Find the filters for threshold definition for selected group/dataSource
final List<ResourceFilter> filters = thresholdEntity.getThresholdConfig().getBasethresholddef().getResourceFilters();
if (filters.size() == 0)
return true;
// Threshold definition with filters must match ThresholdEntity (checking DataSource and ResourceType)
LOG.debug("passedThresholdFilters: applying {} filters to resource {}", filters.size(), resource);
int count = 1;
final FilterOperator operator = thresholdEntity.getThresholdConfig().getBasethresholddef().getFilterOperator();
boolean andResult = true;
for (ResourceFilter f : filters) {
LOG.debug("passedThresholdFilters: filter #{}: field={}, regex='{}'", count, f.getField(), f.getContent());
count++;
// Read Resource Attribute and apply filter rules if attribute is not null
String attr = resource.getFieldValue(f.getField());
if (attr != null) {
try {
final Pattern p = Pattern.compile(f.getContent().orElse(""));
final Matcher m = p.matcher(attr);
boolean pass = m.matches();
LOG.debug("passedThresholdFilters: the value of {} is {}. Pass filter? {}", f.getField(), attr, pass);
if (operator.equals(FilterOperator.OR) && pass) {
return true;
}
if (operator.equals(FilterOperator.AND)) {
andResult = andResult && pass;
if (andResult == false)
return false;
}
} catch (PatternSyntaxException e) {
LOG.warn("passedThresholdFilters: the regular expression {} is invalid: {}", f.getContent(), e.getMessage(), e);
return false;
}
} else {
LOG.warn("passedThresholdFilters: can't find value of {} for resource {}", f.getField(), resource);
if (operator.equals(FilterOperator.AND)) {
return false;
}
}
}
if (operator.equals(FilterOperator.AND) && andResult) {
return true;
}
return false;
}
use of org.opennms.netmgt.config.threshd.FilterOperator in project opennms by OpenNMS.
the class ThresholdController method addStandardEditingBits.
private void addStandardEditingBits(ModelAndView modelAndView) {
Map<String, String> dsTypes = new LinkedHashMap<String, String>();
dsTypes.put("node", "Node");
// "interface" is a wrong word
dsTypes.put("if", "Interface");
Collection<OnmsResourceType> resourceTypes = m_resourceDao.getResourceTypes();
Multimap<String, String> genericDsTypes = TreeMultimap.create();
for (OnmsResourceType resourceType : resourceTypes) {
if (resourceType instanceof GenericIndexResourceType) // Put these in by label to sort them, we'll get them out in a moment
{
genericDsTypes.put(resourceType.getLabel(), resourceType.getName());
}
}
// Now get the resource types out of the TreeMultimap
for (String rtLabel : genericDsTypes.keys()) {
Collection<String> rtNames = genericDsTypes.get(rtLabel);
for (String rtName : rtNames) {
if (rtNames.size() > 1) {
dsTypes.put(rtName, rtLabel + " [" + rtName + "]");
} else {
dsTypes.put(rtName, rtLabel);
}
}
}
// Finally, set the sorted resource types into the model
modelAndView.addObject("dsTypes", dsTypes);
Collection<String> thresholdTypes = new ArrayList<String>();
for (final ThresholdType tt : ThresholdType.values()) {
thresholdTypes.add(tt.getEnumName());
}
modelAndView.addObject("thresholdTypes", thresholdTypes);
Collection<String> filterOperators = new ArrayList<String>();
for (final FilterOperator fo : FilterOperator.values()) {
filterOperators.add(fo.getEnumName());
}
modelAndView.addObject("filterOperators", filterOperators);
modelAndView.addObject("saveButtonTitle", SAVE_BUTTON_TITLE);
modelAndView.addObject("cancelButtonTitle", CANCEL_BUTTON_TITLE);
modelAndView.addObject("addFilterButtonTitle", ADDFILTER_BUTTON_TITLE);
modelAndView.addObject("editButtonTitle", EDIT_BUTTON_TITLE);
modelAndView.addObject("deleteButtonTitle", DELETE_BUTTON_TITLE);
modelAndView.addObject("updateButtonTitle", UPDATE_BUTTON_TITLE);
modelAndView.addObject("moveUpButtonTitle", MOVEUP_BUTTON_TITLE);
modelAndView.addObject("moveDownButtonTitle", MOVEDOWN_BUTTON_TITLE);
}
Aggregations