class Nexpose::ReportConfig
Definition object for a report configuration.
Attributes
Database export configuration.
Report delivery configuration.
Description associated with this report.
Configuration of when a report is generated.
The ID of the report definition (config). Use -1 to create a new definition.
The unique name assigned to the report definition.
Array of user IDs which have access to resulting reports.
Public Class Methods
Build and save a report configuration against the specified site using the supplied type and format.
Returns the new configuration.
# File lib/nexpose/report.rb, line 324 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) unless generate_now config.filters << Filter.new('site', site_id) config.save(connection, generate_now) config end
Retrieve the configuration for an existing report definition.
# File lib/nexpose/report.rb, line 313 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
Construct a basic ReportConfig
object.
# File lib/nexpose/report.rb, line 301 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
# File lib/nexpose/report.rb, line 382 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
Public Instance Methods
Delete this report definition from the Security Console
. Deletion will also remove all reports previously generated from the configuration.
# File lib/nexpose/report.rb, line 352 def delete(connection) connection.delete_report_config(@id) end
Generate a new report using this report definition.
# File lib/nexpose/report.rb, line 345 def generate(connection, wait = false) connection.generate_report(@id, wait) end
Save the configuration of this report definition.
# File lib/nexpose/report.rb, line 334 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
# File lib/nexpose/report.rb, line 358 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