Search in sources :

Example 11 with MockService

use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.

the class CategoryModelIT method test.

@Test
public void test() throws SQLException {
    MockService service = m_network.getService(1, "192.168.1.1", "ICMP");
    MockService upSmtp = m_network.getService(1, "192.168.1.1", "SMTP");
    MockService upSnmp = m_network.getService(1, "192.168.1.1", "SNMP");
    // Generate some events for referential integrity
    Event[] events = new Event[10];
    for (int i = 0; i < events.length; i++) {
        events[i] = new Event();
        events[i].setTime(new Date());
        events[i].setCreationTime(new Date());
        events[i].setUei(EventConstants.NODE_LOST_SERVICE_EVENT_UEI);
        events[i].setSource(getClass().getSimpleName());
        events[i].setNodeid((long) service.getNodeId());
        events[i].setInterface(service.getIpAddr());
        events[i].setService(service.getSvcName());
        m_db.writeEvent(events[i]);
    }
    long startTime = 0L;
    long timeframe = 60L * 60L * 24L * 1000L;
    /// 24 HOUR TIMEFRAME
    // There are 3 services total
    assertEquals(100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(0), new Date(startTime + timeframe)), 0.0000001);
    // No downtime yet
    assertEquals(100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // Take down one service
    assertEquals(0, m_db.countOpenOutagesForService(service));
    m_db.createOutage(service, events[0].getDbid(), new Timestamp(0L));
    assertEquals(1, m_db.countOpenOutagesForService(service));
    /// 24 HOUR TIMEFRAME
    // There are 3 services total, one totally down, the other 2 up
    assertEquals(48.0 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // One hour of downtime
    assertEquals(0.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    timeframe = 60L * 60L * 4L * 1000L;
    /// 4 HOUR TIMEFRAME
    // There are 3 services total, one totally down, the other 2 up
    assertEquals(8.0 / 12.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // One hour of downtime
    assertEquals(0.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // Bring the service back up after 2 hours
    m_db.resolveOutage(service, events[1].getDbid(), new Timestamp(2L * 60L * 60L * 1000L));
    assertEquals(0, m_db.countOpenOutagesForService(service));
    timeframe = 60L * 60L * 24L * 1000L;
    /// 24 HOUR TIMEFRAME
    // There are 3 services total
    assertEquals(70.0 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // One hour of downtime
    assertEquals(22.0 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // Shift the start time forward 30 minutes so that we only see 30 minutes of downtime
    startTime = 30L * 60L * 1000L;
    /// 24 HOUR TIMEFRAME
    // There are 3 services total
    assertEquals(70.5 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // One hour of downtime
    assertEquals(22.5 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    startTime = 0L;
    timeframe = 60L * 60L * 4L * 1000L;
    /// 4 HOUR TIMEFRAME
    // There are 3 services total
    assertEquals(10.0 / 12.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // One hour of downtime
    assertEquals(2.0 / 4.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    startTime = 0L;
    timeframe = 60L * 60L * 24L * 1000L;
    // Take down the service again at the 23 hour mark
    assertEquals(0, m_db.countOpenOutagesForService(service));
    m_db.createOutage(service, events[2].getDbid(), new Timestamp(23L * 60L * 60L * 1000L));
    assertEquals(1, m_db.countOpenOutagesForService(service));
    /// 24 HOUR TIMEFRAME
    // There are 3 services total, one totally down, the other 2 up
    assertEquals(69.0 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // One hour of downtime
    assertEquals(21.0 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // Shift the start time forward 60 minutes so that we only see 60 minutes of downtime
    // from the first outage and 2 hours from the second outage
    startTime = 60L * 60L * 1000L;
    /// 24 HOUR TIMEFRAME
    // There are 3 services total
    assertEquals(69.0 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // One hour of downtime
    assertEquals(21.0 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // Bring the service back up after 1.5 hours
    m_db.resolveOutage(service, events[3].getDbid(), new Timestamp((24L * 60L * 60L * 1000L) + /* 24 hours */
    (30L * 60L * 1000L)));
    assertEquals(0, m_db.countOpenOutagesForService(service));
    startTime = 0L;
    timeframe = 60L * 60L * 24L * 1000L;
    /// 24 HOUR TIMEFRAME
    // There are 3 services total
    assertEquals(69.0 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // One hour of downtime
    assertEquals(21.0 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // Shift the start time forward 60 minutes so that we only see 60 minutes of downtime
    // from the first outage and 1.5 hours from the second outage
    startTime = 60L * 60L * 1000L;
    /// 24 HOUR TIMEFRAME
    // There are 3 services total
    assertEquals(69.5 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    // One hour of downtime
    assertEquals(21.5 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
    assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.Test)

Example 12 with MockService

use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.

the class PollerIT method anticipateServicesDown.

private void anticipateServicesDown(MockElement node) {
    MockVisitor eventCreator = new MockVisitorAdapter() {

        @Override
        public void visitService(MockService svc) {
            anticipateDown(svc);
        }
    };
    node.visit(eventCreator);
}
Also used : MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockVisitor(org.opennms.netmgt.mock.MockVisitor) MockService(org.opennms.netmgt.mock.MockService)

Example 13 with MockService

use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.

the class PollerIT method restoresServiceStateOnRestart.

@Test
public void restoresServiceStateOnRestart() {
    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();
    // Bring the critical service up and expect a nodeUp
    // The service should restore the proper state and know that the outage
    // was triggered by a node down
    anticipateUp(node);
    criticalService.bringUp();
    // (Re)start the poller
    startDaemons();
    // Verify
    verifyAnticipated(10000);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 14 with MockService

use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.

the class PollerIT method testServiceDeleted.

// serviceDeleted: EventConstants.SERVICE_DELETED_EVENT_UEI
@Test
public void testServiceDeleted() {
    MockService svc = m_network.getService(1, "192.168.1.1", "SMTP");
    testElementDeleted(svc);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Test(org.junit.Test)

Example 15 with MockService

use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.

the class PollerIT method bringDownCritSvcs.

private void bringDownCritSvcs(MockElement element) {
    MockVisitor markCritSvcDown = new MockVisitorAdapter() {

        @Override
        public void visitService(MockService svc) {
            if ("ICMP".equals(svc.getSvcName())) {
                svc.bringDown();
            }
        }
    };
    element.visit(markCritSvcDown);
}
Also used : MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockVisitor(org.opennms.netmgt.mock.MockVisitor) MockService(org.opennms.netmgt.mock.MockService)

Aggregations

MockService (org.opennms.netmgt.mock.MockService)59 Test (org.junit.Test)36 Event (org.opennms.netmgt.xml.event.Event)19 MockNode (org.opennms.netmgt.mock.MockNode)16 MockVisitor (org.opennms.netmgt.mock.MockVisitor)14 MockVisitorAdapter (org.opennms.netmgt.mock.MockVisitorAdapter)14 Date (java.util.Date)8 MockInterface (org.opennms.netmgt.mock.MockInterface)8 Timestamp (java.sql.Timestamp)3 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)3 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2 Querier (org.opennms.core.utils.Querier)2 PollAnticipator (org.opennms.netmgt.mock.PollAnticipator)2 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)1 LocationAwarePingClient (org.opennms.netmgt.icmp.proxy.LocationAwarePingClient)1 MockNetwork (org.opennms.netmgt.mock.MockNetwork)1