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;
}
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;
}
Aggregations