Search in sources :

Example 36 with OnmsOutage

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

the class PollerIT method testNoDuplicateOutagesWithDownDownUp.

/**
 * Verifies that outages are properly opened and resolved
 * when events arrive out of order.
 *
 * See NMS-7394 for details.
 */
@Test
public void testNoDuplicateOutagesWithDownDownUp() {
    MockInterface nodeIf = m_network.getInterface(1, "192.168.1.1");
    MockService icmpService = m_network.getService(1, "192.168.1.1", "ICMP");
    MockService smtpService = m_network.getService(1, "192.168.1.1", "SMTP");
    // Start the poller
    startDaemons();
    // Kill the critical service on the interface and expect an interfaceDown:
    // The node in question has multiple interfaces, so we don't expect a nodeDown.
    resetAnticipated();
    anticipateDown(nodeIf);
    icmpService.bringDown();
    verifyAnticipated(10000);
    // There should now be a single outage for the SMTP service:
    // The critical service on the interface is down, so all
    // of the services on that interface are also marked as down.
    List<OnmsOutage> smtpOutages = getOutages(smtpService);
    assertEquals(1, smtpOutages.size());
    assertEquals(null, smtpOutages.get(0).getIfRegainedService());
    // Next, we will take the SMTP service offline and bring
    // the ICMP service online in order to make
    // the poller daemon generate a interfaceDown event
    // followed by a nodeLostService event.
    // 
    // The poller daemon will then  wait to receive these event back
    // from eventd, so that they are populated with the database ids.
    // 
    // When the interfaceDown event is received, it will close
    // the previous outages, and when the nodeLostService event is
    // received it will create a new outage.
    // 
    // If these events are received in a different order then which
    // they were sent, we will end up with two outages in the table.
    // This can happen, as observed in NMS-7394, if both events
    // are sent shortly one after another.
    // 
    // In order to test the behavior of pollerd, we manually
    // manipulate the order of these events.
    // Stops all other events until the nodeLostService has been processed
    EventOrderAlteringHook hook = new EventOrderAlteringHook(EventConstants.NODE_LOST_SERVICE_EVENT_UEI);
    m_eventMgr.setSendNowHook(hook);
    anticipateUp(nodeIf);
    anticipateDown(smtpService);
    smtpService.bringDown();
    icmpService.bringUp();
    verifyAnticipated(10000);
    // There should be two outages in the database:
    // one closed with the event id populated and another one pending
    smtpOutages = getOutages(smtpService);
    assertEquals(2, smtpOutages.size());
    assertNotNull(smtpOutages.get(0).getIfRegainedService());
    assertNotNull(smtpOutages.get(0).getServiceRegainedEvent());
    assertNull(smtpOutages.get(1).getIfRegainedService());
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) MockInterface(org.opennms.netmgt.mock.MockInterface) MockService(org.opennms.netmgt.mock.MockService) Test(org.junit.Test)

Example 37 with OnmsOutage

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

the class TimelineRestService method html.

@GET
@Produces("text/html")
@Transactional
@Path("html/{nodeId}/{ipAddress}/{serviceName}/{start}/{end}/{width}")
public Response html(@Context final UriInfo uriInfo, @PathParam("nodeId") final int nodeId, @PathParam("ipAddress") final String ipAddress, @PathParam("serviceName") final String serviceName, @PathParam("start") final long start, @PathParam("end") final long end, @PathParam("width") final int width) throws IOException {
    long delta = end - start;
    OnmsOutageCollection onmsOutageCollection = queryOutages(uriInfo, nodeId, ipAddress, serviceName, start, end);
    BufferedImage bufferedImage = new BufferedImage(width, 20, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = (Graphics2D) bufferedImage.getGraphics();
    graphics2D.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
    graphics2D.setColor(Color.BLACK);
    int numLabels = TimescaleDescriptor.computeNumberOfLabels(graphics2D, delta, width);
    final StringBuilder htmlBuffer = new StringBuilder();
    htmlBuffer.append("<img src=\"/opennms/rest/timeline/image/");
    htmlBuffer.append(nodeId);
    htmlBuffer.append("/");
    htmlBuffer.append(ipAddress);
    htmlBuffer.append("/");
    htmlBuffer.append(serviceName);
    htmlBuffer.append("/");
    htmlBuffer.append(start);
    htmlBuffer.append("/");
    htmlBuffer.append(end);
    htmlBuffer.append("/");
    htmlBuffer.append(width);
    htmlBuffer.append("\" usemap=\"#");
    htmlBuffer.append(nodeId);
    htmlBuffer.append("-");
    htmlBuffer.append(ipAddress);
    htmlBuffer.append("-");
    htmlBuffer.append(serviceName);
    htmlBuffer.append("\"><map name=\"");
    htmlBuffer.append(nodeId);
    htmlBuffer.append("-");
    htmlBuffer.append(ipAddress);
    htmlBuffer.append("-");
    htmlBuffer.append(serviceName);
    htmlBuffer.append("\">");
    for (TimescaleDescriptor desc : TIMESCALE_DESCRIPTORS) {
        if (desc.match(delta, numLabels)) {
            for (OnmsOutage onmsOutage : onmsOutageCollection) {
                htmlBuffer.append(desc.getMapEntry(graphics2D, delta, start, width, onmsOutage));
            }
            break;
        }
    }
    htmlBuffer.append("</map>");
    return Response.ok(htmlBuffer.toString()).build();
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsOutageCollection(org.opennms.netmgt.model.OnmsOutageCollection) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with OnmsOutage

use of org.opennms.netmgt.model.OnmsOutage 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 39 with OnmsOutage

use of org.opennms.netmgt.model.OnmsOutage 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 40 with OnmsOutage

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

the class DaoWebOutageRepository method mapOnmsOutageToOutage.

private Outage mapOnmsOutageToOutage(OnmsOutage onmsOutage) {
    if (onmsOutage != null) {
        Outage outage = new Outage();
        final String outageAddress = str(onmsOutage.getIpAddress());
        outage.outageId = onmsOutage.getId();
        outage.ipAddress = outageAddress;
        outage.hostname = outageAddress;
        outage.lostServiceTime = onmsOutage.getIfLostService();
        outage.regainedServiceTime = onmsOutage.getIfRegainedService();
        outage.serviceId = onmsOutage.getServiceId();
        outage.serviceName = onmsOutage.getMonitoredService() != null ? onmsOutage.getMonitoredService().getServiceName() : "";
        outage.suppressedBy = onmsOutage.getSuppressedBy();
        outage.suppressTime = onmsOutage.getSuppressTime();
        // Node-related fields
        outage.nodeId = onmsOutage.getNodeId();
        outage.location = "";
        final OnmsNode node = onmsOutage.getNode();
        if (node != null) {
            outage.nodeLabel = node.getLabel();
            if (node.getLocation() != null) {
                outage.location = node.getLocation().getLocationName();
            }
        }
        // Event-related fields
        final OnmsEvent event = onmsOutage.getServiceLostEvent();
        outage.lostServiceEventId = 0;
        outage.regainedServiceEventId = 0;
        if (event != null) {
            outage.lostServiceEventId = onmsOutage.getServiceLostEvent().getId();
            if (event.getDistPoller() != null) {
                outage.eventLocation = event.getDistPoller().getLocation();
            }
        }
        if (onmsOutage.getServiceRegainedEvent() != null) {
            outage.regainedServiceEventId = onmsOutage.getServiceRegainedEvent().getId();
        }
        return outage;
    } else {
        return null;
    }
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsOutage(org.opennms.netmgt.model.OnmsOutage)

Aggregations

OnmsOutage (org.opennms.netmgt.model.OnmsOutage)47 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)26 Date (java.util.Date)23 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)16 OnmsNode (org.opennms.netmgt.model.OnmsNode)12 Test (org.junit.Test)8 Transactional (org.springframework.transaction.annotation.Transactional)8 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 Alias (org.opennms.core.criteria.Alias)5 Criteria (org.opennms.core.criteria.Criteria)5 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)5 NullRestriction (org.opennms.core.criteria.restrictions.NullRestriction)5 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)4 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Before (org.junit.Before)3 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)3 Font (java.awt.Font)2