Search in sources :

Example 21 with OnmsOutage

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

the class PollerIT method testNoDuplicateOutagesWithUpDownDown.

/**
 * Verifies that outages are properly opened and resolved
 * when events arrive out of order.
 *
 * See NMS-7519 for details.
 */
@Test
public void testNoDuplicateOutagesWithUpDownDown() throws InterruptedException {
    final MockService httpService = m_network.getService(2, "192.168.1.3", "HTTP");
    final MockService smtpService = m_network.getService(2, "192.168.1.3", "SMTP");
    // Start the poller
    startDaemons();
    // Starting with 0 outages
    List<OnmsOutage> httpOutages = getOutages(httpService);
    assertEquals(0, httpOutages.size());
    // Halts all nodeLostService events until at least 2
    // of them a queued.
    // 
    // The event bus should receive the following sequence:
    // nodeLostService
    // nodeGainedService
    // nodeLostService
    // 
    // We're looking to reorder them as follows:
    // nodeGainedService
    // nodeLostService
    // nodeLostService
    QueueMultipleDownsHook hook = new QueueMultipleDownsHook(2);
    m_eventMgr.setSendNowHook(hook);
    // Verify that the initial latch count is 2
    waitForHookCount(hook, 2);
    // Take the HTTP service down
    httpService.bringDown();
    // Wait for the latch count to decrease
    waitForHookCount(hook, 1);
    m_eventMgr.getEventAnticipator().reset();
    m_eventMgr.getEventAnticipator().anticipateEvent(httpService.createUpEvent());
    // Bring the HTTP service back up even though the nodeLostService
    // event is still pending
    httpService.bringUp();
    m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
    // Take the HTTP service down again
    httpService.bringDown();
    // Wait for the latch count to decrease and send the queued events
    waitForHookCount(hook, 0);
    m_eventMgr.getEventAnticipator().reset();
    m_eventMgr.getEventAnticipator().anticipateEvent(httpService.createUpEvent());
    // Bring the HTTP service back online
    httpService.bringUp();
    m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
    // We've succeeded in altering the order of events for the
    // HTTP service. Now we make sure that outage processing
    // continues to work as expeceted on a different service
    m_eventMgr.setSendNowHook(null);
    m_eventMgr.getEventAnticipator().reset();
    m_eventMgr.getEventAnticipator().anticipateEvent(httpService.createUpEvent());
    smtpService.bringDown();
    m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
    // Verifies that all of the outage fields are properly
    // set for both outages affecting the HTTP service,
    // even though the events we're send out of order
    httpOutages = getOutages(httpService);
    assertEquals(2, httpOutages.size());
    assertNotNull(httpOutages.get(0).getIfRegainedService());
    assertNotNull(httpOutages.get(0).getIfLostService());
    assertNotNull(httpOutages.get(0).getIfRegainedService());
    assertNotNull(httpOutages.get(0).getServiceRegainedEvent());
    assertNotNull(httpOutages.get(1).getIfRegainedService());
    assertNotNull(httpOutages.get(1).getIfLostService());
    assertNotNull(httpOutages.get(1).getIfRegainedService());
    assertNotNull(httpOutages.get(1).getServiceRegainedEvent());
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) MockService(org.opennms.netmgt.mock.MockService) Test(org.junit.Test)

Example 22 with OnmsOutage

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

the class PollerIT method closesOpenOutagesWithNoSvcLostEventIdOnRestart.

/**
 * Test for NMS-7585
 */
@Test
public void closesOpenOutagesWithNoSvcLostEventIdOnRestart() {
    MockNode node = m_network.getNode(2);
    MockService criticalService = m_network.getService(2, "192.168.1.3", "ICMP");
    // Bring the critical service down
    anticipateDown(node);
    criticalService.bringDown();
    // Start the poller
    startDaemons();
    // Verify
    verifyAnticipated(10000);
    // Stop the poller
    stopDaemons();
    // Remove the reference to the lost service event from all of the outages,
    // and let's pretend that they weren't even there in the first place
    Set<Integer> outageIds = new HashSet<>();
    for (OnmsOutage outage : m_outageDao.findAll()) {
        outage.setServiceLostEvent(null);
        m_outageDao.update(outage);
        outageIds.add(outage.getId());
    }
    m_outageDao.flush();
    // We should get another node down
    m_eventMgr.getEventAnticipator().anticipateEvent(node.createDownEvent());
    // (Re)start the poller
    startDaemons();
    // Verify
    m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
    // Wait for the outages to be populated (this happen after
    // the down event is sent)
    sleep(1000);
    for (OnmsOutage outage : m_outageDao.findAll()) {
        if (outageIds.contains(outage.getId())) {
            // Outages in our list should be closed with
            // no svcRegainedEvent
            assertNotNull(outage.getIfRegainedService());
            assertNull(outage.getServiceRegainedEvent());
        } else {
            // Other outages should be open
            assertNull(outage.getIfRegainedService());
        }
    }
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) MockService(org.opennms.netmgt.mock.MockService) MockNode(org.opennms.netmgt.mock.MockNode) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with OnmsOutage

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

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

the class OutageDaoIT method testSave.

@Test
@Transactional
public void testSave() {
    OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "localhost");
    m_nodeDao.save(node);
    OnmsIpInterface ipInterface = new OnmsIpInterface(addr("172.16.1.1"), node);
    OnmsServiceType serviceType = m_serviceTypeDao.findByName("ICMP");
    assertNotNull(serviceType);
    OnmsMonitoredService monitoredService = new OnmsMonitoredService(ipInterface, serviceType);
    OnmsEvent event = new OnmsEvent();
    OnmsOutage outage = new OnmsOutage(new Date(), monitoredService);
    outage.setServiceLostEvent(event);
    m_outageDao.save(outage);
    // it works we're so smart! hehe
    outage = m_outageDao.load(outage.getId());
    assertEquals("ICMP", outage.getMonitoredService().getServiceType().getName());
// outage.setEventBySvcRegainedEvent();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with OnmsOutage

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

the class PathOutageManagerDaoImpl method getLabelAndStatus.

/**
 * This method is responsible for determining the
 * node label of a node, and the up/down status
 * and status color
 *
 * @param nodeIDStr a {@link java.lang.String} object.
 * @param conn a {@link java.sql.Connection} object.
 * @return an array of {@link java.lang.String} objects.
 * @throws java.sql.SQLException if any.
 */
@Override
public String[] getLabelAndStatus(String nodeIDStr, Connection conn) {
    String[] result = new String[3];
    result[1] = "Cleared";
    result[2] = "Unmanaged";
    int nodeID = WebSecurityUtils.safeParseInt(nodeIDStr);
    OnmsNode node = nodeDao.get(nodeID);
    if (node == null) {
        // TODO Log that node could not be found in database
        return result;
    }
    result[0] = node.getLabel();
    final org.opennms.core.criteria.Criteria crit = new org.opennms.core.criteria.Criteria(OnmsMonitoredService.class).setAliases(Arrays.asList(new Alias[] { new Alias("ipInterface", "ipInterface", JoinType.INNER_JOIN) })).addRestriction(new EqRestriction("status", "A")).addRestriction(new EqRestriction("ipInterface.node", node));
    // Get all active services on the node
    List<OnmsMonitoredService> services = monitoredServiceDao.findMatching(crit);
    int countManagedSvcs = services.size();
    // Count how many of these services have open outages
    int countOutages = 0;
    for (OnmsMonitoredService service : services) {
        OnmsOutage out = outageDao.currentOutageForService(service);
        if (out != null) {
            countOutages++;
        }
    }
    if (countManagedSvcs == countOutages) {
        result[1] = "Critical";
        result[2] = "All Services Down";
    } else if (countOutages == 0) {
        result[1] = "Normal";
        result[2] = "All Services Up";
    } else {
        result[1] = "Minor";
        result[2] = "Some Services Down";
    }
    return result;
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

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