Search in sources :

Example 46 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 47 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 48 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)

Example 49 with OnmsCriteria

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

Example 50 with OnmsCriteria

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

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