Search in sources :

Example 56 with OnmsMonitoredService

use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.

the class DefaultDistributedStatusService method calculateCurrentStatus.

/**
 * <p>calculateCurrentStatus</p>
 *
 * @param monitor a {@link org.opennms.netmgt.model.OnmsLocationMonitor} object.
 * @param applicationServices a {@link java.util.Collection} object.
 * @param statuses a {@link java.util.Collection} object.
 * @return a {@link org.opennms.web.svclayer.support.DefaultDistributedStatusService.Severity} object.
 */
public Severity calculateCurrentStatus(OnmsLocationMonitor monitor, Collection<OnmsMonitoredService> applicationServices, Collection<OnmsLocationSpecificStatus> statuses) {
    Set<PollStatus> pollStatuses = new HashSet<>();
    for (OnmsMonitoredService service : applicationServices) {
        boolean foundIt = false;
        for (OnmsLocationSpecificStatus status : statuses) {
            if (status.getMonitoredService().equals(service) && status.getLocationMonitor().equals(monitor)) {
                pollStatuses.add(status.getPollResult());
                foundIt = true;
                break;
            }
        }
        if (!foundIt) {
            pollStatuses.add(PollStatus.unknown("No status found for this service"));
            LOG.debug("Did not find status for service {} in application.  Setting status for it to unknown.", service);
        }
    }
    return calculateStatus(pollStatuses);
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) HashSet(java.util.HashSet) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 57 with OnmsMonitoredService

use of org.opennms.netmgt.model.OnmsMonitoredService 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)

Example 58 with OnmsMonitoredService

use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.

the class AvailabilityServiceIT method canCalculateAvailability.

@Test
public void canCalculateAvailability() throws Exception {
    final MockNetwork mockNetwork = new MockNetwork();
    // This test depends on the specifics in the standard network definition
    mockNetwork.createStandardNetwork();
    m_mockDatabase.populate(mockNetwork);
    final RTCCategory rtcCat = EasyMock.createNiceMock(RTCCategory.class);
    EasyMock.expect(rtcCat.getLabel()).andReturn("NOC").anyTimes();
    EasyMock.expect(rtcCat.getNodes()).andReturn(Lists.newArrayList(1, 2)).anyTimes();
    EasyMock.replay(rtcCat);
    // Verify the availability when no outages are present
    EuiLevel euiLevel = m_availabilityService.getEuiLevel(rtcCat);
    assertEquals(1, euiLevel.getCategory().size());
    Category category = euiLevel.getCategory().get(0);
    assertEquals(100.0, category.getCatvalue(), 0.001);
    assertEquals(2, category.getNode().size());
    // Assumes the nodes are sorted
    assertEquals(4, category.getNode().get(0).getNodesvccount());
    assertEquals(2, category.getNode().get(1).getNodesvccount());
    // Create an outage that is both open and closed within the window
    final Date now = new Date();
    final Date oneHourAgo = new Date(now.getTime() - (60 * 60 * 1000));
    final Date thirtyMinutesAgo = new Date(now.getTime() - (30 * 60 * 1000));
    final OnmsMonitoredService icmpService = toMonitoredService(mockNetwork.getService(1, "192.168.1.1", "ICMP"));
    OnmsOutage outage = new OnmsOutage();
    outage.setMonitoredService(icmpService);
    outage.setIfLostService(oneHourAgo);
    outage.setIfRegainedService(thirtyMinutesAgo);
    m_outageDao.save(outage);
    m_outageDao.flush();
    // Verify the availability when outages are present
    euiLevel = m_availabilityService.getEuiLevel(rtcCat);
    assertEquals(1, euiLevel.getCategory().size());
    category = euiLevel.getCategory().get(0);
    // This number should only need to be adjusted if the duration of the outage
    // or the number of services in the category changes
    assertEquals(RTCUtils.getOutagePercentage(1800000, 86400000, 6), category.getCatvalue(), 0.0001);
    assertEquals(2, category.getNode().size());
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Category(org.opennms.netmgt.xml.rtc.Category) MockNetwork(org.opennms.netmgt.mock.MockNetwork) EuiLevel(org.opennms.netmgt.xml.rtc.EuiLevel) Date(java.util.Date) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Example 59 with OnmsMonitoredService

use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.

the class DefaultRtcService method calculateServiceDownTime.

private static Map<OnmsMonitoredService, Long> calculateServiceDownTime(Date periodEnd, Date periodStart, List<OnmsOutage> outages) {
    Map<OnmsMonitoredService, Long> map = new HashMap<OnmsMonitoredService, Long>();
    for (OnmsOutage outage : outages) {
        if (map.get(outage.getMonitoredService()) == null) {
            map.put(outage.getMonitoredService(), 0L);
        }
        Date begin;
        if (outage.getIfLostService().before(periodStart)) {
            begin = periodStart;
        } else if (outage.getIfLostService().after(periodEnd)) {
            LoggerFactory.getLogger(DefaultRtcService.class).warn("Outage beginning is after period end {}, discarding outage: {}", periodEnd, outage.toString());
            continue;
        } else {
            begin = outage.getIfLostService();
        }
        Date end;
        if (outage.getIfRegainedService() == null) {
            // If the outage hasn't ended yet, use the end of the period as the end time
            end = periodEnd;
        } else if (outage.getIfRegainedService().after(periodEnd)) {
            // If the outage ended after the end of the period, use the end of the period as the end time
            end = periodEnd;
        } else {
            end = outage.getIfRegainedService();
        }
        if (begin.after(end)) {
            LoggerFactory.getLogger(DefaultRtcService.class).warn("Outage beginning is after outage end inside period {} to {}, discarding outage: {}", periodStart, periodEnd, outage.toString());
            continue;
        } else {
            Long count = map.get(outage.getMonitoredService());
            count += (end.getTime() - begin.getTime());
            map.put(outage.getMonitoredService(), count);
        }
    }
    return map;
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) HashMap(java.util.HashMap) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 60 with OnmsMonitoredService

use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.

the class AvailCalculatorTest method testNotAvailabileDuringTimeChunk.

@Test
public void testNotAvailabileDuringTimeChunk() {
    Date endTime = new Date(System.currentTimeMillis());
    Date startTime = new Date(endTime.getTime() - 100);
    TimeChunker chunker = new TimeChunker((int) (endTime.getTime() - startTime.getTime()), startTime, endTime);
    AvailCalculator calculator = new AvailCalculator(chunker);
    calculator.onStatusChange(createStatusChange(PollStatus.unavailable(), new Date(endTime.getTime() - 150)));
    calculator.onStatusChange(createStatusChange(PollStatus.available(), new Date(endTime.getTime() + 50)));
    Collection<OnmsMonitoredService> svcs = getServices();
    double uptimePercent = calculator.getAvailabilityFor(svcs, 0);
    assertEquals(0.0, uptimePercent, 0.00);
}
Also used : AvailCalculator(org.opennms.web.rest.v1.AvailCalculator) TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Aggregations

OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)119 Date (java.util.Date)37 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)33 Test (org.junit.Test)27 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)25 Transactional (org.springframework.transaction.annotation.Transactional)22 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)20 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)18 ArrayList (java.util.ArrayList)17 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)17 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)15 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)15 LinkedList (java.util.LinkedList)13 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)13 HashSet (java.util.HashSet)9 Before (org.junit.Before)6 Criteria (org.opennms.core.criteria.Criteria)5 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)5 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)5