Search in sources :

Example 6 with EventCriteria

use of org.opennms.web.event.filter.EventCriteria in project opennms by OpenNMS.

the class DaoWebEventRepositoryIT method testCountMatchingEvents.

@Test
@Transactional
public void testCountMatchingEvents() {
    EventCriteria criteria = new EventCriteria();
    int event = m_daoEventRepo.countMatchingEvents(criteria);
    assertEquals(2, event);
}
Also used : EventCriteria(org.opennms.web.event.filter.EventCriteria) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with EventCriteria

use of org.opennms.web.event.filter.EventCriteria in project opennms by OpenNMS.

the class DaoWebEventRepositoryIT method testCountMatchingEventsBySeverity.

@Test
@Transactional
public void testCountMatchingEventsBySeverity() {
    EventCriteria criteria = new EventCriteria();
    int[] matchingEvents = m_daoEventRepo.countMatchingEventsBySeverity(criteria);
    assertNotNull(matchingEvents);
    assertEquals(8, matchingEvents.length);
    assertEquals(1, matchingEvents[OnmsSeverity.CLEARED.getId()]);
    assertEquals(0, matchingEvents[OnmsSeverity.CRITICAL.getId()]);
    assertEquals(1, matchingEvents[OnmsSeverity.INDETERMINATE.getId()]);
    assertEquals(0, matchingEvents[OnmsSeverity.MAJOR.getId()]);
    assertEquals(0, matchingEvents[OnmsSeverity.MINOR.getId()]);
    assertEquals(0, matchingEvents[OnmsSeverity.NORMAL.getId()]);
    assertEquals(0, matchingEvents[OnmsSeverity.WARNING.getId()]);
}
Also used : EventCriteria(org.opennms.web.event.filter.EventCriteria) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with EventCriteria

use of org.opennms.web.event.filter.EventCriteria in project opennms by OpenNMS.

the class EventController method acknowledge.

/**
 * Acknowledge the events specified in the POST and then redirect the client
 * to an appropriate URL for display.
 */
public ModelAndView acknowledge(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // required parameter
    String[] eventIdStrings = request.getParameterValues("event");
    String action = request.getParameter("actionCode");
    if (eventIdStrings == null) {
        throw new MissingParameterException("event", new String[] { "event", "actionCode" });
    }
    if (action == null) {
        throw new MissingParameterException("actionCode", new String[] { "event", "actionCode" });
    }
    List<Filter> filters = new ArrayList<>();
    filters.add(new EventIdListFilter(WebSecurityUtils.safeParseInt(eventIdStrings)));
    EventCriteria criteria = new EventCriteria(filters.toArray(new Filter[0]));
    LOG.debug("criteria = {}, action = {}", criteria, action);
    if (action.equals(AcknowledgeType.ACKNOWLEDGED.getShortName())) {
        m_webEventRepository.acknowledgeMatchingEvents(request.getRemoteUser(), new Date(), criteria);
    } else if (action.equals(AcknowledgeType.UNACKNOWLEDGED.getShortName())) {
        m_webEventRepository.unacknowledgeMatchingEvents(criteria);
    } else {
        throw new ServletException("Unknown acknowledge action: " + action);
    }
    return getRedirectView(request);
}
Also used : ServletException(javax.servlet.ServletException) EventIdFilter(org.opennms.web.event.filter.EventIdFilter) Filter(org.opennms.web.filter.Filter) EventIdListFilter(org.opennms.web.event.filter.EventIdListFilter) ArrayList(java.util.ArrayList) MissingParameterException(org.opennms.web.servlet.MissingParameterException) EventCriteria(org.opennms.web.event.filter.EventCriteria) EventIdListFilter(org.opennms.web.event.filter.EventIdListFilter) Date(java.util.Date)

Example 9 with EventCriteria

use of org.opennms.web.event.filter.EventCriteria in project opennms by OpenNMS.

the class NotificationFilterController method handleRequestInternal.

/**
 * {@inheritDoc}
 *
 * Parses the query string to determine what types of notification filters to use
 * (for example, what to filter on or sort by), then does the database query
 * and then forwards the results to a JSP for display.
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String display = request.getParameter("display");
    // handle the style sort parameter
    String sortStyleString = request.getParameter("sortby");
    SortStyle sortStyle = m_defaultSortStyle;
    if (sortStyleString != null) {
        SortStyle temp = SortStyle.getSortStyle(sortStyleString);
        if (temp != null) {
            sortStyle = temp;
        }
    }
    // handle the acknowledgment type parameter
    String ackTypeString = request.getParameter("acktype");
    AcknowledgeType ackType = m_defaultAckType;
    if (ackTypeString != null) {
        AcknowledgeType temp = AcknowledgeType.getAcknowledgeType(ackTypeString);
        if (temp != null) {
            ackType = temp;
        }
    }
    // handle the filter parameters
    String[] filterStrings = request.getParameterValues("filter");
    List<Filter> filterList = new ArrayList<>();
    if (filterStrings != null) {
        for (String filterString : filterStrings) {
            Filter filter = NoticeUtil.getFilter(filterString, getServletContext());
            if (filter != null) {
                filterList.add(filter);
            }
        }
    }
    // Check for a username filter (used on notifications/index.jsp)
    String username = request.getParameter("user");
    if (username != null) {
        Filter filter = NoticeUtil.getFilter("user=" + username, getServletContext());
        if (filter != null) {
            filterList.add(filter);
        }
    }
    // handle the optional limit parameter
    String limitString = request.getParameter("limit");
    int limit = "long".equals(display) ? m_defaultLongLimit : m_defaultShortLimit;
    if (limitString != null) {
        try {
            int newlimit = WebSecurityUtils.safeParseInt(limitString);
            if (newlimit > 0) {
                limit = newlimit;
            }
        } catch (NumberFormatException e) {
        // do nothing, the default is already set
        }
    }
    // handle the optional multiple parameter
    String multipleString = request.getParameter("multiple");
    int multiple = DEFAULT_MULTIPLE;
    if (multipleString != null) {
        try {
            multiple = Math.max(0, WebSecurityUtils.safeParseInt(multipleString));
        } catch (NumberFormatException e) {
        }
    }
    // put the parameters in a convenient struct
    Filter[] filters = filterList.toArray(new Filter[0]);
    NoticeQueryParms parms = new NoticeQueryParms();
    parms.ackType = ackType;
    parms.display = display;
    parms.filters = filterList;
    parms.limit = limit;
    parms.multiple = multiple;
    parms.sortStyle = sortStyle;
    NotificationCriteria queryCriteria = new NotificationCriteria(filters, sortStyle, ackType, limit, limit * multiple);
    NotificationCriteria countCriteria = new NotificationCriteria(ackType, filters);
    Notification[] notices = m_webNotificationRepository.getMatchingNotifications(queryCriteria);
    int noticeCount = m_webNotificationRepository.countMatchingNotifications(countCriteria);
    final Map<Integer, String[]> nodeLabels = new HashMap<Integer, String[]>();
    final Map<Integer, String[]> nodeLocations = new HashMap<Integer, String[]>();
    Set<Integer> eventIds = new TreeSet<>();
    // really inefficient, is there a better way to do this?
    for (Notification notice : notices) {
        if (notice.getEventId() > 0) {
            eventIds.add(notice.getEventId());
        }
        if (notice.getNodeId() > 0) {
            if (!nodeLabels.containsKey(notice.getNodeId())) {
                String[] labels = null;
                String[] locations = null;
                OnmsNode node = m_nodeDao.get(notice.getNodeId());
                if (node != null) {
                    String longLabel = node.getLabel();
                    if (longLabel == null) {
                        labels = new String[] { "&lt;No Node Label&gt;", "&lt;No Node Label&gt;" };
                    } else {
                        if (longLabel.length() > 32) {
                            String shortLabel = longLabel.substring(0, 31) + "&hellip;";
                            labels = new String[] { shortLabel, longLabel };
                        } else {
                            labels = new String[] { longLabel, longLabel };
                        }
                    }
                    if (node.getLocation() != null) {
                        String location = node.getLocation().getLocationName();
                        if (location == null) {
                            locations = new String[] { "&lt;No Node Location&gt;", "&lt;No Node Location&gt;" };
                        } else {
                            if (location.length() > 32) {
                                String shortLocation = location.substring(0, 31) + "&hellip;";
                                locations = new String[] { shortLocation, location };
                            } else {
                                locations = new String[] { location, location };
                            }
                        }
                    }
                }
                nodeLabels.put(notice.getNodeId(), labels);
                nodeLocations.put(notice.getNodeId(), locations);
            }
        }
    }
    Map<Integer, Event> events = new HashMap<Integer, Event>();
    if (eventIds.size() > 0) {
        for (Event e : m_webEventRepository.getMatchingEvents(new EventCriteria(new EventIdListFilter(eventIds)))) {
            events.put(e.getId(), e);
        }
    }
    ModelAndView modelAndView = new ModelAndView(m_successView);
    modelAndView.addObject("notices", notices);
    modelAndView.addObject("noticeCount", noticeCount);
    modelAndView.addObject("nodeLabels", nodeLabels);
    modelAndView.addObject("nodeLocations", nodeLocations);
    modelAndView.addObject("events", events);
    modelAndView.addObject("parms", parms);
    return modelAndView;
}
Also used : SortStyle(org.opennms.web.notification.SortStyle) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) EventCriteria(org.opennms.web.event.filter.EventCriteria) EventIdListFilter(org.opennms.web.event.filter.EventIdListFilter) Notification(org.opennms.web.notification.Notification) TreeSet(java.util.TreeSet) NoticeQueryParms(org.opennms.web.notification.NoticeQueryParms) OnmsNode(org.opennms.netmgt.model.OnmsNode) AcknowledgeType(org.opennms.web.notification.AcknowledgeType) Filter(org.opennms.web.filter.Filter) EventIdListFilter(org.opennms.web.event.filter.EventIdListFilter) NotificationCriteria(org.opennms.web.notification.filter.NotificationCriteria) Event(org.opennms.web.event.Event)

Example 10 with EventCriteria

use of org.opennms.web.event.filter.EventCriteria in project opennms by OpenNMS.

the class EventController method acknowledgeByFilter.

/**
 * Acknowledge the events specified in the POST and then redirect the client
 * to an appropriate URL for display.
 */
public ModelAndView acknowledgeByFilter(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 = EventUtil.getFilter(filterString, getServletContext());
        if (filter != null) {
            filterArray.add(filter);
        }
    }
    Filter[] filters = filterArray.toArray(new Filter[filterArray.size()]);
    EventCriteria criteria = new EventCriteria(filters);
    if (action.equals(AcknowledgeType.ACKNOWLEDGED.getShortName())) {
        m_webEventRepository.acknowledgeMatchingEvents(request.getRemoteUser(), new Date(), criteria);
    } else if (action.equals(AcknowledgeType.UNACKNOWLEDGED.getShortName())) {
        m_webEventRepository.unacknowledgeMatchingEvents(criteria);
    } else {
        throw new ServletException("Unknown acknowledge action: " + action);
    }
    return getRedirectView(request);
}
Also used : ServletException(javax.servlet.ServletException) EventIdFilter(org.opennms.web.event.filter.EventIdFilter) Filter(org.opennms.web.filter.Filter) EventIdListFilter(org.opennms.web.event.filter.EventIdListFilter) ArrayList(java.util.ArrayList) MissingParameterException(org.opennms.web.servlet.MissingParameterException) EventCriteria(org.opennms.web.event.filter.EventCriteria) Date(java.util.Date)

Aggregations

EventCriteria (org.opennms.web.event.filter.EventCriteria)10 Test (org.junit.Test)6 Transactional (org.springframework.transaction.annotation.Transactional)5 Date (java.util.Date)4 ArrayList (java.util.ArrayList)3 EventIdFilter (org.opennms.web.event.filter.EventIdFilter)3 EventIdListFilter (org.opennms.web.event.filter.EventIdListFilter)3 Filter (org.opennms.web.filter.Filter)3 ServletException (javax.servlet.ServletException)2 AcknowledgedByFilter (org.opennms.web.event.filter.AcknowledgedByFilter)2 NegativeSeverityFilter (org.opennms.web.event.filter.NegativeSeverityFilter)2 MissingParameterException (org.opennms.web.servlet.MissingParameterException)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)1 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 Event (org.opennms.web.event.Event)1 SeverityFilter (org.opennms.web.event.filter.SeverityFilter)1