class Nexpose::Ticket

Attributes

comments[RW]

Array of comments about the ticket.

history[RW]

History of events on this ticket.

vulnerabilities[RW]

List of vulnerabilities (by ID) this ticket addresses.

Public Class Methods

load(connection, id) click to toggle source

Load existing ticket data.

@param [Connection] connection Connection to console where ticket exists. @param [Fixnum] id Ticket ID of an existing ticket. @return [Ticket] Ticket populated with current state.

# File lib/nexpose/ticket.rb, line 170
def self.load(connection, id)
  # TODO: Load multiple tickets in a single request, as supported by API.
  xml = connection.make_xml('TicketDetailsRequest')
  xml.add_element('Ticket', { 'id' => id })
  response = connection.execute(xml, '1.2')
  response.res.elements.each('//TicketInfo') do |info|
    return parse_details(info)
  end
end
new(name, id = nil) click to toggle source
# File lib/nexpose/ticket.rb, line 133
def initialize(name, id = nil)
  @id              = id
  @name            = name
  @priority        = Priority::NORMAL
  @vulnerabilities = []
  @comments        = []
  @history         = []
end
parse_details(xml) click to toggle source
# File lib/nexpose/ticket.rb, line 206
def self.parse_details(xml)
  ticket = parse(xml)

  xml.elements.each('Vulnerabilities/Vulnerability') do |vuln|
    ticket.vulnerabilities << vuln.attributes['id']
  end

  xml.elements.each('TicketHistory/Entry') do |entry|
    ticket.history << Event.parse(entry)
  end

  ticket.comments = ticket.history.select { |h| h.description == 'Added comment' }.map(&:comment)

  ticket
end

Public Instance Methods

delete(connection) click to toggle source

Delete this ticket from the system.

@param [Connection] connection Connection to console where ticket exists. @return [Boolean] Whether the ticket was successfully delete.

# File lib/nexpose/ticket.rb, line 160
def delete(connection)
  connection.delete_ticket(@id)
end
save(connection) click to toggle source

Save this ticket to a Nexpose console.

@param [Connection] connection Connection to console where ticket exists. @return [Fixnum] Unique ticket ID assigned to this ticket.

# File lib/nexpose/ticket.rb, line 147
def save(connection)
  xml = connection.make_xml('TicketCreateRequest')
  xml.add_element(to_xml)

  response = connection.execute(xml, '1.2')
  @id = response.attributes['id'].to_i if response.success
end
to_xml() click to toggle source
# File lib/nexpose/ticket.rb, line 180
def to_xml
  xml = REXML::Element.new('TicketCreate')
  xml.add_attributes({ 'name' => @name,
                       'priority' => @priority,
                       'device-id' => @asset_id,
                       'assigned-to' => @assigned_to })

  vuln_xml = REXML::Element.new('Vulnerabilities')
  @vulnerabilities.each do |vuln_id|
    vuln_xml.add_element('Vulnerability', { 'id' => vuln_id.downcase })
  end
  xml.add_element(vuln_xml)

  unless @comments.empty?
    comments_xml = REXML::Element.new('Comments')
    @comments.each do |comment|
      comment_xml = REXML::Element.new('Comment')
      comment_xml.add_text(comment)
      comments_xml.add_element(comment_xml)
    end
    xml.add_element(comments_xml)
  end

  xml
end