Esempio n. 1
0
  private void sendNewSuspectEvent(InetAddress address, Long rtt, String foreignSource) {
    EventBuilder eb =
        new EventBuilder(EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI, "OpenNMS.Discovery");
    eb.setInterface(address);
    eb.setHost(InetAddressUtils.getLocalHostName());

    eb.addParam("RTT", rtt);

    if (foreignSource != null) {
      eb.addParam("foreignSource", foreignSource);
    }

    try {
      m_ipc_manager.sendNow(eb.getEvent());
      LOG.debug("Sent event: {}", EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI);
    } catch (Throwable t) {
      LOG.warn("run: unexpected throwable exception caught during send to middleware", t);
    }
  }
Esempio n. 2
0
  /**
   * mergeIpInterfaces
   *
   * @param scannedNode a {@link org.opennms.netmgt.model.OnmsNode} object.
   * @param eventForwarder a {@link org.opennms.netmgt.events.api.EventForwarder} object.
   * @param deleteMissing a boolean.
   */
  public void mergeIpInterfaces(
      OnmsNode scannedNode, EventForwarder eventForwarder, boolean deleteMissing) {
    OnmsIpInterface oldPrimaryInterface = null;
    OnmsIpInterface scannedPrimaryIf = null;
    // build a map of ipAddrs to ipInterfaces for the scanned node
    Map<InetAddress, OnmsIpInterface> ipInterfaceMap = new HashMap<InetAddress, OnmsIpInterface>();
    for (OnmsIpInterface iface : scannedNode.getIpInterfaces()) {
      if (scannedPrimaryIf == null && iface.isPrimary()) {
        scannedPrimaryIf = iface;
      } else if (iface.isPrimary()) {
        iface.setIsSnmpPrimary(PrimaryType.SECONDARY);
      }

      ipInterfaceMap.put(iface.getIpAddress(), iface);
    }

    // for each ipInterface from the database
    for (Iterator<OnmsIpInterface> it = getIpInterfaces().iterator(); it.hasNext(); ) {
      OnmsIpInterface dbIface = it.next();
      // find the corresponding scanned Interface
      OnmsIpInterface scannedIface = ipInterfaceMap.get(dbIface.getIpAddress());

      // if we can't find a scanned interface remove from the database
      if (scannedIface == null) {
        if (deleteMissing) {
          it.remove();
          dbIface.visit(new DeleteEventVisitor(eventForwarder));
        } else if (scannedPrimaryIf != null && dbIface.isPrimary()) {
          dbIface.setIsSnmpPrimary(PrimaryType.SECONDARY);
          oldPrimaryInterface = dbIface;
        }
      } else {
        // else update the database with scanned info
        dbIface.mergeInterface(scannedIface, eventForwarder, deleteMissing);
        if (scannedPrimaryIf != null && dbIface.isPrimary() && scannedPrimaryIf != scannedIface) {
          dbIface.setIsSnmpPrimary(PrimaryType.SECONDARY);
          oldPrimaryInterface = dbIface;
        }
      }

      // now remove the interface from the map to indicate it was processed
      ipInterfaceMap.remove(dbIface.getIpAddress());
    }

    // for any remaining scanned interfaces, add them to the database
    for (OnmsIpInterface iface : ipInterfaceMap.values()) {
      addIpInterface(iface);
      if (iface.getIfIndex() != null) {
        iface.setSnmpInterface(getSnmpInterfaceWithIfIndex(iface.getIfIndex()));
      }
      iface.visit(new AddEventVisitor(eventForwarder));
    }

    if (oldPrimaryInterface != null && scannedPrimaryIf != null) {
      EventBuilder bldr =
          new EventBuilder(EventConstants.PRIMARY_SNMP_INTERFACE_CHANGED_EVENT_UEI, "Provisiond");
      bldr.setIpInterface(scannedPrimaryIf);
      bldr.setService("SNMP");
      bldr.addParam(
          EventConstants.PARM_OLD_PRIMARY_SNMP_ADDRESS,
          InetAddressUtils.str(oldPrimaryInterface.getIpAddress()));
      bldr.addParam(
          EventConstants.PARM_NEW_PRIMARY_SNMP_ADDRESS,
          InetAddressUtils.str(scannedPrimaryIf.getIpAddress()));

      eventForwarder.sendNow(bldr.getEvent());
    }
  }
Esempio n. 3
0
  /**
   * mergeNodeAttributes
   *
   * @param scannedNode a {@link org.opennms.netmgt.model.OnmsNode} object.
   */
  public void mergeNodeAttributes(final OnmsNode scannedNode, final EventForwarder eventForwarder) {
    final String scannedLabel = scannedNode.getLabel();

    boolean send = false;

    if (m_oldLabel != null || m_oldLabelSource != null) {
      send = true;
    } else if (hasNewValue(scannedLabel, getLabel())) {
      m_oldLabel = getLabel();
      m_oldLabelSource = getLabelSource();
      send = true;
    }

    if (send) {
      LOG.debug("mergeNodeAttributes(): sending NODE_LABEL_CHANGED_EVENT_UEI");
      // Create a NODE_LABEL_CHANGED_EVENT_UEI event
      final EventBuilder bldr =
          new EventBuilder(
              EventConstants.NODE_LABEL_CHANGED_EVENT_UEI, "OnmsNode.mergeNodeAttributes");

      bldr.setNodeid(scannedNode.getId());
      bldr.setHost(InetAddressUtils.getLocalHostAddressAsString());

      if (m_oldLabel != null) {
        bldr.addParam(EventConstants.PARM_OLD_NODE_LABEL, m_oldLabel);
        if (m_oldLabelSource != null) {
          bldr.addParam(EventConstants.PARM_OLD_NODE_LABEL_SOURCE, m_oldLabelSource.toString());
        }
      }

      if (scannedLabel != null) {
        bldr.addParam(EventConstants.PARM_NEW_NODE_LABEL, scannedLabel);
        if (scannedNode.getLabelSource() != null) {
          bldr.addParam(
              EventConstants.PARM_NEW_NODE_LABEL_SOURCE, scannedNode.getLabelSource().toString());
        }
      }

      m_oldLabel = null;
      m_oldLabelSource = null;

      eventForwarder.sendNow(bldr.getEvent());

      // Update the node label value
      m_label = scannedLabel;
    } else {
      LOG.debug("mergeNodeAttributes(): skipping event.");
    }

    if (hasNewValue(scannedNode.getForeignSource(), getForeignSource())) {
      setForeignSource(scannedNode.getForeignSource());
    }

    if (hasNewValue(scannedNode.getForeignId(), getForeignId())) {
      setForeignId(scannedNode.getForeignId());
    }

    if (hasNewValue(scannedNode.getLabelSource(), getLabelSource())) {
      setLabelSource(scannedNode.getLabelSource());
    }

    if (hasNewValue(scannedNode.getNetBiosName(), getNetBiosDomain())) {
      setNetBiosName(scannedNode.getNetBiosDomain());
    }

    if (hasNewValue(scannedNode.getNetBiosDomain(), getNetBiosDomain())) {
      setNetBiosDomain(scannedNode.getNetBiosDomain());
    }

    if (hasNewValue(scannedNode.getOperatingSystem(), getOperatingSystem())) {
      setOperatingSystem(scannedNode.getOperatingSystem());
    }

    mergeAgentAttributes(scannedNode);

    mergeAdditionalCategories(scannedNode);
  }