Search in sources :

Example 1 with RtcNode

use of org.opennms.web.svclayer.model.RtcNode in project opennms by OpenNMS.

the class DefaultRtcService method getNodeListForCriteria.

/**
 * {@inheritDoc}
 */
@Override
public RtcNodeModel getNodeListForCriteria(OnmsCriteria serviceCriteria, OnmsCriteria outageCriteria) {
    serviceCriteria.addOrder(Order.asc("node.label"));
    serviceCriteria.addOrder(Order.asc("node.id"));
    serviceCriteria.addOrder(Order.asc("ipInterface.ipAddress"));
    serviceCriteria.addOrder(Order.asc("serviceType.name"));
    Date periodEnd = new Date(System.currentTimeMillis());
    Date periodStart = new Date(periodEnd.getTime() - (24 * 60 * 60 * 1000));
    Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(Restrictions.isNull("ifRegainedService"));
    disjunction.add(Restrictions.ge("ifLostService", periodStart));
    disjunction.add(Restrictions.ge("ifRegainedService", periodStart));
    outageCriteria.add(disjunction);
    outageCriteria.addOrder(Order.asc("monitoredService"));
    outageCriteria.addOrder(Order.asc("ifLostService"));
    List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(serviceCriteria);
    List<OnmsOutage> outages = m_outageDao.findMatching(outageCriteria);
    Map<OnmsMonitoredService, Long> serviceDownTime = calculateServiceDownTime(periodEnd, periodStart, outages);
    RtcNodeModel model = new RtcNodeModel();
    OnmsNode lastNode = null;
    int serviceCount = 0;
    int serviceDownCount = 0;
    long downMillisCount = 0;
    for (OnmsMonitoredService service : services) {
        if (!service.getIpInterface().getNode().equals(lastNode) && lastNode != null) {
            Double availability = calculateAvailability(serviceCount, downMillisCount, periodEnd.getTime() - periodStart.getTime());
            model.addNode(new RtcNode(lastNode, serviceCount, serviceDownCount, availability));
            serviceCount = 0;
            serviceDownCount = 0;
            downMillisCount = 0;
        }
        serviceCount++;
        if (service.isDown()) {
            serviceDownCount++;
        }
        Long downMillis = serviceDownTime.get(service);
        if (downMillis == null) {
        // This service had 100% availability over the period, no downtime
        } else {
            downMillisCount += downMillis;
        }
        lastNode = service.getIpInterface().getNode();
    }
    if (lastNode != null) {
        Double availability = calculateAvailability(serviceCount, downMillisCount, periodEnd.getTime() - periodStart.getTime());
        model.addNode(new RtcNode(lastNode, serviceCount, serviceDownCount, availability));
    }
    return model;
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) RtcNodeModel(org.opennms.web.svclayer.model.RtcNodeModel) OnmsNode(org.opennms.netmgt.model.OnmsNode) RtcNode(org.opennms.web.svclayer.model.RtcNode) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Disjunction(org.hibernate.criterion.Disjunction)

Aggregations

Date (java.util.Date)1 Disjunction (org.hibernate.criterion.Disjunction)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)1 RtcNode (org.opennms.web.svclayer.model.RtcNode)1 RtcNodeModel (org.opennms.web.svclayer.model.RtcNodeModel)1