Class: Nexpose::ReportConfig

Inherits:
AdhocReportConfig show all
Includes:
Sanitize
Defined in:
lib/nexpose/report.rb

Overview

Definition object for a report configuration.

Instance Attribute Summary collapse

Attributes inherited from AdhocReportConfig

#baseline, #filters, #format, #language, #owner, #template_id, #time_zone

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sanitize

#replace_entities

Methods inherited from AdhocReportConfig

#add_filter

Methods included from XMLUtils

#make_xml, #parse_xml

Constructor Details

#initialize(name, template_id, format, id = -1,, owner = nil, time_zone = nil) ⇒ ReportConfig

Construct a basic ReportConfig object.



285
286
287
288
289
290
291
292
293
294
295
# File 'lib/nexpose/report.rb', line 285

def initialize(name, template_id, format, id = -1, owner = nil, time_zone = nil)
  @name = name
  @template_id = template_id
  @format = format
  @id = id
  @owner = owner
  @time_zone = time_zone

  @filters = []
  @users = []
end

Instance Attribute Details

#db_exportObject

Database export configuration.



282
283
284
# File 'lib/nexpose/report.rb', line 282

def db_export
  @db_export
end

#deliveryObject

Report delivery configuration.



280
281
282
# File 'lib/nexpose/report.rb', line 280

def delivery
  @delivery
end

#descriptionObject

Description associated with this report.



274
275
276
# File 'lib/nexpose/report.rb', line 274

def description
  @description
end

#frequencyObject

Configuration of when a report is generated.



278
279
280
# File 'lib/nexpose/report.rb', line 278

def frequency
  @frequency
end

#idObject

The ID of the report definition (config). Use -1 to create a new definition.



269
270
271
# File 'lib/nexpose/report.rb', line 269

def id
  @id
end

#nameObject

The unique name assigned to the report definition.



271
272
273
# File 'lib/nexpose/report.rb', line 271

def name
  @name
end

#usersObject

Array of user IDs which have access to resulting reports.



276
277
278
# File 'lib/nexpose/report.rb', line 276

def users
  @users
end

Class Method Details

.build(connection, site_id, site_name, type, format, generate_now = false) ⇒ Object

Build and save a report configuration against the specified site using the supplied type and format.

Returns the new configuration.



309
310
311
312
313
314
315
316
# File 'lib/nexpose/report.rb', line 309

def self.build(connection, site_id, site_name, type, format, generate_now = false)
  name = %(#{site_name} #{type} report in #{format})
  config = ReportConfig.new(name, type, format)
  config.frequency = Frequency.new(true, false)
  config.filters << Filter.new('site', site_id)
  config.save(connection, generate_now)
  config
end

.load(connection, report_config_id) ⇒ Object

Retrieve the configuration for an existing report definition.



298
299
300
301
# File 'lib/nexpose/report.rb', line 298

def self.load(connection, report_config_id)
  xml = %(<ReportConfigRequest session-id='#{connection.session_id}' reportcfg-id='#{report_config_id}'/>)
  ReportConfig.parse(connection.execute(xml))
end

.parse(xml) ⇒ Object



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/nexpose/report.rb', line 367

def self.parse(xml)
  xml.res.elements.each('//ReportConfig') do |cfg|
    config = ReportConfig.new(cfg.attributes['name'],
                              cfg.attributes['template-id'],
                              cfg.attributes['format'],
                              cfg.attributes['id'].to_i,
                              cfg.attributes['owner'].to_i,
                              cfg.attributes['timezone'])

    cfg.elements.each('//description') do |desc|
      config.description = desc.text
    end

    config.filters = Filter.parse(xml)

    cfg.elements.each('//user') do |user|
      config.users << user.attributes['id'].to_i
    end

    cfg.elements.each('//Baseline') do |baseline|
      config.baseline = baseline.attributes['compareTo']
    end

    config.frequency = Frequency.parse(cfg)
    config.delivery = Delivery.parse(cfg)
    config.db_export = DBExport.parse(cfg)

    return config
  end
  nil
end

Instance Method Details

#delete(connection) ⇒ Object

Delete this report definition from the Security Console. Deletion will also remove all reports previously generated from the configuration.



337
338
339
# File 'lib/nexpose/report.rb', line 337

def delete(connection)
  connection.delete_report_config(@id)
end

#generate(connection, wait = false) ⇒ Object

Generate a new report using this report definition.



330
331
332
# File 'lib/nexpose/report.rb', line 330

def generate(connection, wait = false)
  connection.generate_report(@id, wait)
end

#save(connection, generate_now = false) ⇒ Object

Save the configuration of this report definition.



319
320
321
322
323
324
325
326
327
# File 'lib/nexpose/report.rb', line 319

def save(connection, generate_now = false)
  xml = %(<ReportSaveRequest session-id='#{connection.session_id}' generate-now='#{generate_now ? 1 : 0}'>)
  xml << to_xml
  xml << '</ReportSaveRequest>'
  response = connection.execute(xml)
  if response.success
    @id = response.attributes['reportcfg-id'].to_i
  end
end

#to_xmlObject



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/nexpose/report.rb', line 343

def to_xml
  xml = %(<ReportConfig format='#{@format}' id='#{@id}' name='#{replace_entities(@name)}' template-id='#{@template_id}')
  xml << %( owner='#{@owner}') if @owner
  xml << %( timezone='#{@time_zone}') if @time_zone
  xml << %( language='#{@language}') if @language
  xml << '>'
  xml << %(<description>#{@description}</description>) if @description

  xml << '<Filters>'
  @filters.each { |filter| xml << filter.to_xml }
  xml << '</Filters>'

  xml << '<Users>'
  @users.each { |user| xml << %(<user id='#{user}' />) }
  xml << '</Users>'

  xml << %(<Baseline compareTo='#{@baseline}' />) if @baseline
  xml << @frequency.to_xml if @frequency
  xml << @delivery.to_xml if @delivery
  xml << @db_export.to_xml if @db_export

  xml << '</ReportConfig>'
end