Ejemplo n.º 1
0
  /**
   * replaceNotification
   *
   * @param oldName a {@link java.lang.String} object.
   * @param newNotice a {@link org.opennms.netmgt.config.notifications.Notification} object.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   * @throws java.io.IOException if any.
   * @throws java.lang.ClassNotFoundException if any.
   */
  public synchronized void replaceNotification(final String oldName, final Notification newNotice)
      throws MarshalException, ValidationException, IOException, ClassNotFoundException {
    //   In order to preserve the order of the notices, we have to replace "in place".

    Notification notice = getNotification(oldName);
    if (notice != null) {
      notice.setWriteable(newNotice.getWriteable());
      notice.setName(newNotice.getName());
      notice.setDescription(newNotice.getDescription());
      notice.setUei(newNotice.getUei());
      notice.setRule(newNotice.getRule());
      notice.setDestinationPath(newNotice.getDestinationPath());
      notice.setNoticeQueue(newNotice.getNoticeQueue());
      notice.setTextMessage(newNotice.getTextMessage());
      notice.setSubject(newNotice.getSubject());
      notice.setNumericMessage(newNotice.getNumericMessage());
      notice.setStatus(newNotice.getStatus());
      notice.setVarbind(newNotice.getVarbind());
      notice.getParameterCollection().clear(); // Required to avoid NMS-5948
      for (Parameter parameter : newNotice.getParameterCollection()) {
        Parameter newParam = new Parameter();
        newParam.setName(parameter.getName());
        newParam.setValue(parameter.getValue());
        notice.addParameter(newParam);
      }
      saveCurrent();
    } else addNotification(newNotice);
  }
Ejemplo n.º 2
0
  /**
   * Sets the status on an individual notification configuration and saves to xml.
   *
   * @param name The name of the notification.
   * @param status The status (either "on" or "off").
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   * @throws java.io.IOException if any.
   * @throws java.lang.ClassNotFoundException if any.
   */
  public synchronized void updateStatus(final String name, final String status)
      throws MarshalException, ValidationException, IOException, ClassNotFoundException {
    if ("on".equals(status) || "off".equals(status)) {
      Notification notice = getNotification(name);
      notice.setStatus(status);

      saveCurrent();
    } else throw new IllegalArgumentException("Status must be on|off, not " + status);
  }