コード例 #1
0
  @Test
  public void testNodeGainedServiceWhileNodeDownAndServiceUp() {

    startDaemons();

    MockNode node = m_network.getNode(4);
    MockService svc = m_network.getService(4, "192.168.1.6", "SNMP");

    anticipateDown(node);

    node.bringDown();

    verifyAnticipated(5000);

    resetAnticipated();

    anticipateUp(node);
    anticipateDown(svc, true);

    MockService newSvc = m_network.addService(4, "192.168.1.6", "SMTP");

    m_db.writeService(newSvc);

    Event e = MockEventUtil.createNodeGainedServiceEvent("Test", newSvc);
    m_eventMgr.sendEventToListeners(e);

    sleep(5000);
    System.err.println(m_db.getOutages());

    verifyAnticipated(8000);
  }
コード例 #2
0
ファイル: AlarmdTest.java プロジェクト: lunar999/opennms
  private void sendNodeDownEventWithUpdateFieldSeverity(
      String reductionKey, MockNode node, OnmsSeverity severity) throws SQLException {
    EventBuilder event = MockEventUtil.createNodeDownEventBuilder("Test", node);

    if (reductionKey != null) {
      AlarmData data = new AlarmData();
      data.setAlarmType(1);
      data.setReductionKey(reductionKey);

      List<UpdateField> fields = new ArrayList<UpdateField>();

      UpdateField field = new UpdateField();
      field.setFieldName("Severity");
      field.setUpdateOnReduction(Boolean.TRUE);
      fields.add(field);

      data.setUpdateField(fields);

      event.setAlarmData(data);
    } else {
      event.setAlarmData(null);
    }

    event.setLogDest("logndisplay");
    event.setLogMessage("testing");

    event.setSeverity(severity.getLabel());

    m_eventdIpcMgr.sendNow(event.getEvent());
  }
コード例 #3
0
ファイル: AlarmdTest.java プロジェクト: lunar999/opennms
  private void sendNodeDownEventChangeLogMsg(String reductionKey, MockNode node, String logMsg) {

    EventBuilder event = MockEventUtil.createNodeDownEventBuilder("Test", node);

    if (reductionKey != null) {
      AlarmData data = new AlarmData();
      data.setAlarmType(1);
      data.setReductionKey(reductionKey);

      List<UpdateField> fields = new ArrayList<UpdateField>();

      UpdateField field = new UpdateField();
      field.setFieldName("logMsg");
      field.setUpdateOnReduction(Boolean.TRUE);
      fields.add(field);

      data.setUpdateField(fields);

      event.setAlarmData(data);
    } else {
      event.setAlarmData(null);
    }

    event.setLogDest("logndisplay");
    event.setLogMessage(logMsg);

    m_eventdIpcMgr.sendNow(event.getEvent());
  }
コード例 #4
0
 private void expectUpdateEvent() {
   m_eventManager
       .getEventAnticipator()
       .anticipateEvent(
           MockEventUtil.createEventBuilder("Test", EventConstants.SCHEDOUTAGES_CHANGED_EVENT_UEI)
               .getEvent());
 }
    @Override
    public boolean matches(Object actual) {
      if (!(actual instanceof Event)) {
        return false;
      }

      Event actualEvent = (Event) actual;
      return MockEventUtil.eventsMatchDeep(m_expected, actualEvent);
    }
コード例 #6
0
  @Test
  public void testSuspendPollingResumeService() {

    MockService svc = m_network.getService(1, "192.168.1.2", "SMTP");

    startDaemons();

    sleep(2000);
    assertTrue(0 < svc.getPollCount());

    m_eventMgr.sendEventToListeners(MockEventUtil.createSuspendPollingServiceEvent("Test", svc));
    svc.resetPollCount();

    sleep(5000);
    assertEquals(0, svc.getPollCount());

    m_eventMgr.sendEventToListeners(MockEventUtil.createResumePollingServiceEvent("Test", svc));

    sleep(2000);
    assertTrue(0 < svc.getPollCount());
  }
コード例 #7
0
 private void verifyAnticipated(long millis, boolean checkUnanticipated) {
   // make sure the down events are received
   MockEventUtil.printEvents(
       "Events we're still waiting for: ", m_anticipator.waitForAnticipated(millis));
   assertTrue("Expected events not forthcoming", m_anticipator.waitForAnticipated(0).isEmpty());
   if (checkUnanticipated) {
     sleep(2000);
     MockEventUtil.printEvents("Unanticipated: ", m_anticipator.unanticipatedEvents());
     assertEquals("Received unexpected events", 0, m_anticipator.unanticipatedEvents().size());
   }
   sleep(1000);
   m_eventMgr.finishProcessingEvents();
   assertEquals(
       "Wrong number of outages opened",
       m_outageAnticipator.getExpectedOpens(),
       m_outageAnticipator.getActualOpens());
   assertEquals(
       "Wrong number of outages in outage table",
       m_outageAnticipator.getExpectedOutages(),
       m_outageAnticipator.getActualOutages());
   assertTrue(
       "Created outages don't match the expected outages", m_outageAnticipator.checkAnticipated());
 }
コード例 #8
0
  // test open outages for unmanaged services
  @Test
  public void testUnmangedWithOpenOutageAtStartup() {
    // before we start we need to initialize the database

    // create an outage for the service
    MockService svc = m_network.getService(1, "192.168.1.1", "SMTP");
    MockInterface iface = m_network.getInterface(1, "192.168.1.2");

    Event svcLostEvent = MockEventUtil.createNodeLostServiceEvent("Test", svc);
    m_db.writeEvent(svcLostEvent);
    createOutages(svc, svcLostEvent);

    Event ifaceDownEvent = MockEventUtil.createInterfaceDownEvent("Test", iface);
    m_db.writeEvent(ifaceDownEvent);
    createOutages(iface, ifaceDownEvent);

    // mark the service as unmanaged
    m_db.setServiceStatus(svc, 'U');
    m_db.setInterfaceStatus(iface, 'U');

    // assert that we have an open outage
    assertEquals(1, m_db.countOpenOutagesForService(svc));
    assertEquals(1, m_db.countOutagesForService(svc));

    assertEquals(iface.getServices().size(), m_db.countOutagesForInterface(iface));
    assertEquals(iface.getServices().size(), m_db.countOpenOutagesForInterface(iface));

    startDaemons();

    // assert that we have no open outages
    assertEquals(0, m_db.countOpenOutagesForService(svc));
    assertEquals(1, m_db.countOutagesForService(svc));

    assertEquals(0, m_db.countOpenOutagesForInterface(iface));
    assertEquals(iface.getServices().size(), m_db.countOutagesForInterface(iface));
  }
コード例 #9
0
ファイル: AlarmdTest.java プロジェクト: lunar999/opennms
  private void sendNodeDownEvent(String reductionKey, MockNode node) throws SQLException {
    EventBuilder event = MockEventUtil.createNodeDownEventBuilder("Test", node);

    if (reductionKey != null) {
      AlarmData data = new AlarmData();
      data.setAlarmType(1);
      data.setReductionKey(reductionKey);
      event.setAlarmData(data);
    } else {
      event.setAlarmData(null);
    }

    event.setLogDest("logndisplay");
    event.setLogMessage("testing");

    m_eventdIpcMgr.sendNow(event.getEvent());
  }
コード例 #10
0
  // test open outages for unmanaged services
  @Test
  public void testReparentCausesStatusChange() {

    m_pollerConfig.setNodeOutageProcessingEnabled(true);

    MockNode node1 = m_network.getNode(1);
    MockNode node2 = m_network.getNode(2);

    MockInterface dotOne = m_network.getInterface(1, "192.168.1.1");
    MockInterface dotTwo = m_network.getInterface(1, "192.168.1.2");
    MockInterface dotThree = m_network.getInterface(2, "192.168.1.3");

    //
    // Plan to bring down both nodes except the reparented interface
    // the node owning the interface should be up while the other is down
    // after reparenting we should got the old owner go down while the other
    // comes up.
    //
    anticipateDown(node2);
    anticipateDown(dotOne);

    // bring down both nodes but bring iface back up
    node1.bringDown();
    node2.bringDown();
    dotTwo.bringUp();

    Event reparentEvent = MockEventUtil.createReparentEvent("Test", "192.168.1.2", 1, 2);

    startDaemons();

    verifyAnticipated(2000);

    m_db.reparentInterface(dotTwo.getIpAddr(), dotTwo.getNodeId(), node2.getNodeId());
    dotTwo.moveTo(node2);

    resetAnticipated();
    anticipateDown(node1, true);
    anticipateUp(node2, true);
    anticipateDown(dotThree, true);

    m_eventMgr.sendEventToListeners(reparentEvent);

    verifyAnticipated(20000);
  }
コード例 #11
0
  // interfaceReparented: EventConstants.INTERFACE_REPARENTED_EVENT_UEI
  @Test
  public void testInterfaceReparented() throws Exception {
    m_assertLevel = null;

    m_pollerConfig.setNodeOutageProcessingEnabled(true);

    MockNode node1 = m_network.getNode(1);
    MockNode node2 = m_network.getNode(2);

    assertNotNull("Node 1 should have 192.168.1.1", node1.getInterface("192.168.1.1"));
    assertNotNull("Node 1 should have 192.168.1.2", node1.getInterface("192.168.1.2"));

    assertNull("Node 2 should not yet have 192.168.1.2", node2.getInterface("192.168.1.2"));
    assertNotNull("Node 2 should have 192.168.1.3", node2.getInterface("192.168.1.3"));

    MockInterface dotTwo = m_network.getInterface(1, "192.168.1.2");
    MockInterface dotThree = m_network.getInterface(2, "192.168.1.3");

    Event reparentEvent = MockEventUtil.createReparentEvent("Test", "192.168.1.2", 1, 2);

    // we are going to reparent to node 2 so when we bring down its only
    // current interface we expect an interface down not the whole node.
    anticipateDown(dotThree);

    startDaemons();

    final int waitTime = 2000;
    final int verifyTime = 2000;

    sleep(waitTime);

    // move the reparented interface and send a reparented event
    dotTwo.moveTo(node2);
    m_db.reparentInterface(dotTwo.getIpAddr(), node1.getNodeId(), node2.getNodeId());

    // send the reparent event to the daemons
    m_eventMgr.sendEventToListeners(reparentEvent);

    sleep(waitTime);

    // now bring down the other interface on the new node
    // System.err.println("Bring Down:"+node2Iface);
    dotThree.bringDown();

    verifyAnticipated(verifyTime);

    resetAnticipated();
    anticipateDown(node2);

    // System.err.println("Bring Down:"+reparentedIface);
    dotTwo.bringDown();

    sleep(waitTime);

    verifyAnticipated(verifyTime);

    node1 = m_network.getNode(1);
    node2 = m_network.getNode(2);

    assertNotNull("Node 1 should still have 192.168.1.1", node1.getInterface("192.168.1.1"));
    assertNull("Node 1 should no longer have 192.168.1.2", node1.getInterface("192.168.1.2"));

    assertNotNull("Node 2 should now have 192.168.1.2", node2.getInterface("192.168.1.2"));
    assertNotNull("Node 2 should still have 192.168.1.3", node2.getInterface("192.168.1.3"));
  }