Search in sources :

Example 31 with MockService

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

the class PollablesIT method addDownServiceToDownNode.

private void addDownServiceToDownNode(int nodeId, String nodeLabel, String nodeLocation, String ipAddr, String existingSvcName, String newSvcName) {
    MockNode mNode = m_mockNetwork.getNode(nodeId);
    PollableService pExistingSvc = m_network.getService(nodeId, getInetAddress(ipAddr), existingSvcName);
    PollableInterface pIface = pExistingSvc.getInterface();
    PollableNode pNode = pExistingSvc.getNode();
    // before we start make sure the node is down
    anticipateDown(mNode);
    mNode.bringDown();
    pExistingSvc.doPoll();
    m_network.processStatusChange(new Date());
    verifyAnticipated();
    // ok the node is down.. here is the cause
    PollEvent nodeCause = pNode.getCause();
    // add a new mock service
    MockService mSvc = m_mockNetwork.addService(nodeId, ipAddr, newSvcName);
    m_db.writeService(mSvc);
    // that is down
    mSvc.bringDown();
    // expect nothing since we already have node down event outstanding
    // simulate a nodeGainedService event
    PollableService pSvc = addServiceToNetwork(nodeId, nodeLabel, nodeLocation, ipAddr, newSvcName);
    assertNotNull(pSvc);
    // before the first poll everthing should have the node down cause
    assertElementHasCause(pSvc, nodeCause);
    assertElementHasCause(pExistingSvc, nodeCause);
    assertElementHasCause(pIface, nodeCause);
    assertElementHasCause(pNode, nodeCause);
    // and should be mored down
    assertDown(pSvc);
    assertDown(pExistingSvc);
    assertDown(pIface);
    assertDown(pNode);
    // now to the first poll
    pSvc.doPoll();
    // everything should still be down
    assertDown(pSvc);
    assertDown(pExistingSvc);
    assertDown(pIface);
    assertDown(pNode);
    m_network.processStatusChange(new Date());
    // and should have the same node down cause
    assertElementHasCause(pSvc, nodeCause);
    assertElementHasCause(pExistingSvc, nodeCause);
    assertElementHasCause(pIface, nodeCause);
    assertElementHasCause(pNode, nodeCause);
    // verify we've received no events
    verifyAnticipated();
}
Also used : MockService(org.opennms.netmgt.mock.MockService) MockNode(org.opennms.netmgt.mock.MockNode) Date(java.util.Date)

Example 32 with MockService

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

the class PollerIT method sendNodeGainedServices.

private void sendNodeGainedServices(int nodeid, String nodeLabel, String ipAddr, String... svcNames) {
    assertNotNull(svcNames);
    assertTrue(svcNames.length > 0);
    MockNode node = m_network.addNode(nodeid, nodeLabel);
    m_db.writeNode(node);
    MockInterface iface = m_network.addInterface(nodeid, ipAddr);
    m_db.writeInterface(iface);
    List<MockService> services = new ArrayList<>();
    for (String svcName : svcNames) {
        MockService svc = m_network.addService(nodeid, ipAddr, svcName);
        m_db.writeService(svc);
        m_pollerConfig.addService(svc);
        services.add(svc);
    }
    MockVisitor gainSvcSender = new MockVisitorAdapter() {

        @Override
        public void visitService(MockService svc) {
            Event event = MockEventUtil.createNodeGainedServiceEvent("Test", svc);
            m_eventMgr.sendEventToListeners(event);
        }
    };
    node.visit(gainSvcSender);
    MockService svc1 = services.get(0);
    PollAnticipator anticipator = new PollAnticipator();
    svc1.addAnticipator(anticipator);
    anticipator.anticipateAllServices(svc1);
    final StringBuilder didNotOccur = new StringBuilder();
    for (MockService service : anticipator.waitForAnticipated(10000)) {
        didNotOccur.append(service.toString());
    }
    final StringBuilder unanticipatedStuff = new StringBuilder();
    for (MockService service : anticipator.unanticipatedPolls()) {
        unanticipatedStuff.append(service.toString());
    }
    assertEquals(unanticipatedStuff.toString(), "", didNotOccur.toString());
    anticipateDown(svc1);
    svc1.bringDown();
    verifyAnticipated(10000);
}
Also used : PollAnticipator(org.opennms.netmgt.mock.PollAnticipator) MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockInterface(org.opennms.netmgt.mock.MockInterface) MockVisitor(org.opennms.netmgt.mock.MockVisitor) ArrayList(java.util.ArrayList) MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) MockNode(org.opennms.netmgt.mock.MockNode)

Example 33 with MockService

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

the class PollerIT method testBug1564.

@Test
@Ignore
public void testBug1564() {
    // NODE processing = true;
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    MockNode node = m_network.getNode(2);
    MockService icmpService = m_network.getService(2, "192.168.1.3", "ICMP");
    MockService smtpService = m_network.getService(2, "192.168.1.3", "SMTP");
    MockService snmpService = m_network.getService(2, "192.168.1.3", "SNMP");
    // start the poller
    startDaemons();
    // 
    // Bring Down the HTTP service and expect nodeLostService Event
    // 
    resetAnticipated();
    anticipateDown(snmpService);
    // One service works fine
    snmpService.bringDown();
    verifyAnticipated(10000);
    // Now we simulate the restart, the node
    // looses all three at the same time
    resetAnticipated();
    anticipateDown(node);
    icmpService.bringDown();
    smtpService.bringDown();
    snmpService.bringDown();
    verifyAnticipated(10000);
    anticipateDown(smtpService);
    verifyAnticipated(10000);
    anticipateDown(snmpService);
    verifyAnticipated(10000);
    // This is to simulate a restart,
    // where I turn off the node behaviour
    m_pollerConfig.setNodeOutageProcessingEnabled(false);
    anticipateUp(snmpService);
    snmpService.bringUp();
    verifyAnticipated(10000);
    anticipateUp(smtpService);
    smtpService.bringUp();
    verifyAnticipated(10000);
    // Another restart - let's see if this will work?
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    // So everything is down, now
    // SNMP will regain and SMTP will regain
    // will the node come up?
    smtpService.bringDown();
    anticipateUp(smtpService);
    smtpService.bringUp();
    verifyAnticipated(10000, true);
    anticipateUp(snmpService);
    snmpService.bringUp();
    verifyAnticipated(10000);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) MockNode(org.opennms.netmgt.mock.MockNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 34 with MockService

use of org.opennms.netmgt.mock.MockService 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 35 with MockService

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

the class PollerIT method setUp.

// 
// SetUp and TearDown
// 
@Before
public void setUp() throws Exception {
    MockUtil.println("------------ Begin Test  --------------------------");
    MockLogAppender.setupLogging();
    m_network = new MockNetwork();
    m_network.setCriticalService("ICMP");
    m_network.addNode(1, "Router");
    m_network.addInterface("192.168.1.1");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addService("SNMP");
    m_network.addInterface("192.168.1.2");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addNode(2, "Server");
    m_network.addInterface("192.168.1.3");
    m_network.addService("ICMP");
    m_network.addService("HTTP");
    m_network.addService("SMTP");
    m_network.addService("SNMP");
    m_network.addNode(3, "Firewall");
    m_network.addInterface("192.168.1.4");
    m_network.addService("SMTP");
    m_network.addService("HTTP");
    m_network.addInterface("192.168.1.5");
    m_network.addService("SMTP");
    m_network.addService("HTTP");
    m_network.addNode(4, "DownNode");
    m_network.addInterface("192.168.1.6");
    m_network.addService("SNMP");
    m_network.addNode(5, "Loner");
    m_network.addInterface("192.168.1.7");
    m_network.addService("ICMP");
    m_network.addService("SNMP");
    MockService unmonitoredService = m_network.addService("NotMonitored");
    m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);
    m_pollerConfig = new MockPollerConfig(m_network);
    m_pollerConfig.setNextOutageIdSql(m_db.getNextOutageIdStatement());
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    m_pollerConfig.setCriticalService("ICMP");
    m_pollerConfig.addPackage("TestPackage");
    m_pollerConfig.addDowntime(1000L, 0L, -1L, false);
    m_pollerConfig.setDefaultPollInterval(1000L);
    m_pollerConfig.populatePackage(m_network, unmonitoredService);
    m_pollerConfig.addPackage("TestPkg2");
    m_pollerConfig.addDowntime(1000L, 0L, -1L, false);
    m_pollerConfig.setDefaultPollInterval(2000L);
    m_pollerConfig.addService(m_network.getService(2, "192.168.1.3", "HTTP"));
    m_outageAnticipator = new OutageAnticipator(m_db);
    m_eventMgr = new MockEventIpcManager();
    m_eventMgr.setEventWriter(m_db);
    m_eventMgr.setEventAnticipator(m_eventMgr.getEventAnticipator());
    m_eventMgr.addEventListener(m_outageAnticipator);
    m_eventMgr.setSynchronous(false);
    m_eventMgr.setNumSchedulerThreads(2);
    m_locationAwarePingClient = mock(LocationAwarePingClient.class);
    DefaultPollContext pollContext = new DefaultPollContext();
    pollContext.setEventManager(m_eventMgr);
    pollContext.setLocalHostName("localhost");
    pollContext.setName("Test.DefaultPollContext");
    pollContext.setPollerConfig(m_pollerConfig);
    pollContext.setQueryManager(m_queryManager);
    pollContext.setLocationAwarePingClient(m_locationAwarePingClient);
    PollableNetwork network = new PollableNetwork(pollContext);
    m_poller = new Poller();
    m_poller.setMonitoredServiceDao(m_monitoredServiceDao);
    m_poller.setOutageDao(m_outageDao);
    m_poller.setTransactionTemplate(m_transactionTemplate);
    m_poller.setEventIpcManager(m_eventMgr);
    m_poller.setNetwork(network);
    m_poller.setQueryManager(m_queryManager);
    m_poller.setPollerConfig(m_pollerConfig);
    m_poller.setPollOutagesConfig(m_pollerConfig);
    m_poller.setLocationAwarePollerClient(m_locationAwarePollerClient);
}
Also used : LocationAwarePingClient(org.opennms.netmgt.icmp.proxy.LocationAwarePingClient) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) MockService(org.opennms.netmgt.mock.MockService) OutageAnticipator(org.opennms.netmgt.mock.OutageAnticipator) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) PollableNetwork(org.opennms.netmgt.poller.pollables.PollableNetwork) Before(org.junit.Before)

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