Search in sources :

Example 1 with NodeFilter

use of org.opennms.web.event.filter.NodeFilter in project opennms by OpenNMS.

the class EventFeed method getFeed.

/**
 * <p>getFeed</p>
 *
 * @return a {@link com.rometools.rome.feed.synd.SyndFeed} object.
 */
@Override
public SyndFeed getFeed() {
    SyndFeed feed = new SyndFeedImpl();
    feed.setTitle("Events");
    feed.setDescription("OpenNMS Events");
    feed.setLink(getUrlBase() + "event/list.htm");
    List<SyndEntry> entries = new ArrayList<>();
    try {
        Event[] events;
        ArrayList<Filter> filters = new ArrayList<>();
        if (this.getRequest().getParameter("node") != null) {
            Integer nodeId = WebSecurityUtils.safeParseInt(this.getRequest().getParameter("node"));
            filters.add(new NodeFilter(nodeId, getServletContext()));
        }
        if (this.getRequest().getParameter("severity") != null) {
            String parameter = this.getRequest().getParameter("severity");
            try {
                Integer severityId = WebSecurityUtils.safeParseInt(parameter);
                filters.add(new SeverityFilter(severityId));
            } catch (NumberFormatException e) {
                for (OnmsSeverity sev : OnmsSeverity.values()) {
                    if (sev.getLabel().equalsIgnoreCase(parameter)) {
                        filters.add(new SeverityFilter(sev));
                        break;
                    }
                }
            }
        }
        events = EventFactory.getEvents(SortStyle.TIME, AcknowledgeType.BOTH, filters.toArray(new Filter[] {}), this.getMaxEntries(), 0);
        SyndEntry entry;
        for (Event event : events) {
            entry = new SyndEntryImpl();
            entry.setPublishedDate(event.getTime());
            if (event.getAcknowledgeTime() != null) {
                entry.setTitle(sanitizeTitle(event.getLogMessage()) + " (Acknowledged by " + event.getAcknowledgeUser() + ")");
                entry.setUpdatedDate(event.getAcknowledgeTime());
            } else {
                entry.setTitle(sanitizeTitle(event.getLogMessage()));
                entry.setUpdatedDate(event.getTime());
            }
            entry.setLink(getUrlBase() + "event/detail.jsp?id=" + event.getId());
            entry.setAuthor("OpenNMS");
            SyndContent content = new SyndContentImpl();
            content.setType("text/html");
            content.setValue(event.getDescription());
            entry.setDescription(content);
            entries.add(entry);
        }
    } catch (SQLException e) {
        LOG.warn("unable to get event(s)", e);
    }
    feed.setEntries(entries);
    return feed;
}
Also used : SQLException(java.sql.SQLException) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SeverityFilter(org.opennms.web.event.filter.SeverityFilter) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SyndContent(com.rometools.rome.feed.synd.SyndContent) SeverityFilter(org.opennms.web.event.filter.SeverityFilter) Filter(org.opennms.web.filter.Filter) NodeFilter(org.opennms.web.event.filter.NodeFilter) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) Event(org.opennms.web.event.Event) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) NodeFilter(org.opennms.web.event.filter.NodeFilter)

Example 2 with NodeFilter

use of org.opennms.web.event.filter.NodeFilter 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

NodeFilter (org.opennms.web.event.filter.NodeFilter)2 SeverityFilter (org.opennms.web.event.filter.SeverityFilter)2 Filter (org.opennms.web.filter.Filter)2 SyndContent (com.rometools.rome.feed.synd.SyndContent)1 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)1 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)1 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)1 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 StringTokenizer (java.util.StringTokenizer)1 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)1 Event (org.opennms.web.event.Event)1 AcknowledgedByFilter (org.opennms.web.event.filter.AcknowledgedByFilter)1 AfterDateFilter (org.opennms.web.event.filter.AfterDateFilter)1 AlarmIDFilter (org.opennms.web.event.filter.AlarmIDFilter)1 BeforeDateFilter (org.opennms.web.event.filter.BeforeDateFilter)1 EventIdFilter (org.opennms.web.event.filter.EventIdFilter)1