Пример #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);
  }
Пример #2
0
 private boolean isRuleMatchingFilter(final Notification notif, final String rule) {
   try {
     return FilterDaoFactory.getInstance().isRuleMatching(rule);
   } catch (FilterParseException e) {
     LOG.error("Invalid filter rule for notification {}: {}", notif.getName(), notif.getRule(), e);
     throw e;
   }
 }
Пример #3
0
  /**
   * nodeInterfaceServiceValid
   *
   * @param notif a {@link org.opennms.netmgt.config.notifications.Notification} object.
   * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
   * @return a boolean.
   */
  protected boolean nodeInterfaceServiceValid(final Notification notif, final Event event) {
    Assert.notNull(notif, "notif argument must not be null");
    Assert.notNull(event, "event argument must not be null");
    Assert.notNull(notif.getRule(), "getRule() on notif argument must not return null");

    /*
     *  If the event doesn't have a nodeId, interface, or service,
     *  return true since there is nothing on which to filter.
     */
    if (event.getNodeid() == 0 && event.getInterface() == null && event.getService() == null) {
      if ("MATCH-ANY-UEI".equals(notif.getUei())) {
        // TODO: Trim parentheses from the filter and trim whitespace from inside the
        // filter statement. This comparison is very brittle as it is.
        if ("ipaddr != '0.0.0.0'".equals(notif.getRule().toLowerCase())
            || "ipaddr iplike *.*.*.*".equals(notif.getRule().toLowerCase())) {
          return true;
        } else {
          return false;
        }
      }
      return true;
    }

    StringBuffer constraints = new StringBuffer();
    if (event.getNodeid() != 0) {
      constraints.append(" & (nodeId == " + event.getNodeid() + ")");
    }

    if (event.getInterface() != null && !"0.0.0.0".equals(event.getInterface())) {
      constraints.append(" & (ipAddr == '" + event.getInterface() + "')");
      if (event.getService() != null) {
        constraints.append(" & (serviceName == '" + event.getService() + "')");
      }
    }

    String rule = "((" + notif.getRule() + ")" + constraints + ")";

    return isRuleMatchingFilter(notif, rule);
  }