Search in sources :

Example 1 with RTTicket

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

the class RtTicketerPlugin method get.

/**
	 * {@inheritDoc}
	 *
	 * Gets ticket details from the RT trouble ticket system
	 */
@Override
public Ticket get(final String ticketId) throws PluginException {
    Ticket ticket = null;
    RTTicket rtt = null;
    try {
        rtt = m_requestTracker.getTicket(Long.valueOf(ticketId), false);
    } catch (final RequestTrackerException e) {
        throw new PluginException(e);
    }
    if (rtt != null) {
        ticket = new Ticket();
        ticket.setState(rtToOpenNMSState(rtt.getStatus()));
        ticket.setId(rtt.getId().toString());
        ticket.setUser(StringUtils.join(rtt.getRequestors(), ", "));
        ticket.setSummary(rtt.getSubject());
        ticket.setDetails(rtt.getText());
    } else {
        throw new PluginException("could not find ticket in RT for Ticket: " + ticketId);
    }
    return ticket;
}
Also used : RTTicket(org.opennms.netmgt.rt.RTTicket) Ticket(org.opennms.api.integration.ticketing.Ticket) RequestTrackerException(org.opennms.netmgt.rt.RequestTrackerException) RTTicket(org.opennms.netmgt.rt.RTTicket) PluginException(org.opennms.api.integration.ticketing.PluginException)

Example 2 with RTTicket

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

the class RtTicketerPlugin method rtTicketFromTicket.

private RTTicket rtTicketFromTicket(final Ticket ticket) {
    final RTTicket rtt = new RTTicket();
    final String id = ticket.getId();
    if (id != null && id.length() > 0) {
        rtt.setId(Long.valueOf(id));
    }
    rtt.setQueue(m_queue);
    rtt.setRequestor(m_requestor);
    if (ticket.getSummary() != null)
        rtt.setSubject(ticket.getSummary());
    // Remove any HTML tags in the ticket details.
    if (ticket.getDetails() != null)
        rtt.setText(m_tagPattern.matcher(ticket.getDetails()).replaceAll(""));
    rtt.setStatus(openNMSToRTState(ticket.getState()));
    return rtt;
}
Also used : RTTicket(org.opennms.netmgt.rt.RTTicket)

Example 3 with RTTicket

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

the class RtTicketerPlugin method saveOrUpdate.

/**
	 * {@inheritDoc}
	 *
	 * Creates a new ticket (if none exists) or updates an existing ticket in the
	 * RT trouble ticket system. Ticket updates are currently limited to updating
	 * the ticket status only.
	 */
@Override
public void saveOrUpdate(final Ticket newTicket) throws PluginException {
    String newTicketID;
    Ticket currentTicket = null;
    try {
        if ((newTicket.getId() == null)) {
            LOG.debug("TicketId is null creating a new ticket");
            RTTicket ticket = rtTicketFromTicket(newTicket);
            Long rtTicketNumber = null;
            try {
                rtTicketNumber = m_requestTracker.createTicket(ticket);
            } catch (final Exception e) {
                throw new PluginException(e);
            }
            if (rtTicketNumber == null) {
                throw new PluginException("Received no ticket number from RT");
            }
            newTicketID = rtTicketNumber.toString();
            newTicket.setId(newTicketID);
            LOG.debug("created new ticket: {}", newTicket.getId());
        } else {
            currentTicket = get(newTicket.getId());
            LOG.debug("updating existing ticket: {}", currentTicket.getId());
            if (currentTicket.getState() != newTicket.getState()) {
                updateRtStatus(newTicket);
            } else {
            // There is no else at the moment
            // Tickets are _only_ updated with new state
            }
        }
    } catch (final PluginException e) {
        LOG.error("Failed to create or update RT ticket", e);
        throw e;
    }
}
Also used : RTTicket(org.opennms.netmgt.rt.RTTicket) Ticket(org.opennms.api.integration.ticketing.Ticket) RTTicket(org.opennms.netmgt.rt.RTTicket) PluginException(org.opennms.api.integration.ticketing.PluginException) PluginException(org.opennms.api.integration.ticketing.PluginException) RequestTrackerException(org.opennms.netmgt.rt.RequestTrackerException)

Example 4 with RTTicket

use of org.opennms.netmgt.rt.RTTicket 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)

Aggregations

RTTicket (org.opennms.netmgt.rt.RTTicket)4 RequestTrackerException (org.opennms.netmgt.rt.RequestTrackerException)3 PluginException (org.opennms.api.integration.ticketing.PluginException)2 Ticket (org.opennms.api.integration.ticketing.Ticket)2 ArrayList (java.util.ArrayList)1 HttpSession (javax.servlet.http.HttpSession)1 CustomField (org.opennms.netmgt.rt.CustomField)1 RTQueue (org.opennms.netmgt.rt.RTQueue)1 RTUser (org.opennms.netmgt.rt.RTUser)1 RequestTracker (org.opennms.netmgt.rt.RequestTracker)1 SystemReportPlugin (org.opennms.systemreport.SystemReportPlugin)1 FtpSystemReportFormatter (org.opennms.systemreport.formatters.FtpSystemReportFormatter)1