Search in sources :

Example 31 with OnmsCriteria

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);
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 32 with OnmsCriteria

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;
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 33 with OnmsCriteria

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);
}
Also used : ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Date(java.util.Date) ServletException(javax.servlet.ServletException) Filter(org.opennms.web.filter.Filter) RedirectView(org.springframework.web.servlet.view.RedirectView) MissingParameterException(org.opennms.web.servlet.MissingParameterException) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria)

Example 34 with OnmsCriteria

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));
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 35 with OnmsCriteria

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;
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SyndContent(com.rometools.rome.feed.synd.SyndContent) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) Filter(org.opennms.web.filter.Filter) NodeFilter(org.opennms.web.alarm.filter.NodeFilter) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) NodeFilter(org.opennms.web.alarm.filter.NodeFilter)

Aggregations

OnmsCriteria (org.opennms.netmgt.model.OnmsCriteria)51 Transactional (org.springframework.transaction.annotation.Transactional)8 Filter (org.opennms.web.filter.Filter)7 Test (org.junit.Test)6 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)6 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 ArrayList (java.util.ArrayList)4 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)3 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)3 Date (java.util.Date)2 List (java.util.List)2 Criteria (org.hibernate.Criteria)2 Session (org.hibernate.Session)2 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)2 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)2 AcknowledgedByFilter (org.opennms.web.alarm.filter.AcknowledgedByFilter)2 SeverityFilter (org.opennms.web.alarm.filter.SeverityFilter)2 HibernateCallback (org.springframework.orm.hibernate3.HibernateCallback)2 SyndContent (com.rometools.rome.feed.synd.SyndContent)1