Search in sources :

Example 1 with Notification

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

the class ChooseUeisController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // Pull the notice from the session
    HttpSession session = request.getSession(true);
    Notification newNotice = (Notification) session.getAttribute("newNotice");
    // If the notice is not present in the session, redirect to the first page of the wizard
    if (newNotice == null) {
        return new ModelAndView(new RedirectView(NotificationWizardServlet.SOURCE_PAGE_NOTICES));
    }
    return new ModelAndView("/admin/notification/noticeWizard/chooseUeis", "model", createModel(newNotice));
}
Also used : HttpSession(javax.servlet.http.HttpSession) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) Notification(org.opennms.netmgt.config.notifications.Notification)

Example 2 with Notification

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

the class NotificationWizardServlet method processUeis.

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

Example 3 with Notification

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

the class NotificationWizardServlet method processPath.

private String processPath(final HttpServletRequest request, final HttpSession user) throws ServletException {
    final Notification newNotice = (Notification) user.getAttribute("newNotice");
    newNotice.setDestinationPath(request.getParameter("path"));
    final String description = request.getParameter("description");
    if (description != null && !description.trim().equals("")) {
        newNotice.setDescription(description);
    } else {
        newNotice.setDescription(null);
    }
    newNotice.setTextMessage(request.getParameter("textMsg"));
    final String subject = request.getParameter("subject");
    if (subject != null && !subject.trim().equals("")) {
        newNotice.setSubject(subject);
    } else {
        newNotice.setSubject(null);
    }
    final String numMessage = request.getParameter("numMsg");
    if (numMessage != null && !numMessage.trim().equals("")) {
        newNotice.setNumericMessage(numMessage);
    } else {
        newNotice.setNumericMessage(null);
    }
    final String oldName = newNotice.getName();
    newNotice.setName(request.getParameter("name"));
    final String varbindName = request.getParameter("varbindName");
    final String varbindValue = request.getParameter("varbindValue");
    Varbind varbind = newNotice.getVarbind();
    if (varbindName != null && !varbindName.trim().equals("") && varbindValue != null && !varbindValue.trim().equals("")) {
        if (varbind == null) {
            varbind = new Varbind();
            newNotice.setVarbind(varbind);
        }
        varbind.setVbname(varbindName);
        varbind.setVbvalue(varbindValue);
    } else {
        // Must do this to allow clearing out varbind definitions
        newNotice.setVarbind(null);
    }
    try {
        // replacing a path with a new name.
        getNotificationFactory().replaceNotification(oldName, newNotice);
    } catch (final Throwable t) {
        throw new ServletException("Couldn't save/reload notification configuration file.", t);
    }
    final String suppliedReturnPage = (String) user.getAttribute("noticeWizardReturnPage");
    if (suppliedReturnPage != null && !"".equals(suppliedReturnPage)) {
        // Remove this attribute once we have consumed it, else the user may later
        // get returned to a potentially unexpected page here
        user.removeAttribute("noticeWizardReturnPage");
        return suppliedReturnPage;
    } else {
        return SOURCE_PAGE_NOTICES;
    }
}
Also used : ServletException(javax.servlet.ServletException) Varbind(org.opennms.netmgt.config.notifications.Varbind) Notification(org.opennms.netmgt.config.notifications.Notification)

Example 4 with Notification

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

the class NotificationWizardServlet method buildNewNotification.

private Notification buildNewNotification(final String status) {
    final Notification notice = new Notification();
    notice.setRule("IPADDR IPLIKE *.*.*.*");
    notice.setNumericMessage("111-%noticeid%");
    notice.setSubject("Notice #%noticeid%");
    notice.setStatus(status);
    return notice;
}
Also used : Notification(org.opennms.netmgt.config.notifications.Notification)

Example 5 with Notification

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

the class NotificationManagerIT method doTestNodeInterfaceServiceWithRule.

private void doTestNodeInterfaceServiceWithRule(String description, int nodeId, String intf, String svc, String rule, boolean matches) {
    Notification notif = new Notification();
    notif.setName("a notification");
    notif.setRule(rule);
    EventBuilder builder = new EventBuilder("uei.opennms.org/doNotCareAboutTheUei", "Test.Event");
    builder.setNodeid(nodeId);
    builder.setInterface(addr(intf));
    builder.setService(svc);
    assertEquals(description, matches, m_notificationManager.nodeInterfaceServiceValid(notif, builder.getEvent()));
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) 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