Search in sources :

Example 1 with SystemReportPlugin

use of org.opennms.systemreport.SystemReportPlugin in project opennms by OpenNMS.

the class ReportPluginITCase method setUp.

@Before
public void setUp() {
    System.err.println("---");
    m_plugins = new ArrayList<SystemReportPlugin>(m_defaultServiceRegistry.findProviders(SystemReportPlugin.class));
    Collections.sort(m_plugins);
    for (final SystemReportPlugin plugin : m_plugins) {
        System.err.println(plugin.getName() + ":");
        for (final Entry<String, org.springframework.core.io.Resource> entry : plugin.getEntries().entrySet()) {
            System.err.println("  " + entry.getKey() + ": " + getResourceText(entry.getValue()));
        }
    }
}
Also used : SystemReportPlugin(org.opennms.systemreport.SystemReportPlugin) Resource(javax.annotation.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Before(org.junit.Before)

Example 2 with SystemReportPlugin

use of org.opennms.systemreport.SystemReportPlugin 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 SystemReportPlugin

use of org.opennms.systemreport.SystemReportPlugin in project opennms by OpenNMS.

the class FormatterView method render.

@Override
public void render(final Map<String, ?> model, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    if (m_view == null) {
        String fileName = getFileName(request);
        response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    } else {
        final String outputParameter = request.getParameter("output");
        m_formatter.setOutput(outputParameter);
    }
    if (model.containsKey("report")) {
        final SystemReportInfo info = (SystemReportInfo) model.get("report");
        LOG.debug("found report = {}", info);
        final OutputStream output;
        if (m_view == null) {
            output = response.getOutputStream();
        } else {
            output = new OutputStream() {

                @Override
                public void write(int b) throws IOException {
                }
            };
        }
        try {
            LOG.debug("beginning output");
            m_formatter.setOutputStream(output);
            m_formatter.begin();
            for (final SystemReportPlugin plugin : info.getPlugins()) {
                LOG.debug("running plugin {}", plugin);
                m_formatter.write(plugin);
                output.flush();
            }
            LOG.debug("finishing output");
            m_formatter.end();
        } catch (final Throwable e) {
            LOG.warn("Error while formatting system report output", e);
            throw new SystemReportException(e);
        } finally {
            IOUtils.closeQuietly(output);
        }
    } else {
        LOG.info("Invalid form input: {}", model);
        throw new SystemReportException("Form input was invalid.");
    }
    LOG.debug("done");
    if (m_view != null) {
        m_view.render(model, request, response);
    }
}
Also used : SystemReportPlugin(org.opennms.systemreport.SystemReportPlugin) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 4 with SystemReportPlugin

use of org.opennms.systemreport.SystemReportPlugin in project opennms by OpenNMS.

the class SystemReportController method handleRequestInternal.

/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    String operation = request.getParameter("operation");
    if (!StringUtils.hasText(operation)) {
        operation = "list";
    }
    LOG.debug("Calling operation {} in SystemReportController", operation);
    if ("run".equalsIgnoreCase(operation)) {
        SystemReportFormatter formatter = null;
        final String formatterName = request.getParameter("formatter");
        for (final SystemReportFormatter f : m_systemReport.getFormatters()) {
            if (f.getName().equals(formatterName)) {
                formatter = f;
                break;
            }
        }
        if (formatter == null) {
            throw new FormatterNotFoundException("Unable to locate formatter plugin for format type '" + formatterName + "'");
        }
        final List<String> selectedPlugins = Arrays.asList(request.getParameterValues("plugins"));
        final List<SystemReportPlugin> plugins = new ArrayList<SystemReportPlugin>();
        for (final SystemReportPlugin plugin : m_systemReport.getPlugins()) {
            if (selectedPlugins.contains(plugin.getName())) {
                plugins.add(plugin);
            }
        }
        return new ModelAndView(new FormatterView(formatter), "report", new SystemReportInfo(Arrays.asList(formatter), plugins));
    } else {
        return new ModelAndView("redirect:/admin/support/systemReportList.htm");
    }
}
Also used : SystemReportPlugin(org.opennms.systemreport.SystemReportPlugin) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) SystemReportFormatter(org.opennms.systemreport.SystemReportFormatter)

Aggregations

SystemReportPlugin (org.opennms.systemreport.SystemReportPlugin)4 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Resource (javax.annotation.Resource)1 HttpSession (javax.servlet.http.HttpSession)1 Before (org.junit.Before)1 CustomField (org.opennms.netmgt.rt.CustomField)1 RTQueue (org.opennms.netmgt.rt.RTQueue)1 RTTicket (org.opennms.netmgt.rt.RTTicket)1 RTUser (org.opennms.netmgt.rt.RTUser)1 RequestTracker (org.opennms.netmgt.rt.RequestTracker)1 RequestTrackerException (org.opennms.netmgt.rt.RequestTrackerException)1 SystemReportFormatter (org.opennms.systemreport.SystemReportFormatter)1 FtpSystemReportFormatter (org.opennms.systemreport.formatters.FtpSystemReportFormatter)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1