Search in sources :

Example 1 with ApplicationStatus

use of org.opennms.netmgt.dao.api.ApplicationStatus in project opennms by OpenNMS.

the class ApplicationDaoHibernate method getApplicationStatus.

@Override
public List<ApplicationStatus> getApplicationStatus(List<OnmsApplication> applications) {
    // Applications do not have a alarm mapping, so we grab all nodeDown, interfaceDown and serviceLost alarms
    // for all monitored services of each application to calculate the maximum severity (-> status)
    final List<ApplicationStatus> statusList = new ArrayList<>();
    for (OnmsApplication application : applications) {
        final Set<String> reductionKeys = new HashSet<>();
        for (OnmsMonitoredService eachService : application.getMonitoredServices()) {
            reductionKeys.addAll(ReductionKeyHelper.getReductionKeys(eachService));
        }
        if (!reductionKeys.isEmpty()) {
            final CriteriaBuilder builder = new CriteriaBuilder(OnmsAlarm.class);
            builder.in("reductionKey", reductionKeys);
            // findMatching would exepct OnmsApplications, but we need OnmsAlarms, so hack it
            HibernateCallback<List<OnmsAlarm>> callback = buildHibernateCallback(builder.toCriteria());
            List<OnmsAlarm> alarms = getHibernateTemplate().execute(callback);
            // All alarms for the current application have been determined, now get the max severity
            final Optional<OnmsAlarm> maxSeverity = alarms.stream().reduce((leftAlarm, rightAlarm) -> {
                if (leftAlarm.getSeverity().isGreaterThan(rightAlarm.getSeverity())) {
                    return leftAlarm;
                }
                return rightAlarm;
            });
            if (maxSeverity.isPresent()) {
                statusList.add(new ApplicationStatus(application, maxSeverity.get().getSeverity()));
            } else {
                // ensure that each application has a status
                statusList.add(new ApplicationStatus(application, OnmsSeverity.NORMAL));
            }
        } else {
            // ensure that each application has a status
            statusList.add(new ApplicationStatus(application, OnmsSeverity.NORMAL));
        }
    }
    return statusList;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) ApplicationStatus(org.opennms.netmgt.dao.api.ApplicationStatus) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 2 with ApplicationStatus

use of org.opennms.netmgt.dao.api.ApplicationStatus in project opennms by OpenNMS.

the class ApplicationBoxController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    final int numberOfRows = Integer.getInteger("opennms.applicationsWithProblems.count", DEFAULT_ROW_COUNT);
    final boolean all = "true".equalsIgnoreCase(request.getParameter("all"));
    // Get application status, but only consider everything > NORMAL
    List<ApplicationStatus> applicationStatus = applicationDao.getApplicationStatus();
    applicationStatus = applicationStatus.stream().filter(a -> a.getSeverity().isGreaterThan(OnmsSeverity.NORMAL)).collect(Collectors.toList());
    // Calculate status for application
    // Define if there is a "more"
    boolean more = !all && applicationStatus.size() - numberOfRows > 0;
    if (!all) {
        if (applicationStatus.size() > numberOfRows) {
            applicationStatus = applicationStatus.subList(0, numberOfRows);
        }
    }
    // Sort
    // desc sort
    applicationStatus.sort((s1, s2) -> -1 * s1.getSeverity().compareTo(s2.getSeverity()));
    // Prepare Model
    ModelAndView modelAndView = new ModelAndView(m_successView);
    modelAndView.addObject("more", more);
    modelAndView.addObject("summaries", applicationStatus);
    return modelAndView;
}
Also used : ApplicationStatus(org.opennms.netmgt.dao.api.ApplicationStatus) ModelAndView(org.springframework.web.servlet.ModelAndView)

Aggregations

ApplicationStatus (org.opennms.netmgt.dao.api.ApplicationStatus)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)1 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1