@Test
  @DirtiesContext
  @Ignore("not yet implemented")
  public void testMultipleDownAndSingleUpCase() throws Exception {

    // Get engine
    DroolsCorrelationEngine engine = findEngineByName("monolithicDependencyRules");

    // Anticipate down event
    getAnticipator().reset();
    anticipate(
        createComponentImpactedEvent(
            "ServiceElementComponent",
            "jnxVpnPw-vcid(50)",
            "NA-SvcElemComp",
            "9876,jnxVpnPw-vcid(50)",
            17));
    anticipate(
        createComponentImpactedEvent("ServiceElement", "PE2,SE1", "NA-ServiceElement", "9876", 17));
    anticipate(createComponentImpactedEvent("Service", "CokeP2P", "NA-Service", "123", 17));

    // Generate down event
    Event event = createVpnPwDownEvent(m_pe2NodeId, "10.1.1.1", "5", "ge-3/1/4.50");
    event.setDbid(17);
    System.err.println("SENDING VpnPwDown EVENT!!");
    engine.correlate(event);

    // Check down event
    getAnticipator().verifyAnticipated();

    // Generate additional down event - nothing should happen
    getAnticipator().reset();
    event = createVpnPwDownEvent(m_pe2NodeId, "10.1.1.1", "5", "ge-3/1/4.50");
    event.setDbid(18);
    System.err.println("SENDING VpnPwDown EVENT!!");
    engine.correlate(event);
    getAnticipator().verifyAnticipated();

    // Anticipate up event
    getAnticipator().reset();
    anticipate(
        createComponentResolvedEvent(
            "ServiceElementComponent",
            "jnxVpnPw-vcid(50)",
            "NA-SvcElemComp",
            "9876,jnxVpnPw-vcid(50)",
            17));
    anticipate(
        createComponentResolvedEvent("ServiceElement", "PE2,SE1", "NA-ServiceElement", "9876", 17));
    anticipate(createComponentResolvedEvent("Service", "CokeP2P", "NA-Service", "123", 17));

    // Generate up event
    event = createVpnPwUpEvent(m_pe2NodeId, "10.1.1.1", "5", "ge-3/1/4.50");
    event.setDbid(17);
    System.err.println("SENDING VpnPwUp EVENT!!");
    engine.correlate(event);

    // Check up event
    getAnticipator().verifyAnticipated();
  }
예제 #2
0
  @Test
  @JUnitTemporaryDatabase(
      tempDbClass = MockDatabase.class) // Relies on specific IDs so we need a fresh database
  public void testNorthbounder() throws Exception {
    assertTrue(m_northbounder.isInitialized());
    assertTrue(m_northbounder.getAlarms().isEmpty());

    final EventBuilder bldr = new EventBuilder("testNoLogmsg", "AlarmdTest");
    bldr.setAlarmData(new AlarmData());
    bldr.setLogMessage("This is a test.");

    final Event event = bldr.getEvent();
    event.setDbid(17);

    MockNode node = m_mockNetwork.getNode(1);
    sendNodeDownEvent("%nodeid%", node);

    final List<NorthboundAlarm> alarms = m_northbounder.getAlarms();
    assertTrue(alarms.size() > 0);
  }
  @Test
  @DirtiesContext
  @Ignore("Non Deterministic!!!")
  public void testDependencyAnyRules() throws Exception {

    // Get engine
    DroolsCorrelationEngine engine = findEngineByName("monolithicDependencyRules");

    // Anticipate component lspA down event
    getAnticipator().reset();
    anticipate(
        createComponentImpactedEvent(
            "ServiceElementComponent", "lspA-PE1-PE2", "NA-SvcElemComp", "8765,lspA-PE1-PE2", 17));
    // Generate down event
    Event event = createMplsLspPathDownEvent(m_pe1NodeId, "10.1.1.1", "lspA-PE1-PE2");
    event.setDbid(17);
    System.err.println("SENDING MplsLspPathDown on LspA EVENT!!");
    engine.correlate(event);
    // Check down event
    getAnticipator().verifyAnticipated();

    // Anticipate component lspB down event
    // Parent should go down too
    getAnticipator().reset();
    anticipate(
        createComponentImpactedEvent(
            "ServiceElementComponent", "lspB-PE1-PE2", "NA-SvcElemComp", "8765,lspB-PE1-PE2", 18));
    anticipate(
        createComponentImpactedEvent(
            "ServiceElementComponent",
            "jnxVpnPw-vcid(50)",
            "NA-SvcElemComp",
            "8765,jnxVpnPw-vcid(50)",
            18));
    anticipate(
        createComponentImpactedEvent("ServiceElement", "PE1,SE1", "NA-ServiceElement", "8765", 18));
    anticipate(createComponentImpactedEvent("Service", "CokeP2P", "NA-Service", "123", 18));

    // anticipate(  createComponentImpactedEvent( "Service", "NA-Service", "123", 17 ) );
    // Generate down event
    event = createMplsLspPathDownEvent(m_pe1NodeId, "10.1.1.1", "lspB-PE1-PE2");
    event.setDbid(18);
    System.err.println("SENDING MplsLspPathDown on LspB EVENT!!");
    engine.correlate(event);
    // Check down event
    getAnticipator().verifyAnticipated();

    // Anticipate up event
    getAnticipator().reset();
    anticipate(
        createComponentResolvedEvent(
            "ServiceElementComponent", "lspA-PE1-PE2", "NA-SvcElemComp", "8765,lspA-PE1-PE2", 18));
    anticipate(
        createComponentResolvedEvent(
            "ServiceElementComponent",
            "jnxVpnPw-vcid(50)",
            "NA-SvcElemComp",
            "8765,jnxVpnPw-vcid(50)",
            18));
    anticipate(
        createComponentResolvedEvent("ServiceElement", "PE1,SE1", "NA-ServiceElement", "8765", 18));
    anticipate(createComponentResolvedEvent("Service", "CokeP2P", "NA-Service", "123", 18));

    // Generate up event
    event = createMplsLspPathUpEvent(m_pe1NodeId, "10.1.1.1", "lspA-PE1-PE2");
    event.setDbid(17);
    System.err.println("SENDING MplsLspPathUp on LspA EVENT!!");
    engine.correlate(event);

    // Check up event
    getAnticipator().verifyAnticipated();
  }
예제 #4
0
  /**
   * Insert values into the EVENTS table
   *
   * @exception java.sql.SQLException Thrown if there is an error adding the event to the database.
   * @exception java.lang.NullPointerException Thrown if a required resource cannot be found in the
   *     properties file.
   */
  private void insertEvent(final Header eventHeader, final Event event, final Connection connection)
      throws SQLException {
    // Execute the statement to get the next event id
    final int eventID = getNextId();

    LOG.debug("DBID: {}", eventID);

    synchronized (event) {
      event.setDbid(eventID);
    }
    final DBUtils d = new DBUtils(getClass());

    try {
      final PreparedStatement insStmt =
          connection.prepareStatement(EventdConstants.SQL_DB_INS_EVENT);
      d.watch(insStmt);

      // eventID
      insStmt.setInt(1, eventID);

      // eventUEI
      insStmt.setString(2, Constants.format(event.getUei(), EVENT_UEI_FIELD_SIZE));

      // nodeID
      final Long nodeid = event.getNodeid();
      set(insStmt, 3, event.hasNodeid() ? nodeid.intValue() : -1);

      // eventTime
      insStmt.setTimestamp(4, getEventTime(event));

      // Resolve the event host to a hostname using the ipInterface table
      String hostname = getEventHost(event);

      // eventHost
      set(insStmt, 5, Constants.format(hostname, EVENT_HOST_FIELD_SIZE));

      // ipAddr
      set(insStmt, 6, Constants.format(event.getInterface(), EVENT_INTERFACE_FIELD_SIZE));

      // eventDpName
      String dpName = "localhost";
      if (eventHeader != null && eventHeader.getDpName() != null) {
        dpName = Constants.format(eventHeader.getDpName(), EVENT_DPNAME_FIELD_SIZE);
      } else if (event.getDistPoller() != null) {
        dpName = Constants.format(event.getDistPoller(), EVENT_DPNAME_FIELD_SIZE);
      }
      insStmt.setString(7, dpName);

      // eventSnmpHost
      set(insStmt, 8, Constants.format(event.getSnmphost(), EVENT_SNMPHOST_FIELD_SIZE));

      // service identifier - convert the service name to a service id
      set(insStmt, 9, getEventServiceId(event));

      // eventSnmp
      if (event.getSnmp() != null) {
        insStmt.setString(10, SnmpInfo.format(event.getSnmp(), EVENT_SNMP_FIELD_SIZE));
      } else {
        insStmt.setNull(10, Types.VARCHAR);
      }

      // eventParms

      // Replace any null bytes with a space, otherwise postgres will complain about encoding in
      // UNICODE
      final String parametersString = Parameter.format(event);
      set(insStmt, 11, Constants.format(parametersString, 0));

      // eventCreateTime
      final Timestamp eventCreateTime = new Timestamp(System.currentTimeMillis());
      insStmt.setTimestamp(12, eventCreateTime);

      // eventDescr
      set(insStmt, 13, Constants.format(event.getDescr(), 0));

      // eventLoggroup
      set(
          insStmt,
          14,
          (event.getLoggroupCount() > 0)
              ? Constants.format(event.getLoggroup(), EVENT_LOGGRP_FIELD_SIZE)
              : null);

      // eventLogMsg
      // eventLog
      // eventDisplay
      if (event.getLogmsg() != null) {
        // set log message
        set(insStmt, 15, Constants.format(event.getLogmsg().getContent(), 0));
        String logdest = event.getLogmsg().getDest();
        if (logdest.equals("logndisplay")) {
          // if 'logndisplay' set both log and display column to yes
          set(insStmt, 16, MSG_YES);
          set(insStmt, 17, MSG_YES);
        } else if (logdest.equals("logonly")) {
          // if 'logonly' set log column to true
          set(insStmt, 16, MSG_YES);
          set(insStmt, 17, MSG_NO);
        } else if (logdest.equals("displayonly")) {
          // if 'displayonly' set display column to true
          set(insStmt, 16, MSG_NO);
          set(insStmt, 17, MSG_YES);
        } else if (logdest.equals("suppress")) {
          // if 'suppress' set both log and display to false
          set(insStmt, 16, MSG_NO);
          set(insStmt, 17, MSG_NO);
        }
      } else {
        insStmt.setNull(15, Types.VARCHAR);

        /*
         * If this is an event that had no match in the event conf
         * mark it as to be logged and displayed so that there
         * are no events that slip through the system
         * without the user knowing about them
         */
        set(insStmt, 17, MSG_YES);
      }

      // eventSeverity
      set(insStmt, 18, OnmsSeverity.get(event.getSeverity()).getId());

      // eventPathOutage
      set(
          insStmt,
          19,
          (event.getPathoutage() != null)
              ? Constants.format(event.getPathoutage(), EVENT_PATHOUTAGE_FIELD_SIZE)
              : null);

      // eventCorrelation
      set(
          insStmt,
          20,
          (event.getCorrelation() != null)
              ? org.opennms.netmgt.dao.util.Correlation.format(
                  event.getCorrelation(), EVENT_CORRELATION_FIELD_SIZE)
              : null);

      // eventSuppressedCount
      insStmt.setNull(21, Types.INTEGER);

      // eventOperInstruct
      set(insStmt, 22, Constants.format(event.getOperinstruct(), EVENT_OPERINSTRUCT_FIELD_SIZE));

      // eventAutoAction
      set(
          insStmt,
          23,
          (event.getAutoactionCount() > 0)
              ? AutoAction.format(event.getAutoaction(), EVENT_AUTOACTION_FIELD_SIZE)
              : null);

      // eventOperAction / eventOperActionMenuText
      if (event.getOperactionCount() > 0) {
        final List<Operaction> a = new ArrayList<Operaction>();
        final List<String> b = new ArrayList<String>();

        for (final Operaction eoa : event.getOperactionCollection()) {
          a.add(eoa);
          b.add(eoa.getMenutext());
        }

        set(insStmt, 24, OperatorAction.format(a, EVENT_OPERACTION_FIELD_SIZE));
        set(insStmt, 25, Constants.format(b, EVENT_OPERACTION_MENU_FIELD_SIZE));
      } else {
        insStmt.setNull(24, Types.VARCHAR);
        insStmt.setNull(25, Types.VARCHAR);
      }

      // eventNotification, this column no longer needed
      insStmt.setNull(26, Types.VARCHAR);

      // eventTroubleTicket / eventTroubleTicket state
      if (event.getTticket() != null) {
        set(
            insStmt,
            27,
            Constants.format(event.getTticket().getContent(), EVENT_TTICKET_FIELD_SIZE));
        set(insStmt, 28, event.getTticket().getState().equals("on") ? 1 : 0);
      } else {
        insStmt.setNull(27, Types.VARCHAR);
        insStmt.setNull(28, Types.INTEGER);
      }

      // eventForward
      set(
          insStmt,
          29,
          (event.getForwardCount() > 0)
              ? org.opennms.netmgt.dao.util.Forward.format(
                  event.getForward(), EVENT_FORWARD_FIELD_SIZE)
              : null);

      // event mouseOverText
      set(insStmt, 30, Constants.format(event.getMouseovertext(), EVENT_MOUSEOVERTEXT_FIELD_SIZE));

      // eventAckUser
      if (event.getAutoacknowledge() != null
          && event.getAutoacknowledge().getState().equals("on")) {
        set(
            insStmt,
            31,
            Constants.format(event.getAutoacknowledge().getContent(), EVENT_ACKUSER_FIELD_SIZE));

        // eventAckTime - if autoacknowledge is present,
        // set time to event create time
        set(insStmt, 32, eventCreateTime);
      } else {
        insStmt.setNull(31, Types.INTEGER);
        insStmt.setNull(32, Types.TIMESTAMP);
      }

      // eventSource
      set(insStmt, 33, Constants.format(event.getSource(), EVENT_SOURCE_FIELD_SIZE));

      // ifindex
      if (event.hasIfIndex()) {
        set(insStmt, 34, event.getIfIndex());
      } else {
        insStmt.setNull(34, Types.INTEGER);
      }

      // execute
      insStmt.executeUpdate();
    } finally {
      d.cleanUp();
    }

    LOG.debug("SUCCESSFULLY added {} related  data into the EVENTS table.", event.getUei());
  }