Search in sources :

Example 1 with RTQueue

use of org.opennms.netmgt.rt.RTQueue in project opennms by OpenNMS.

the class SupportController method login.

private SupportResults login(final HttpServletRequest request) {
    final String username = request.getParameter("username").trim();
    final String password = request.getParameter("password").trim();
    final RequestTracker rt = new RequestTracker(m_configDao.getBaseURL(), username, password, m_configDao.getTimeout(), m_configDao.getRetry());
    LOG.debug("tracker = {}", rt);
    final SupportResults results = new SupportResults();
    results.setUsername(username);
    RTQueue queue = null;
    try {
        // First, check if the currently configured queue exists
        Long queueId = m_configDao.getQueueId();
        if (queueId != null) {
            queue = rt.getQueue(queueId);
        }
        // If not, try to find a default queue
        if (queue == null || !queue.isAccessible()) {
            queue = rt.getFirstPublicQueueForUser(username);
            LOG.warn("If more than one queue was found for user {}, the first was used.  ({})", username, queue);
            m_configDao.setQueueId(queue.getId());
        } else {
            LOG.debug("Existing queue found in support.properties ({}), will not overwrite.", m_configDao.getQueueId().toString());
        }
        m_configDao.setUsername(username);
        m_configDao.setPassword(password);
        m_configDao.save();
        final HttpSession session = request.getSession(true);
        session.setAttribute("username", username);
        session.setAttribute("password", password);
        session.setAttribute("requestTracker", rt);
        results.setSuccess(true);
        results.setNeedsLogin(false);
        results.setMessage("Logged in successfully.");
        results.setQueue(queue.getName());
        return results;
    } catch (final Exception e) {
        LOG.warn("Unable to log in user {}", username, e);
        results.setSuccess(false);
        results.setNeedsLogin(true);
        results.setMessage("Unable to log in: " + e.getLocalizedMessage());
        return results;
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) RequestTracker(org.opennms.netmgt.rt.RequestTracker) RTQueue(org.opennms.netmgt.rt.RTQueue) IOException(java.io.IOException) RequestTrackerException(org.opennms.netmgt.rt.RequestTrackerException)

Example 2 with RTQueue

use of org.opennms.netmgt.rt.RTQueue in project opennms by OpenNMS.

the class SupportController method createTicket.

private SupportResults createTicket(final HttpServletRequest request) {
    final HttpSession session = request.getSession();
    final RequestTracker rt = (RequestTracker) session.getAttribute("requestTracker");
    // get ticket and user information
    final String subject = request.getParameter("subject").trim();
    String body = request.getParameter("text").trim();
    final String includeReport = request.getParameter("include-report");
    final boolean report = Boolean.parseBoolean(includeReport);
    LOG.debug("include report?: {} (parsed as {})", includeReport, Boolean.valueOf(report));
    final RTUser user = rt.getUserInfo(rt.getUsername());
    String email = user.getEmail();
    if (email == null || "".equals(email)) {
        email = m_configDao.getRequestor();
    }
    final Long queueId = m_configDao.getQueueId();
    RTQueue queue = new RTQueue(0, "Unknown");
    try {
        queue = rt.getQueue(queueId);
    } catch (final RequestTrackerException e) {
        LOG.warn("Unable to determine queue for queue ID {}", queueId.toString());
    }
    // create report if necessary
    if (report) {
        final FtpSystemReportFormatter formatter = new FtpSystemReportFormatter();
        final String url = m_configDao.getFtpBaseURL() + "/" + queue.getName() + "-" + user.getUsername() + "-" + UUID.randomUUID() + ".zip";
        formatter.setOutput(url);
        formatter.begin();
        for (final SystemReportPlugin plugin : m_systemReport.getPlugins()) {
            if (plugin.getName().equals("Logs"))
                continue;
            formatter.write(plugin);
        }
        formatter.end();
        body = body.concat("\n\nSystem report is available at: " + url + "\n");
    }
    final SupportResults results = new SupportResults();
    results.setNeedsLogin(false);
    results.setUsername(rt.getUsername());
    results.setQueue(queue.getName());
    List<CustomField> customFields = new ArrayList<CustomField>();
    customFields.add(new CustomField(m_configDao.getVersionFieldName(), "Version " + Vault.getProperty("version.display"), false));
    customFields.add(new CustomField(m_configDao.getOSFieldName(), System.getProperty("os.name") + " " + System.getProperty("os.version") + " (" + System.getProperty("os.arch") + ")", false));
    final RTTicket ticket = new RTTicket(queue.getName(), email, subject, body, customFields);
    try {
        final long id = rt.createTicket(ticket);
        results.setSuccess(true);
        results.setMessage("New ticket created: <a href=\"" + m_configDao.getBaseURL() + "/Ticket/Display.html?id=" + id + "\">" + id + "</a>");
    } catch (final RequestTrackerException e) {
        LOG.warn("Unable to create ticket {}", ticket, e);
        results.setSuccess(false);
        results.setMessage("Unable to create ticket: " + e.getLocalizedMessage());
    }
    return results;
}
Also used : HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) RequestTracker(org.opennms.netmgt.rt.RequestTracker) RTQueue(org.opennms.netmgt.rt.RTQueue) SystemReportPlugin(org.opennms.systemreport.SystemReportPlugin) RequestTrackerException(org.opennms.netmgt.rt.RequestTrackerException) FtpSystemReportFormatter(org.opennms.systemreport.formatters.FtpSystemReportFormatter) RTTicket(org.opennms.netmgt.rt.RTTicket) RTUser(org.opennms.netmgt.rt.RTUser) CustomField(org.opennms.netmgt.rt.CustomField)

Example 3 with RTQueue

use of org.opennms.netmgt.rt.RTQueue in project opennms by OpenNMS.

the class SupportController method handleRequestInternal.

/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final String operation = request.getParameter("operation");
    final HttpSession session = request.getSession(true);
    SupportResults results = new SupportResults();
    results.setSuccess(false);
    results.setNeedsLogin(false);
    LOG.debug("operation = {}", operation);
    if ("login".equals(operation)) {
        results = login(request);
    } else if (session.getAttribute("requestTracker") == null) {
        results.setNeedsLogin(true);
    } else if ("logout".equals(operation)) {
        results = logout(request);
    } else if ("createTicket".equals(operation)) {
        results = createTicket(request);
    }
    RequestTracker rt = (RequestTracker) session.getAttribute("requestTracker");
    if (results.getNeedsLogin() == false) {
        if (results.getQueue() == null) {
            final Long queueId = m_configDao.getQueueId();
            if (queueId != null) {
                RTQueue queue = rt.getQueue(queueId);
                results.setQueue(queue.getName());
            }
        }
        results.setUsername(rt.getUsername());
        results.setLatestTickets(rt.getTicketsForQueue(results.getQueue(), 5));
    }
    results.setRTUrl(m_configDao.getBaseURL());
    return new ModelAndView("/support/index", "results", results);
}
Also used : HttpSession(javax.servlet.http.HttpSession) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestTracker(org.opennms.netmgt.rt.RequestTracker) RTQueue(org.opennms.netmgt.rt.RTQueue)

Aggregations

HttpSession (javax.servlet.http.HttpSession)3 RTQueue (org.opennms.netmgt.rt.RTQueue)3 RequestTracker (org.opennms.netmgt.rt.RequestTracker)3 RequestTrackerException (org.opennms.netmgt.rt.RequestTrackerException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CustomField (org.opennms.netmgt.rt.CustomField)1 RTTicket (org.opennms.netmgt.rt.RTTicket)1 RTUser (org.opennms.netmgt.rt.RTUser)1 SystemReportPlugin (org.opennms.systemreport.SystemReportPlugin)1 FtpSystemReportFormatter (org.opennms.systemreport.formatters.FtpSystemReportFormatter)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1