Search in sources :

Example 1 with LogMessageMatchesAnyFilter

use of org.opennms.web.event.filter.LogMessageMatchesAnyFilter 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<Filter>();
    // 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);
}
Also used : NodeNameLikeFilter(org.opennms.web.event.filter.NodeNameLikeFilter) ServiceFilter(org.opennms.web.event.filter.ServiceFilter) IPAddrLikeFilter(org.opennms.web.event.filter.IPAddrLikeFilter) HashMap(java.util.HashMap) LogMessageSubstringFilter(org.opennms.web.event.filter.LogMessageSubstringFilter) ArrayList(java.util.ArrayList) ExactUEIFilter(org.opennms.web.event.filter.ExactUEIFilter) ServletException(javax.servlet.ServletException) NodeLocationFilter(org.opennms.web.event.filter.NodeLocationFilter) SeverityFilter(org.opennms.web.event.filter.SeverityFilter) LogMessageMatchesAnyFilter(org.opennms.web.event.filter.LogMessageMatchesAnyFilter) EventIdFilter(org.opennms.web.event.filter.EventIdFilter) NodeLocationFilter(org.opennms.web.event.filter.NodeLocationFilter) SeverityFilter(org.opennms.web.event.filter.SeverityFilter) SystemIdFilter(org.opennms.web.event.filter.SystemIdFilter) IPAddrLikeFilter(org.opennms.web.event.filter.IPAddrLikeFilter) ExactUEIFilter(org.opennms.web.event.filter.ExactUEIFilter) NodeNameLikeFilter(org.opennms.web.event.filter.NodeNameLikeFilter) LocationFilter(org.opennms.web.event.filter.LocationFilter) ServiceFilter(org.opennms.web.event.filter.ServiceFilter) BeforeDateFilter(org.opennms.web.event.filter.BeforeDateFilter) AfterDateFilter(org.opennms.web.event.filter.AfterDateFilter) Filter(org.opennms.web.filter.Filter) LogMessageMatchesAnyFilter(org.opennms.web.event.filter.LogMessageMatchesAnyFilter) LogMessageSubstringFilter(org.opennms.web.event.filter.LogMessageSubstringFilter) NodeLocationFilter(org.opennms.web.event.filter.NodeLocationFilter) LocationFilter(org.opennms.web.event.filter.LocationFilter) SystemIdFilter(org.opennms.web.event.filter.SystemIdFilter) MissingParameterException(org.opennms.web.servlet.MissingParameterException) EventIdFilter(org.opennms.web.event.filter.EventIdFilter)

Example 2 with LogMessageMatchesAnyFilter

use of org.opennms.web.event.filter.LogMessageMatchesAnyFilter 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;
}
Also used : NegativeServiceFilter(org.opennms.web.event.filter.NegativeServiceFilter) ServiceFilter(org.opennms.web.event.filter.ServiceFilter) InterfaceFilter(org.opennms.web.event.filter.InterfaceFilter) NegativeInterfaceFilter(org.opennms.web.event.filter.NegativeInterfaceFilter) NegativePartialUEIFilter(org.opennms.web.event.filter.NegativePartialUEIFilter) LogMessageSubstringFilter(org.opennms.web.event.filter.LogMessageSubstringFilter) PartialUEIFilter(org.opennms.web.event.filter.PartialUEIFilter) NegativePartialUEIFilter(org.opennms.web.event.filter.NegativePartialUEIFilter) LogMessageMatchesAnyFilter(org.opennms.web.event.filter.LogMessageMatchesAnyFilter) NegativeSeverityFilter(org.opennms.web.event.filter.NegativeSeverityFilter) SystemIdFilter(org.opennms.web.event.filter.SystemIdFilter) NegativeSystemIdFilter(org.opennms.web.event.filter.NegativeSystemIdFilter) NegativeServiceFilter(org.opennms.web.event.filter.NegativeServiceFilter) NegativeAcknowledgedByFilter(org.opennms.web.event.filter.NegativeAcknowledgedByFilter) EventIdFilter(org.opennms.web.event.filter.EventIdFilter) NodeNameLikeFilter(org.opennms.web.event.filter.NodeNameLikeFilter) IPAddrLikeFilter(org.opennms.web.event.filter.IPAddrLikeFilter) NegativeNodeFilter(org.opennms.web.event.filter.NegativeNodeFilter) AlarmIDFilter(org.opennms.web.event.filter.AlarmIDFilter) AcknowledgedByFilter(org.opennms.web.event.filter.AcknowledgedByFilter) NegativeAcknowledgedByFilter(org.opennms.web.event.filter.NegativeAcknowledgedByFilter) NegativeExactUEIFilter(org.opennms.web.event.filter.NegativeExactUEIFilter) ExactUEIFilter(org.opennms.web.event.filter.ExactUEIFilter) NegativeInterfaceFilter(org.opennms.web.event.filter.NegativeInterfaceFilter) BeforeDateFilter(org.opennms.web.event.filter.BeforeDateFilter) NegativeSeverityFilter(org.opennms.web.event.filter.NegativeSeverityFilter) SeverityFilter(org.opennms.web.event.filter.SeverityFilter) NodeLocationFilter(org.opennms.web.event.filter.NodeLocationFilter) NegativeNodeLocationFilter(org.opennms.web.event.filter.NegativeNodeLocationFilter) StringTokenizer(java.util.StringTokenizer) NegativeLocationFilter(org.opennms.web.event.filter.NegativeLocationFilter) NegativeNodeLocationFilter(org.opennms.web.event.filter.NegativeNodeLocationFilter) PartialUEIFilter(org.opennms.web.event.filter.PartialUEIFilter) EventIdFilter(org.opennms.web.event.filter.EventIdFilter) NegativeSeverityFilter(org.opennms.web.event.filter.NegativeSeverityFilter) AcknowledgedByFilter(org.opennms.web.event.filter.AcknowledgedByFilter) NodeLocationFilter(org.opennms.web.event.filter.NodeLocationFilter) SeverityFilter(org.opennms.web.event.filter.SeverityFilter) SystemIdFilter(org.opennms.web.event.filter.SystemIdFilter) NegativeAcknowledgedByFilter(org.opennms.web.event.filter.NegativeAcknowledgedByFilter) InterfaceFilter(org.opennms.web.event.filter.InterfaceFilter) IPAddrLikeFilter(org.opennms.web.event.filter.IPAddrLikeFilter) NegativeExactUEIFilter(org.opennms.web.event.filter.NegativeExactUEIFilter) NegativeServiceFilter(org.opennms.web.event.filter.NegativeServiceFilter) NodeFilter(org.opennms.web.event.filter.NodeFilter) ExactUEIFilter(org.opennms.web.event.filter.ExactUEIFilter) NodeNameLikeFilter(org.opennms.web.event.filter.NodeNameLikeFilter) LocationFilter(org.opennms.web.event.filter.LocationFilter) NegativeSystemIdFilter(org.opennms.web.event.filter.NegativeSystemIdFilter) ServiceFilter(org.opennms.web.event.filter.ServiceFilter) BeforeDateFilter(org.opennms.web.event.filter.BeforeDateFilter) IfIndexFilter(org.opennms.web.event.filter.IfIndexFilter) AfterDateFilter(org.opennms.web.event.filter.AfterDateFilter) NegativeInterfaceFilter(org.opennms.web.event.filter.NegativeInterfaceFilter) AlarmIDFilter(org.opennms.web.event.filter.AlarmIDFilter) NegativeLocationFilter(org.opennms.web.event.filter.NegativeLocationFilter) Filter(org.opennms.web.filter.Filter) LogMessageMatchesAnyFilter(org.opennms.web.event.filter.LogMessageMatchesAnyFilter) NegativeNodeLocationFilter(org.opennms.web.event.filter.NegativeNodeLocationFilter) NegativeNodeFilter(org.opennms.web.event.filter.NegativeNodeFilter) NegativePartialUEIFilter(org.opennms.web.event.filter.NegativePartialUEIFilter) LogMessageSubstringFilter(org.opennms.web.event.filter.LogMessageSubstringFilter) NodeLocationFilter(org.opennms.web.event.filter.NodeLocationFilter) LocationFilter(org.opennms.web.event.filter.LocationFilter) NegativeLocationFilter(org.opennms.web.event.filter.NegativeLocationFilter) NegativeNodeLocationFilter(org.opennms.web.event.filter.NegativeNodeLocationFilter) NegativeExactUEIFilter(org.opennms.web.event.filter.NegativeExactUEIFilter) IfIndexFilter(org.opennms.web.event.filter.IfIndexFilter) NegativeSystemIdFilter(org.opennms.web.event.filter.NegativeSystemIdFilter) NoSuchElementException(java.util.NoSuchElementException) AfterDateFilter(org.opennms.web.event.filter.AfterDateFilter) NodeFilter(org.opennms.web.event.filter.NodeFilter) NegativeNodeFilter(org.opennms.web.event.filter.NegativeNodeFilter)

Aggregations

AfterDateFilter (org.opennms.web.event.filter.AfterDateFilter)2 BeforeDateFilter (org.opennms.web.event.filter.BeforeDateFilter)2 EventIdFilter (org.opennms.web.event.filter.EventIdFilter)2 ExactUEIFilter (org.opennms.web.event.filter.ExactUEIFilter)2 IPAddrLikeFilter (org.opennms.web.event.filter.IPAddrLikeFilter)2 LocationFilter (org.opennms.web.event.filter.LocationFilter)2 LogMessageMatchesAnyFilter (org.opennms.web.event.filter.LogMessageMatchesAnyFilter)2 LogMessageSubstringFilter (org.opennms.web.event.filter.LogMessageSubstringFilter)2 NodeLocationFilter (org.opennms.web.event.filter.NodeLocationFilter)2 NodeNameLikeFilter (org.opennms.web.event.filter.NodeNameLikeFilter)2 ServiceFilter (org.opennms.web.event.filter.ServiceFilter)2 SeverityFilter (org.opennms.web.event.filter.SeverityFilter)2 SystemIdFilter (org.opennms.web.event.filter.SystemIdFilter)2 Filter (org.opennms.web.filter.Filter)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NoSuchElementException (java.util.NoSuchElementException)1 StringTokenizer (java.util.StringTokenizer)1 ServletException (javax.servlet.ServletException)1 AcknowledgedByFilter (org.opennms.web.event.filter.AcknowledgedByFilter)1