use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class DefaultRtcService method getNodeList.
/**
* <p>getNodeList</p>
*
* @return a {@link org.opennms.web.svclayer.model.RtcNodeModel} object.
*/
@Override
public RtcNodeModel getNodeList() {
OnmsCriteria serviceCriteria = createServiceCriteria();
OnmsCriteria outageCriteria = createOutageCriteria();
return getNodeListForCriteria(serviceCriteria, outageCriteria);
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class DefaultRtcService method createOutageCriteria.
/**
* <p>Create a {@link OnmsCriteria} that will select {@link OnmsOutage} objects.</p>
*
* <p>CAUTION: This criteria must contain a JOIN alias to the node table called 'node' so that the
* {@link org.opennms.dashboard.server.CriteriaAddingVisitor.addCriteriaForCategories(OnmsCriteria, String...)}
* function can add a category-based restriction on matching node IDs to the criteria.</p>
*
* @return a {@link org.opennms.netmgt.model.OnmsCriteria} object.
*/
@Override
public OnmsCriteria createOutageCriteria() {
OnmsCriteria outageCriteria = new OnmsCriteria(OnmsOutage.class, "outage");
outageCriteria.createAlias("monitoredService", "monitoredService", OnmsCriteria.INNER_JOIN);
outageCriteria.add(Restrictions.eq("monitoredService.status", "A"));
outageCriteria.createAlias("monitoredService.ipInterface", "ipInterface", OnmsCriteria.INNER_JOIN);
outageCriteria.add(Restrictions.ne("ipInterface.isManaged", "D"));
// Required for {@link org.opennms.dashboard.server.CriteriaAddingVisitor.addCriteriaForCategories(OnmsCriteria, String...)}
// to work properly.
outageCriteria.createAlias("monitoredService.ipInterface.node", "node", OnmsCriteria.INNER_JOIN);
outageCriteria.add(Restrictions.ne("node.type", "D"));
return outageCriteria;
}
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;
}
Aggregations