Search in sources :

Example 6 with Notification

use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.

the class NotificationManager method replaceNotification.

/**
 * <p>replaceNotification</p>
 *
 * @param oldName a {@link java.lang.String} object.
 * @param newNotice a {@link org.opennms.netmgt.config.notifications.Notification} object.
 * @throws java.io.IOException if any.
 * @throws java.lang.ClassNotFoundException if any.
 */
public synchronized void replaceNotification(final String oldName, final Notification newNotice) throws 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().orElse(null));
        notice.setUei(newNotice.getUei());
        notice.setRule(newNotice.getRule());
        notice.setDestinationPath(newNotice.getDestinationPath());
        notice.setNoticeQueue(newNotice.getNoticeQueue().orElse(null));
        notice.setTextMessage(newNotice.getTextMessage());
        notice.setSubject(newNotice.getSubject().orElse(null));
        notice.setNumericMessage(newNotice.getNumericMessage().orElse(null));
        notice.setStatus(newNotice.getStatus());
        notice.setVarbind(newNotice.getVarbind());
        // Required to avoid NMS-5948
        notice.getParameters().clear();
        for (Parameter parameter : newNotice.getParameters()) {
            Parameter newParam = new Parameter();
            newParam.setName(parameter.getName());
            newParam.setValue(parameter.getValue());
            notice.addParameter(newParam);
        }
        saveCurrent();
    } else
        addNotification(newNotice);
}
Also used : Parameter(org.opennms.netmgt.config.notifications.Parameter) Notification(org.opennms.netmgt.config.notifications.Notification)

Example 7 with Notification

use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.

the class NotificationManager method updateStatus.

/**
 * 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 java.io.IOException if any.
 * @throws java.lang.ClassNotFoundException if any.
 */
public synchronized void updateStatus(final String name, final String status) throws 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);
}
Also used : Notification(org.opennms.netmgt.config.notifications.Notification)

Example 8 with Notification

use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.

the class NotificationManager method rebuildParameterMap.

/**
 * <p>rebuildParameterMap</p>
 *
 * @param notifId a int.
 * @param resolutionPrefix a {@link java.lang.String} object.
 * @param skipNumericPrefix a boolean.
 * @return a {@link java.util.Map} object.
 * @throws java.lang.Exception if any.
 */
public Map<String, String> rebuildParameterMap(final int notifId, final String resolutionPrefix, final boolean skipNumericPrefix) throws Exception {
    final Map<String, String> parmMap = new HashMap<String, String>();
    Querier querier = new Querier(m_dataSource, "select notifications.*, service.* from notifications left outer join service on notifications.serviceID = service.serviceID  where notifyId = ?") {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            /*
                 * Note, getString on results is valid for any SQL data type except the new SQL types:
                 *    Blog, Clob, Array, Struct, Ref
                 * of which we have none in this table so this row processor is using getString
                 * to correctly align with annotated types in the map.
                 */
            parmMap.put(NotificationManager.PARAM_TEXT_MSG, expandNotifParms(resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId))) + rs.getString("textMsg"));
            if (skipNumericPrefix) {
                parmMap.put(NotificationManager.PARAM_NUM_MSG, rs.getString("numericMsg"));
            } else {
                parmMap.put(NotificationManager.PARAM_NUM_MSG, expandNotifParms(resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId))) + rs.getString("numericMsg"));
            }
            parmMap.put(NotificationManager.PARAM_SUBJECT, expandNotifParms(resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId))) + rs.getString("subject"));
            parmMap.put(NotificationManager.PARAM_NODE, rs.getString("nodeID"));
            parmMap.put(NotificationManager.PARAM_INTERFACE, rs.getString("interfaceID"));
            parmMap.put(NotificationManager.PARAM_SERVICE, rs.getString("serviceName"));
            parmMap.put("noticeid", rs.getString("notifyID"));
            parmMap.put("eventID", rs.getString("eventID"));
            parmMap.put("eventUEI", rs.getString("eventUEI"));
            Notification notification = null;
            try {
                notification = getNotification(rs.getObject("notifConfigName").toString());
            } catch (IOException e) {
            }
            if (notification != null) {
                addNotificationParams(parmMap, notification);
            }
        }
    };
    querier.execute(notifId);
    return parmMap;
}
Also used : Querier(org.opennms.core.utils.Querier) SingleResultQuerier(org.opennms.core.utils.SingleResultQuerier) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ResultSet(java.sql.ResultSet) IOException(java.io.IOException) Notification(org.opennms.netmgt.config.notifications.Notification)

Example 9 with Notification

use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.

the class NotificationManager method getNotificationNames.

/**
 * <p>getNotificationNames</p>
 *
 * @return a {@link java.util.List} object.
 * @throws java.io.IOException if any.
 */
public List<String> getNotificationNames() throws IOException {
    update();
    List<String> notificationNames = new ArrayList<>();
    for (Notification curNotif : m_notifications.getNotifications()) {
        notificationNames.add(curNotif.getName());
    }
    return notificationNames;
}
Also used : ArrayList(java.util.ArrayList) Notification(org.opennms.netmgt.config.notifications.Notification)

Example 10 with Notification

use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.

the class NotificationWizardServlet method processRule.

private String processRule(final HttpServletRequest request, final HttpSession user) {
    String ruleString = request.getParameter("newRule");
    ruleString = toSingleQuote(ruleString);
    ruleString = stripExtraWhite(ruleString);
    ruleString = stripServices(ruleString);
    ruleString = checkParens(ruleString);
    final StringBuilder rule = new StringBuilder(ruleString);
    final String[] services = request.getParameterValues("services");
    if (services != null) {
        rule.append(" & ").append(" (");
        for (int i = 0; i < services.length; i++) {
            rule.append("is").append(services[i]);
            if (i < services.length - 1) {
                rule.append(" | ");
            }
        }
        rule.append(" )");
    }
    final String[] notServices = request.getParameterValues("notServices");
    if (notServices != null) {
        rule.append(" & ").append(" (");
        for (int i = 0; i < notServices.length; i++) {
            rule.append("!is").append(notServices[i]);
            if (i < notServices.length - 1) {
                rule.append(" & ");
            }
        }
        rule.append(" )");
    }
    final Map<String, Object> params = new HashMap<String, Object>();
    params.put("newRule", rule.toString());
    if (services != null) {
        params.put("services", services);
    }
    if (notServices != null) {
        params.put("notServices", notServices);
    }
    // page to redirect to, either validate or skip validation
    String redirectPage = request.getParameter("nextPage");
    // now lets see if the rule is syntactically valid
    try {
        getFilterDao().validateRule(rule.toString());
    } catch (final FilterParseException e) {
        // page to redirect to if the rule is invalid
        params.put("mode", "failed");
        redirectPage = SOURCE_PAGE_RULE;
    }
    // save the rule if we are bypassing validation
    if (redirectPage.equals(SOURCE_PAGE_PATH)) {
        final Notification newNotice = (Notification) user.getAttribute("newNotice");
        newNotice.setRule(rule.toString());
    }
    return redirectPage + makeQueryString(params);
}
Also used : FilterParseException(org.opennms.netmgt.filter.api.FilterParseException) HashMap(java.util.HashMap) Notification(org.opennms.netmgt.config.notifications.Notification)

Aggregations

Notification (org.opennms.netmgt.config.notifications.Notification)22 HashMap (java.util.HashMap)7 Test (org.junit.Test)5 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 ServletException (javax.servlet.ServletException)2 Parameter (org.opennms.netmgt.config.notifications.Parameter)2 Event (org.opennms.netmgt.xml.event.Event)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Calendar (java.util.Calendar)1 TreeMap (java.util.TreeMap)1 HttpSession (javax.servlet.http.HttpSession)1 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)1 Querier (org.opennms.core.utils.Querier)1 SingleResultQuerier (org.opennms.core.utils.SingleResultQuerier)1