use of org.opennms.web.event.filter.LogMessageSubstringFilter in project opennms by OpenNMS.
the class EventQueryServlet method doGet.
/**
* {@inheritDoc}
*
* Extracts the key parameters from the parameter set, translates them into
* filter-based parameters, and then passes the modified parameter set to
* the event filter.
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Filter> filterArray = new ArrayList<>();
// convenient syntax for LogMessageSubstringFilter
String msgSubstring = WebSecurityUtils.sanitizeString(request.getParameter("msgsub"));
if (msgSubstring != null && msgSubstring.length() > 0) {
filterArray.add(new LogMessageSubstringFilter(msgSubstring));
}
// convenient syntax for LogMessageMatchesAnyFilter
String msgMatchAny = WebSecurityUtils.sanitizeString(request.getParameter("msgmatchany"));
if (msgMatchAny != null && msgMatchAny.length() > 0) {
filterArray.add(new LogMessageMatchesAnyFilter(msgMatchAny));
}
// convenient syntax for NodeNameContainingFilter
String nodeNameLike = WebSecurityUtils.sanitizeString(request.getParameter("nodenamelike"));
if (nodeNameLike != null && nodeNameLike.length() > 0) {
filterArray.add(new NodeNameLikeFilter(nodeNameLike));
}
// convenient syntax for ExactUEIFilter
String exactUEI = WebSecurityUtils.sanitizeString(request.getParameter("exactuei"));
if (exactUEI != null && exactUEI.length() > 0) {
filterArray.add(new ExactUEIFilter(exactUEI));
}
// convenient syntax for LocationFilter
String location = WebSecurityUtils.sanitizeString(request.getParameter("location"));
if (location != null && !location.equalsIgnoreCase("any")) {
filterArray.add(new LocationFilter(WebSecurityUtils.sanitizeString(location)));
}
// convenient syntax for NodeLocationFilter
String nodeLocation = WebSecurityUtils.sanitizeString(request.getParameter("nodelocation"));
if (nodeLocation != null && !nodeLocation.equalsIgnoreCase("any")) {
filterArray.add(new NodeLocationFilter(WebSecurityUtils.sanitizeString(nodeLocation)));
}
// convenient syntax for SystemIdFilter
String systemId = WebSecurityUtils.sanitizeString(request.getParameter("systemId"));
if (systemId != null && !systemId.equalsIgnoreCase("any")) {
filterArray.add(new SystemIdFilter(WebSecurityUtils.sanitizeString(systemId)));
}
// convenient syntax for ServiceFilter
String service = WebSecurityUtils.sanitizeString(request.getParameter("service"));
if (service != null && !service.equalsIgnoreCase("any")) {
filterArray.add(new ServiceFilter(WebSecurityUtils.safeParseInt(service), this.getServletContext()));
}
// convenient syntax for IPLikeFilter
String ipLikePattern = WebSecurityUtils.sanitizeString(request.getParameter("iplike"));
if (ipLikePattern != null && !ipLikePattern.equals("")) {
filterArray.add(new IPAddrLikeFilter(ipLikePattern));
}
// convenient syntax for SeverityFilter
String severity = WebSecurityUtils.sanitizeString(request.getParameter("severity"));
if (severity != null && !severity.equalsIgnoreCase("any")) {
filterArray.add(new SeverityFilter(WebSecurityUtils.safeParseInt(severity)));
}
String eventId = WebSecurityUtils.sanitizeString(request.getParameter("eventid"));
if (eventId != null && !"".equals(eventId)) {
int eventIdInt = WebSecurityUtils.safeParseInt(eventId);
if (eventIdInt > 0) {
filterArray.add(new EventIdFilter(eventIdInt));
}
}
// convenient syntax for AfterDateFilter as relative to current time
String relativeTime = WebSecurityUtils.sanitizeString(request.getParameter("relativetime"));
if (relativeTime != null && !relativeTime.equalsIgnoreCase("any")) {
int timeInt = WebSecurityUtils.safeParseInt(relativeTime);
if (timeInt > 0) {
try {
filterArray.add(EventUtil.getRelativeTimeFilter(timeInt));
} catch (IllegalArgumentException e) {
// ignore the relative time if it is an illegal value
this.log("Illegal relativetime value", e);
}
}
}
String useBeforeTime = WebSecurityUtils.sanitizeString(request.getParameter("usebeforetime"));
if (useBeforeTime != null && useBeforeTime.equals("1")) {
try {
filterArray.add(this.getBeforeDateFilter(request));
} catch (IllegalArgumentException e) {
// ignore the before time if it is an illegal value
this.log("Illegal before time value", e);
} catch (MissingParameterException e) {
throw new ServletException(e);
}
}
String useAfterTime = WebSecurityUtils.sanitizeString(request.getParameter("useaftertime"));
if (useAfterTime != null && useAfterTime.equals("1")) {
try {
filterArray.add(this.getAfterDateFilter(request));
} catch (IllegalArgumentException e) {
// ignore the after time if it is an illegal value
this.log("Illegal after time value", e);
} catch (MissingParameterException e) {
throw new ServletException(e);
}
}
String queryString = "";
if (filterArray.size() > 0) {
String[] filterStrings = new String[filterArray.size()];
for (int i = 0; i < filterStrings.length; i++) {
Filter filter = filterArray.get(i);
filterStrings[i] = EventUtil.getFilterString(filter);
}
Map<String, Object> paramAdditions = new HashMap<String, Object>();
paramAdditions.put("filter", filterStrings);
queryString = Util.makeQueryString(request, paramAdditions, IGNORE_LIST);
} else {
queryString = Util.makeQueryString(request, IGNORE_LIST);
}
response.sendRedirect(redirectUrl + "?" + queryString);
}
use of org.opennms.web.event.filter.LogMessageSubstringFilter in project opennms by OpenNMS.
the class EventUtil method getFilter.
/**
* <p>getFilter</p>
*
* @param filterString a {@link java.lang.String} object.
* @return a org$opennms$web$filter$Filter object.
*/
public static Filter getFilter(String filterString, ServletContext servletContext) {
if (filterString == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
Filter filter = null;
StringTokenizer tokens = new StringTokenizer(filterString, "=");
String type;
String value;
try {
type = tokens.nextToken();
value = tokens.nextToken();
} catch (NoSuchElementException e) {
throw new IllegalArgumentException("Could not tokenize filter string: " + filterString);
}
if (type.equals(SeverityFilter.TYPE)) {
filter = new SeverityFilter(WebSecurityUtils.safeParseInt(value));
} else if (type.equals(NodeFilter.TYPE)) {
filter = new NodeFilter(WebSecurityUtils.safeParseInt(value), servletContext);
} else if (type.equals(NodeNameLikeFilter.TYPE)) {
filter = new NodeNameLikeFilter(value);
} else if (type.equals(InterfaceFilter.TYPE)) {
filter = new InterfaceFilter(value);
} else if (type.equals(ServiceFilter.TYPE)) {
filter = new ServiceFilter(WebSecurityUtils.safeParseInt(value), servletContext);
} else if (type.equals(IfIndexFilter.TYPE)) {
filter = new IfIndexFilter(WebSecurityUtils.safeParseInt(value));
} else if (type.equals(PartialUEIFilter.TYPE)) {
filter = new PartialUEIFilter(value);
} else if (type.equals(ExactUEIFilter.TYPE)) {
filter = new ExactUEIFilter(value);
} else if (type.equals(AcknowledgedByFilter.TYPE)) {
filter = new AcknowledgedByFilter(value);
} else if (type.equals(NegativeSeverityFilter.TYPE)) {
filter = new NegativeSeverityFilter(WebSecurityUtils.safeParseInt(value));
} else if (type.equals(NegativeNodeFilter.TYPE)) {
filter = new NegativeNodeFilter(WebSecurityUtils.safeParseInt(value), servletContext);
} else if (type.equals(NegativeInterfaceFilter.TYPE)) {
filter = new NegativeInterfaceFilter(value);
} else if (type.equals(NegativeServiceFilter.TYPE)) {
filter = new NegativeServiceFilter(WebSecurityUtils.safeParseInt(value), servletContext);
} else if (type.equals(NegativePartialUEIFilter.TYPE)) {
filter = new NegativePartialUEIFilter(value);
} else if (type.equals(NegativeExactUEIFilter.TYPE)) {
filter = new NegativeExactUEIFilter(value);
} else if (type.equals(NegativeAcknowledgedByFilter.TYPE)) {
filter = new NegativeAcknowledgedByFilter(value);
} else if (type.equals(EventIdFilter.TYPE)) {
filter = new EventIdFilter(WebSecurityUtils.safeParseInt(value));
} else if (type.equals(EventIdFilter.TYPE)) {
filter = new EventIdFilter(WebSecurityUtils.safeParseInt(value));
} else if (type.equals(IPAddrLikeFilter.TYPE)) {
filter = new IPAddrLikeFilter(value);
} else if (type.equals(LogMessageSubstringFilter.TYPE)) {
filter = new LogMessageSubstringFilter(value);
} else if (type.equals(LogMessageMatchesAnyFilter.TYPE)) {
filter = new LogMessageMatchesAnyFilter(value);
} else if (type.equals(BeforeDateFilter.TYPE)) {
filter = new BeforeDateFilter(WebSecurityUtils.safeParseLong(value));
} else if (type.equals(AfterDateFilter.TYPE)) {
filter = new AfterDateFilter(WebSecurityUtils.safeParseLong(value));
} else if (type.equals(AlarmIDFilter.TYPE)) {
filter = new AlarmIDFilter(WebSecurityUtils.safeParseInt(value));
} else if (type.equals(LocationFilter.TYPE)) {
filter = new LocationFilter(WebSecurityUtils.sanitizeString(value));
} else if (type.equals(SystemIdFilter.TYPE)) {
filter = new SystemIdFilter(WebSecurityUtils.sanitizeString(value));
} else if (type.equals(NegativeLocationFilter.TYPE)) {
filter = new NegativeLocationFilter(WebSecurityUtils.sanitizeString(value));
} else if (type.equals(NegativeSystemIdFilter.TYPE)) {
filter = new NegativeSystemIdFilter(WebSecurityUtils.sanitizeString(value));
} else if (type.equals(NodeLocationFilter.TYPE)) {
filter = new NodeLocationFilter(WebSecurityUtils.sanitizeString(value));
} else if (type.equals(NegativeNodeLocationFilter.TYPE)) {
filter = new NegativeNodeLocationFilter(WebSecurityUtils.sanitizeString(value));
}
return filter;
}
Aggregations