use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class AcknowledgeAlarmByFilterController method handleRequestInternal.
/**
* {@inheritDoc}
*
* Acknowledge the events specified in the POST and then redirect the client
* to an appropriate URL for display.
*/
@Override
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
// required parameter
String[] filterStrings = request.getParameterValues("filter");
String action = request.getParameter("actionCode");
if (filterStrings == null) {
filterStrings = new String[0];
}
if (action == null) {
throw new MissingParameterException("actionCode", new String[] { "filter", "actionCode" });
}
// handle the filter parameters
ArrayList<Filter> filterArray = new ArrayList<>();
for (String filterString : filterStrings) {
Filter filter = AlarmUtil.getFilter(filterString, getServletContext());
if (filter != null) {
filterArray.add(filter);
}
}
Filter[] filters = filterArray.toArray(new Filter[filterArray.size()]);
OnmsCriteria criteria = AlarmUtil.getOnmsCriteria(new AlarmCriteria(filters));
if (action.equals(AcknowledgeType.ACKNOWLEDGED.getShortName())) {
m_webAlarmRepository.acknowledgeMatchingAlarms(request.getRemoteUser(), new Date(), criteria);
} else if (action.equals(AcknowledgeType.UNACKNOWLEDGED.getShortName())) {
m_webAlarmRepository.unacknowledgeMatchingAlarms(criteria, request.getRemoteUser());
} else {
throw new ServletException("Unknown acknowledge action: " + action);
}
String redirectParms = request.getParameter("redirectParms");
String redirect = request.getParameter("redirect");
String viewName;
if (redirect != null) {
viewName = redirect;
} else {
viewName = (redirectParms == null || redirectParms == "" || redirectParms == "null" ? m_redirectView : m_redirectView + "?" + redirectParms);
}
RedirectView view = new RedirectView(viewName, true);
return new ModelAndView(view);
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class NetworkElementFactory method getAllManagedIpInterfacesLike.
@Override
public Interface[] getAllManagedIpInterfacesLike(String ipHost) {
OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class);
criteria.createAlias("snmpInterface", "snmpInterface", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("node", "node");
criteria.add(Restrictions.ne("isManaged", "D"));
// criteria.add(Restrictions.ne("ipAddress", InetAddressUtils.addr("0.0.0.0")));
criteria.add(Restrictions.or(Restrictions.ilike("ipHostName", ipHost, MatchMode.ANYWHERE), Restrictions.ilike("ipAddress", ipHost, MatchMode.ANYWHERE)));
// criteria.add(Restrictions.isNotNull("ipAddress"));
criteria.addOrder(Order.asc("ipHostName"));
criteria.addOrder(Order.asc("node.id"));
criteria.addOrder(Order.asc("ipAddress"));
return getInterfaceArray(m_ipInterfaceDao.findMatching(criteria));
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class AlarmFeed 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("Alarms");
feed.setDescription("OpenNMS Alarms");
feed.setLink(getUrlBase() + "alarm/list.htm");
List<SyndEntry> entries = new ArrayList<>();
List<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 sev = this.getRequest().getParameter("severity");
for (OnmsSeverity severity : OnmsSeverity.values()) {
if (severity.getLabel().equalsIgnoreCase(sev)) {
filters.add(new SeverityFilter(severity));
}
}
}
OnmsCriteria queryCriteria = AlarmUtil.getOnmsCriteria(new AlarmCriteria(filters.toArray(new Filter[] {}), SortStyle.FIRSTEVENTTIME, AcknowledgeType.BOTH, this.getMaxEntries(), AlarmCriteria.NO_OFFSET));
OnmsAlarm[] alarms = m_webAlarmRepository.getMatchingAlarms(queryCriteria);
SyndEntry entry;
for (OnmsAlarm alarm : alarms) {
entry = new SyndEntryImpl();
entry.setPublishedDate(alarm.getFirstEventTime());
if (alarm.getAckTime() != null) {
entry.setTitle(sanitizeTitle(alarm.getLogMsg()) + " (acknowledged by " + alarm.getAckUser() + ")");
entry.setUpdatedDate(alarm.getAckTime());
} else {
entry.setTitle(sanitizeTitle(alarm.getLogMsg()));
entry.setUpdatedDate(alarm.getFirstEventTime());
}
entry.setLink(getUrlBase() + "alarm/detail.htm?id=" + alarm.getId());
entry.setAuthor("OpenNMS");
SyndContent content = new SyndContentImpl();
content.setType("text/html");
content.setValue(alarm.getDescription());
entry.setDescription(content);
entries.add(entry);
}
feed.setEntries(entries);
return feed;
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class DaoWebNotificationRepository method getOnmsCriteria.
/**
* TODO: Convert this function to use {@link Criteria} instead.
*/
private static final OnmsCriteria getOnmsCriteria(final NotificationCriteria notificationCriteria) {
final OnmsCriteria criteria = new OnmsCriteria(OnmsNotification.class);
criteria.createAlias("node", "node", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("serviceType", "serviceType", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("event", "event", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("event.distPoller", "distPoller", OnmsCriteria.LEFT_JOIN);
notificationCriteria.visit(new NotificationCriteriaVisitor<RuntimeException>() {
@Override
public void visitAckType(AcknowledgeType ackType) throws RuntimeException {
if (ackType == AcknowledgeType.ACKNOWLEDGED) {
criteria.add(Restrictions.isNotNull("answeredBy"));
} else if (ackType == AcknowledgeType.UNACKNOWLEDGED) {
criteria.add(Restrictions.isNull("answeredBy"));
}
// AcknowledgeType.BOTH just adds no restriction
}
@Override
public void visitFilter(Filter filter) throws RuntimeException {
criteria.add(filter.getCriterion());
}
@Override
public void visitLimit(int limit, int offset) throws RuntimeException {
criteria.setMaxResults(limit);
criteria.setFirstResult(offset);
}
@Override
public void visitSortStyle(SortStyle sortStyle) throws RuntimeException {
switch(sortStyle) {
case LOCATION:
criteria.addOrder(Order.desc("event.distPoller.location"));
break;
case RESPONDER:
criteria.addOrder(Order.desc("answeredBy"));
break;
case PAGETIME:
criteria.addOrder(Order.desc("pageTime"));
break;
case RESPONDTIME:
criteria.addOrder(Order.desc("respondTime"));
break;
case NODE:
criteria.addOrder(Order.desc("node.label"));
break;
case NODE_LOCATION:
criteria.addOrder(Order.desc("node.location.locationName"));
break;
case INTERFACE:
criteria.addOrder(Order.desc("ipAddress"));
break;
case SERVICE:
criteria.addOrder(Order.desc("serviceType.name"));
break;
case ID:
criteria.addOrder(Order.desc("notifyId"));
break;
case SEVERITY:
criteria.addOrder(Order.desc("event.eventSeverity"));
break;
case REVERSE_LOCATION:
criteria.addOrder(Order.desc("event.distPoller.location"));
break;
case REVERSE_RESPONDER:
criteria.addOrder(Order.asc("answeredBy"));
break;
case REVERSE_PAGETIME:
criteria.addOrder(Order.asc("pageTime"));
break;
case REVERSE_RESPONDTIME:
criteria.addOrder(Order.asc("respondTime"));
break;
case REVERSE_NODE:
criteria.addOrder(Order.asc("node.label"));
break;
case REVERSE_NODE_LOCATION:
criteria.addOrder(Order.asc("node.location.locationName"));
break;
case REVERSE_INTERFACE:
criteria.addOrder(Order.asc("ipAddress"));
break;
case REVERSE_SERVICE:
criteria.addOrder(Order.asc("serviceType.name"));
break;
case REVERSE_ID:
criteria.addOrder(Order.asc("notifyId"));
break;
case REVERSE_SEVERITY:
criteria.addOrder(Order.asc("event.eventSeverity"));
break;
}
}
});
return criteria;
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class NetworkElementFactory method getNodeIdsWithIpLike.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getNodeIdsWithIpLike(java.lang.String)
*/
@Override
public List<Integer> getNodeIdsWithIpLike(String iplike) {
if (iplike == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
OnmsCriteria nodeCrit = new OnmsCriteria(OnmsNode.class);
nodeCrit.createCriteria("ipInterfaces", "iface").add(OnmsRestrictions.ipLike(iplike));
nodeCrit.add(Restrictions.ne("type", "D"));
nodeCrit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
List<Integer> nodeIds = new ArrayList<>();
List<OnmsNode> nodes = m_nodeDao.findMatching(nodeCrit);
for (OnmsNode node : nodes) {
nodeIds.add(node.getId());
}
return nodeIds;
}
Aggregations