/**
   * sendLabelChangeEvent
   *
   * @param nodeId a int.
   * @param oldNodeLabel a {@link org.opennms.netmgt.utils.NodeLabelJDBCImpl} object.
   * @param newNodeLabel a {@link org.opennms.netmgt.utils.NodeLabelJDBCImpl} object.
   * @throws org.opennms.netmgt.model.events.EventProxyException if any.
   */
  protected void sendLabelChangeEvent(
      int nodeId, NodeLabelJDBCImpl oldNodeLabel, NodeLabelJDBCImpl newNodeLabel)
      throws EventProxyException {

    EventBuilder bldr =
        new EventBuilder(EventConstants.NODE_LABEL_CHANGED_EVENT_UEI, "NodeLabelChangeServlet");

    bldr.setNodeid(nodeId);
    bldr.setHost("host");

    if (oldNodeLabel != null) {
      bldr.addParam(EventConstants.PARM_OLD_NODE_LABEL, oldNodeLabel.getLabel());
      if (oldNodeLabel.getSource() != null) {
        bldr.addParam(
            EventConstants.PARM_OLD_NODE_LABEL_SOURCE, oldNodeLabel.getSource().toString());
      }
    }

    if (newNodeLabel != null) {
      bldr.addParam(EventConstants.PARM_NEW_NODE_LABEL, newNodeLabel.getLabel());
      if (newNodeLabel.getSource() != null) {
        bldr.addParam(
            EventConstants.PARM_NEW_NODE_LABEL_SOURCE, newNodeLabel.getSource().toString());
      }
    }

    this.proxy.send(bldr.getEvent());
  }
Exemplo n.º 2
0
  /**
   * Send a newSuspect event for the interface construct event with 'linkd' as source
   *
   * @param ipInterface The interface for which the newSuspect event is to be generated
   * @param ipowner The host that hold this ipInterface information
   * @pkgName The package Name of the ready runnable involved
   */
  void sendNewSuspectEvent(InetAddress ipaddress, InetAddress ipowner, String pkgName) {

    if (m_newSuspectEventsIpAddr.contains(ipaddress)) {
      LogUtils.infof(
          this,
          "sendNewSuspectEvent: nothing to send, suspect event previously sent for IP address: %s",
          str(ipaddress));
      return;
    } else if (!isInterfaceInPackageRange(ipaddress, pkgName)) {
      LogUtils.infof(
          this,
          "sendNewSuspectEvent: nothing to send for IP address: %s, not in package: %s",
          str(ipaddress),
          pkgName);
      return;
    }

    org.opennms.netmgt.config.linkd.Package pkg = m_linkdConfig.getPackage(pkgName);

    boolean autodiscovery = false;
    if (pkg.hasAutoDiscovery()) autodiscovery = pkg.getAutoDiscovery();
    else autodiscovery = m_linkdConfig.isAutoDiscoveryEnabled();

    if (autodiscovery) {

      EventBuilder bldr = new EventBuilder(EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI, "linkd");

      bldr.setHost(str(ipowner));
      bldr.setInterface(ipaddress);

      m_eventForwarder.sendNow(bldr.getEvent());

      m_newSuspectEventsIpAddr.add(ipaddress);
    }
  }
Exemplo n.º 3
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);
    }
  }
Exemplo n.º 4
0
  /**
   * mergeNodeAttributes
   *
   * @param scannedNode a {@link org.opennms.netmgt.model.OnmsNode} object.
   */
  public void mergeNodeAttributes(OnmsNode scannedNode, 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("host");

      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);
  }