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