Search in sources :

Example 11 with Notification

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

the class NotificationWizardServlet method copyNotice.

/**
 */
private Notification copyNotice(final Notification oldNotice) {
    final Notification newNotice = new Notification();
    newNotice.setName(oldNotice.getName());
    newNotice.setWriteable(oldNotice.getWriteable());
    newNotice.setDescription(oldNotice.getDescription().orElse(null));
    newNotice.setUei(oldNotice.getUei());
    newNotice.setRule(oldNotice.getRule());
    newNotice.setDestinationPath(oldNotice.getDestinationPath());
    newNotice.setNoticeQueue(oldNotice.getNoticeQueue().orElse(null));
    newNotice.setTextMessage(oldNotice.getTextMessage());
    newNotice.setSubject(oldNotice.getSubject().orElse(null));
    newNotice.setNumericMessage(oldNotice.getNumericMessage().orElse(null));
    newNotice.setStatus(oldNotice.getStatus());
    newNotice.setVarbind(oldNotice.getVarbind());
    for (final Parameter parameter : oldNotice.getParameters()) {
        final Parameter newParam = new Parameter();
        newParam.setName(parameter.getName());
        newParam.setValue(parameter.getValue());
        newNotice.addParameter(newParam);
    }
    return newNotice;
}
Also used : Parameter(org.opennms.netmgt.config.notifications.Parameter) Notification(org.opennms.netmgt.config.notifications.Notification)

Example 12 with Notification

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

the class NotificationWizardServlet method edit.

/**
 * Common code for two source pages that can't really be considered the same
 */
private String edit(final HttpServletRequest request, final HttpSession user) throws ServletException {
    try {
        final Notification oldNotice = getNotificationFactory().getNotification(request.getParameter("notice"));
        user.setAttribute("newNotice", copyNotice(oldNotice));
        return SOURCE_PAGE_UEIS;
    } catch (final Throwable t) {
        throw new ServletException("couldn't get a copy of the notification to edit.", t);
    }
}
Also used : ServletException(javax.servlet.ServletException) Notification(org.opennms.netmgt.config.notifications.Notification)

Example 13 with Notification

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

the class NotificationWizardServlet method processValidate.

private String processValidate(final HttpServletRequest request, final HttpSession user) {
    final String userAction = request.getParameter("userAction");
    if ("rebuild".equals(userAction)) {
        final Map<String, Object> params = new HashMap<String, Object>();
        params.put("newRule", request.getParameter("newRule"));
        final String[] services = request.getParameterValues("services");
        if (services != null) {
            params.put("services", services);
        }
        params.put("mode", "rebuild");
        return SOURCE_PAGE_RULE + makeQueryString(params);
    } else {
        final Notification newNotice = (Notification) user.getAttribute("newNotice");
        newNotice.setRule(request.getParameter("newRule"));
        return SOURCE_PAGE_PATH;
    }
}
Also used : HashMap(java.util.HashMap) Notification(org.opennms.netmgt.config.notifications.Notification)

Example 14 with Notification

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

the class NotificationWizardServlet method newNotifWithUEI.

private String newNotifWithUEI(final HttpServletRequest request, final HttpSession user) {
    final String uei = request.getParameter("uei");
    final Notification newNotice = buildNewNotification("on");
    newNotice.setUei(uei);
    final Map<String, Object> params = new HashMap<String, Object>();
    params.put("newRule", toSingleQuote(newNotice.getRule()));
    user.setAttribute("newNotice", newNotice);
    return SOURCE_PAGE_RULE + makeQueryString(params);
}
Also used : HashMap(java.util.HashMap) Notification(org.opennms.netmgt.config.notifications.Notification)

Example 15 with Notification

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

the class NotificationsConfigTest method testFormattedNotificationsXml.

@Test
public void testFormattedNotificationsXml() throws Exception {
    MockUtil.println("################# Running Test ################");
    MockLogAppender.setupLogging();
    MockNotifdConfigManager notifdConfig = new MockNotifdConfigManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifd-configuration.xml"));
    NotificationManager manager = new MockNotificationManager(notifdConfig, null, ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifications-config-test.xml"));
    Notification n = manager.getNotification("crazyTestNotification");
    assertTrue(n.getTextMessage().contains("\n"));
}
Also used : MockNotificationManager(org.opennms.netmgt.config.mock.MockNotificationManager) MockNotifdConfigManager(org.opennms.netmgt.config.mock.MockNotifdConfigManager) NotificationManager(org.opennms.netmgt.config.NotificationManager) MockNotificationManager(org.opennms.netmgt.config.mock.MockNotificationManager) Notification(org.opennms.netmgt.config.notifications.Notification) Test(org.junit.Test)

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