Class: Nexpose::Ticket
- Inherits:
-
TicketSummary
- Object
- TicketSummary
- Nexpose::Ticket
- Defined in:
- lib/nexpose/ticket.rb
Defined Under Namespace
Classes: Event
Instance Attribute Summary collapse
-
#comments ⇒ Object
Array of comments about the ticket.
-
#history ⇒ Object
History of events on this ticket.
-
#vulnerabilities ⇒ Object
List of vulnerabilities (by ID) this ticket addresses.
Attributes inherited from TicketSummary
#asset_id, #assigned_to, #author, #created_on, #id, #name, #priority, #state
Class Method Summary collapse
-
.load(connection, id) ⇒ Ticket
Load existing ticket data.
- .parse_details(xml) ⇒ Object
Instance Method Summary collapse
-
#delete(connection) ⇒ Boolean
Delete this ticket from the system.
-
#initialize(name, id = nil) ⇒ Ticket
constructor
A new instance of Ticket.
-
#save(connection) ⇒ Fixnum
Save this ticket to a Nexpose console.
- #to_xml ⇒ Object
Methods inherited from TicketSummary
Constructor Details
Instance Attribute Details
#comments ⇒ Object
Array of comments about the ticket.
128 129 130 |
# File 'lib/nexpose/ticket.rb', line 128 def comments @comments end |
#history ⇒ Object
History of events on this ticket.
131 132 133 |
# File 'lib/nexpose/ticket.rb', line 131 def history @history end |
#vulnerabilities ⇒ Object
List of vulnerabilities (by ID) this ticket addresses.
125 126 127 |
# File 'lib/nexpose/ticket.rb', line 125 def vulnerabilities @vulnerabilities end |
Class Method Details
.load(connection, id) ⇒ Ticket
Load existing ticket data.
169 170 171 172 173 174 175 176 177 |
# File 'lib/nexpose/ticket.rb', line 169 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 |
.parse_details(xml) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/nexpose/ticket.rb', line 205 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 { |e| e.comment } ticket end |
Instance Method Details
#delete(connection) ⇒ Boolean
Delete this ticket from the system.
159 160 161 |
# File 'lib/nexpose/ticket.rb', line 159 def delete(connection) connection.delete_ticket(@id) end |
#save(connection) ⇒ Fixnum
Save this ticket to a Nexpose console.
146 147 148 149 150 151 152 |
# File 'lib/nexpose/ticket.rb', line 146 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 ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/nexpose/ticket.rb', line 179 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 |