/**
   * 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());
  }
  /**
   * {@inheritDoc}
   *
   * <p>This method is invoked by the event manager when a new event is available for processing.
   * Each message is examined for its Universal Event Identifier and the appropriate action is
   * taking based on each UEI.
   */
  @Override
  public void onEvent(Event event) {

    LOG.debug("onEvent: received event, UEI = {}", event.getUei());
    EventBuilder ebldr = null;

    if (isReloadConfigEvent(event)) {
      LOG.info(
          "onEvent: Reloading events configuration in response to event with UEI "
              + event.getUei());
      try {
        m_eventConfDao.reload();
        ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, getName());
        ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Eventd");

      } catch (Throwable e) {
        LOG.error("onEvent: Could not reload events config", e);
        ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, getName());
        ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Eventd");
        ebldr.addParam(EventConstants.PARM_REASON, e.getLocalizedMessage().substring(0, 128));
      }

      if (ebldr != null) {
        m_eventIpcManager.sendNow(ebldr.getEvent());
      }
    }
  }
Exemple #3
0
 /**
  * scanCompleted
  *
  * @param currentPhase a {@link org.opennms.core.tasks.BatchTask} object.
  */
 public void scanCompleted(final BatchTask currentPhase) {
   if (!isAborted()) {
     final EventBuilder bldr =
         new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond");
     bldr.setNodeid(getNodeId());
     bldr.addParam(EventConstants.PARM_FOREIGN_SOURCE, getForeignSource());
     bldr.addParam(EventConstants.PARM_FOREIGN_ID, getForeignId());
     getEventForwarder().sendNow(bldr.getEvent());
   }
 }
  private EventBuilder createConfigureSnmpEventBuilder(final String firstIp, final String lastIp) {

    EventBuilder bldr =
        new EventBuilder(EventConstants.CONFIGURE_SNMP_EVENT_UEI, "ConfigureSnmpTest");

    bldr.addParam(EventConstants.PARM_FIRST_IP_ADDRESS, firstIp);
    bldr.addParam(EventConstants.PARM_LAST_IP_ADDRESS, lastIp);

    return bldr;
  }
Exemple #5
0
  /**
   * abort
   *
   * @param reason a {@link java.lang.String} object.
   */
  public void abort(final String reason) {
    m_aborted = true;

    LOG.info("Aborting Scan of node {} for the following reason: {}", m_nodeId, reason);

    final EventBuilder bldr =
        new EventBuilder(EventConstants.PROVISION_SCAN_ABORTED_UEI, "Provisiond");
    if (m_nodeId != null) {
      bldr.setNodeid(m_nodeId);
    }
    bldr.addParam(EventConstants.PARM_FOREIGN_SOURCE, m_foreignSource);
    bldr.addParam(EventConstants.PARM_FOREIGN_ID, m_foreignId);
    bldr.addParam(EventConstants.PARM_REASON, reason);

    m_eventForwarder.sendNow(bldr.getEvent());
  }
  /** {@inheritDoc} */
  @Override
  public void importProvisioningGroup(final String requisitionName) {
    m_writeLock.lock();

    try {
      final Requisition requisition = getProvisioningGroup(requisitionName);
      saveProvisioningGroup(requisitionName, requisition);

      // then we send an event to the importer
      final EventProxy proxy = Util.createEventProxy();

      m_pendingForeignSourceRepository.flush();
      final String url =
          m_pendingForeignSourceRepository.getRequisitionURL(requisitionName).toString();
      Assert.notNull(url, "Could not find url for group " + requisitionName + ".  Does it exists?");

      final EventBuilder bldr = new EventBuilder(EventConstants.RELOAD_IMPORT_UEI, "Web");
      bldr.addParam(EventConstants.PARM_URL, url);

      try {
        proxy.send(bldr.getEvent());
      } catch (final EventProxyException e) {
        throw new DataAccessResourceFailureException(
            "Unable to send event to import group " + requisitionName, e);
      }
    } finally {
      m_writeLock.unlock();
    }
  }
  public void importRequisition(final String foreignSource, final Boolean rescanExisting) {
    final URL activeUrl = createSnapshot(foreignSource);

    final String url = activeUrl.toString();
    LOG.debug("importRequisition: Sending import event with URL {}", url);
    final EventBuilder bldr = new EventBuilder(EventConstants.RELOAD_IMPORT_UEI, "Web");
    bldr.addParam(EventConstants.PARM_URL, url);
    if (rescanExisting != null) {
      bldr.addParam(EventConstants.PARM_IMPORT_RESCAN_EXISTING, rescanExisting);
    }

    try {
      getEventProxy().send(bldr.getEvent());
    } catch (final EventProxyException e) {
      throw new DataAccessResourceFailureException(
          "Unable to send event to import group " + foreignSource, e);
    }
  }
Exemple #8
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);
    }
  }
  private void sendEvent(List<String> filesToPromote) {

    EventBuilder bldr = new EventBuilder(EventConstants.PROMOTE_QUEUE_DATA_UEI, "OpenNMS.Webapp");
    bldr.addParam(EventConstants.PARM_FILES_TO_PROMOTE, filesToPromote);

    try {
      m_eventProxy.send(bldr.getEvent());
    } catch (EventProxyException e) {
      LOG.warn("Unable to send promotion event to opennms daemon", e);
    }
  }
  public void testAuthenticationFailureEvent() throws Exception {
    String userName = "******";
    String ip = "1.2.3.4";
    String sessionId = "it tastes just like our regular coffee";

    HttpServletRequest request = createMock(HttpServletRequest.class);
    HttpSession session = createMock(HttpSession.class);
    expect(request.getRemoteAddr()).andReturn(ip);
    expect(request.getSession(false)).andReturn(session);
    expect(session.getId()).andReturn(sessionId);

    replay(request, session);
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    verify(request, session);

    org.springframework.security.core.Authentication authentication =
        new TestingDetailsAuthenticationToken(
            userName, "cheesiness", new GrantedAuthority[0], details);
    AuthenticationFailureBadCredentialsEvent authEvent =
        new AuthenticationFailureBadCredentialsEvent(
            authentication, new BadCredentialsException("you are bad!"));

    SecurityAuthenticationEventOnmsEventBuilder builder =
        new SecurityAuthenticationEventOnmsEventBuilder();
    builder.setEventProxy(m_eventProxy);
    builder.afterPropertiesSet();

    EventBuilder eventBuilder =
        new EventBuilder(SecurityAuthenticationEventOnmsEventBuilder.FAILURE_UEI, "OpenNMS.WebUI");
    eventBuilder.addParam("user", userName);
    eventBuilder.addParam("ip", ip);
    eventBuilder.addParam("exceptionName", authEvent.getException().getClass().getSimpleName());
    eventBuilder.addParam("exceptionMessage", authEvent.getException().getMessage());

    m_eventProxy.send(EventEquals.eqEvent(eventBuilder.getEvent()));

    m_mocks.replayAll();
    builder.onApplicationEvent(authEvent);
    m_mocks.verifyAll();
  }
  /** {@inheritDoc} */
  public void poll(OnmsMonitoredService monSvc, int pollResultId) {

    EventBuilder bldr =
        new EventBuilder(EventConstants.DEMAND_POLL_SERVICE_EVENT_UEI, "PollerService");

    bldr.setNodeid(monSvc.getNodeId());
    bldr.setInterface(monSvc.getIpAddress());
    bldr.setIfIndex(monSvc.getIfIndex());
    bldr.setService(monSvc.getServiceType().getName());

    bldr.addParam(EventConstants.PARM_DEMAND_POLL_ID, pollResultId);

    sendEvent(bldr.getEvent());
  }
 /**
  * handleReloadConfigEvent
  *
  * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
  */
 @EventHandler(uei = EventConstants.RELOAD_DAEMON_CONFIG_UEI)
 public void handleReloadConfigEvent(final Event event) {
   if (isReloadConfigEventTarget(event)) {
     EventBuilder ebldr = null;
     LogUtils.debugf(this, "Reloading the SNMP asset adapter configuration");
     try {
       m_config.update();
       ebldr =
           new EventBuilder(
               EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, "Provisiond." + NAME);
       ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Provisiond." + NAME);
     } catch (Throwable e) {
       LogUtils.infof(this, e, "Unable to reload SNMP asset adapter configuration");
       ebldr =
           new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, "Provisiond." + NAME);
       ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Provisiond." + NAME);
       ebldr.addParam(EventConstants.PARM_REASON, e.getLocalizedMessage().substring(1, 128));
     }
     if (ebldr != null) {
       getEventForwarder().sendNow(ebldr.getEvent());
     }
   }
 }
 /**
  * setField
  *
  * @param name a {@link java.lang.String} object.
  * @param val a {@link java.lang.String} object.
  */
 public void setField(final String name, final String val) {
   if (name.equals("eventparms")) {
     String[] parts = val.split(";");
     for (String part : parts) {
       String[] pair = part.split("=");
       addParam(pair[0], pair[1].replaceFirst("[(]\\w+,\\w+[)]", ""));
     }
   } else {
     final BeanWrapper w = PropertyAccessorFactory.forBeanPropertyAccess(m_event);
     try {
       w.setPropertyValue(name, val);
     } catch (final BeansException e) {
       LogUtils.warnf(this, e, "Could not set field on event: %s", name);
     }
   }
 }
  private void sendEvent(EventProxy proxy, long count) throws Exception {
    EventBuilder bldr =
        new EventBuilder(
            "uei.opennms.org/internal/authentication/successfulLogin", "MemoryLeakTest");
    bldr.addParam("user", "brozow");

    proxy.send(bldr.getEvent());

    long free = Runtime.getRuntime().freeMemory();
    long max = Runtime.getRuntime().maxMemory();

    double pct = ((double) free) / ((double) max);
    System.err.println("% Free Memory is " + pct);

    if (pct < 0.01) {
      throw new IllegalStateException("Memory Used up!");
    }
  }
  public EventBuilder addParam(
      final String parmName, final String val, final String type, final String encoding) {
    if (parmName != null) {
      Value value = new Value();
      value.setContent(val);

      if (type != null) {
        value.setType(type);
      }

      if (encoding != null) {
        value.setEncoding(encoding);
      }

      Parm parm = new Parm();
      parm.setParmName(parmName);
      parm.setValue(value);

      addParam(parm);
    }

    return this;
  }
Exemple #16
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);
  }
Exemple #17
0
  /**
   * mergeIpInterfaces
   *
   * @param scannedNode a {@link org.opennms.netmgt.model.OnmsNode} object.
   * @param eventForwarder a {@link org.opennms.netmgt.model.events.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());
    }
  }
 private void addCommunityStringToEvent(final EventBuilder bldr, final String commStr) {
   bldr.addParam(EventConstants.PARM_COMMUNITY_STRING, commStr);
 }