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.
170 171 172 173 174 175 176 177 178 |
# 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 |
.parse_details(xml) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# 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 |
Instance Method Details
#delete(connection) ⇒ Boolean
Delete this ticket from the system.
160 161 162 |
# File 'lib/nexpose/ticket.rb', line 160 def delete(connection) connection.delete_ticket(@id) end |
#save(connection) ⇒ Fixnum
Save this ticket to a Nexpose console.
147 148 149 150 151 152 153 |
# 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 ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# 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 |