class Nexpose::ReportTemplate

Definition object for a report template.

Attributes

attributes[RW]

Array of report attributes, in the order they will be present in a report.

built_in[RW]

The report template is built-in, and cannot be modified.

description[RW]

Description of this report template.

id[RW]

The ID of the report template.

name[RW]

The name of the report template.

properties[RW]

Map of report properties.

scope[RW]

The visibility (scope) of the report template. One of: global|silo

sections[RW]

Array of report sections.

show_asset_names[RW]

Display asset names with IPs.

show_device_names[RW]

Display asset names with IPs.

show_device_names=[RW]

Display asset names with IPs.

type[RW]

With a data template, you can export comma-separated value (CSV) files with vulnerability-based data. With a document template, you can create PDF, RTF, HTML, or XML reports with asset-based information. When you retrieve a report template, the type will always be visible even though type is implied. When ReportTemplate is sent as a request, and the type attribute is not provided, the type attribute defaults to document, allowing for backward compatibility with existing API clients.

Public Class Methods

load(connection, template_id) click to toggle source

Retrieve the configuration for a report template.

# File lib/nexpose/report_template.rb, line 139
def self.load(connection, template_id)
  xml = %(<ReportTemplateConfigRequest session-id='#{connection.session_id}' template-id='#{template_id}'/>)
  ReportTemplate.parse(connection.execute(xml))
end
new(name, type = 'document', id = -1, scope = 'silo', built_in = false) click to toggle source
# File lib/nexpose/report_template.rb, line 115
def initialize(name, type = 'document', id = -1, scope = 'silo', built_in = false)
  @name             = name
  @type             = type
  @id               = id
  @scope            = scope
  @built_in         = built_in
  @sections         = []
  @properties       = {}
  @attributes       = []
  @show_asset_names = false
end
parse(xml) click to toggle source
# File lib/nexpose/report_template.rb, line 178
def self.parse(xml)
  xml.res.elements.each('//ReportTemplate') do |tmp|
    template = ReportTemplate.new(tmp.attributes['name'],
                                  tmp.attributes['type'],
                                  tmp.attributes['id'],
                                  tmp.attributes['scope'] || 'silo',
                                  tmp.attributes['builtin'])
    tmp.elements.each('//description') do |desc|
      template.description = desc.text
    end

    tmp.elements.each('//ReportAttributes/ReportAttribute') do |attr|
      template.attributes << attr.attributes['name']
    end

    tmp.elements.each('//ReportSections/property') do |property|
      template.properties[property.attributes['name']] = property.text
    end

    tmp.elements.each('//ReportSection') do |section|
      template.sections << Section.parse(section)
    end

    tmp.elements.each('//showDeviceNames') do |show|
      template.show_asset_names = show.attributes['enabled'] == '1'
    end

    return template
  end
  nil
end

Public Instance Methods

delete(connection) click to toggle source
# File lib/nexpose/report_template.rb, line 144
def delete(connection)
  connection.delete_report_template(@id)
end
save(connection) click to toggle source

Save the configuration for a report template.

# File lib/nexpose/report_template.rb, line 128
def save(connection)
  xml = %(<ReportTemplateSaveRequest session-id='#{connection.session_id}' scope='#{@scope}'>)
  xml << to_xml
  xml << '</ReportTemplateSaveRequest>'
  response = connection.execute(xml)
  if response.success
    @id = response.attributes['template-id']
  end
end
to_xml() click to toggle source
# File lib/nexpose/report_template.rb, line 150
def to_xml
  xml = %(<ReportTemplate id='#{@id}' name='#{@name}' type='#{@type}')
  xml << %( scope='#{@scope}') if @scope
  xml << %( builtin='#{@built_in}') if @built_in
  xml << '>'
  xml << %(<description>#{@description}</description>) if @description

  unless @attributes.empty?
    xml << '<ReportAttributes>'
    @attributes.each do |attr|
      xml << %(<ReportAttribute name='#{attr}'/>)
    end
    xml << '</ReportAttributes>'
  end

  unless @sections.empty?
    xml << '<ReportSections>'
    properties.each_pair do |name, value|
      xml << %(<property name='#{name}'>#{replace_entities(value)}</property>)
    end
    @sections.each { |section| xml << section.to_xml }
    xml << '</ReportSections>'
  end

  xml << %(<Settings><showDeviceNames enabled='#{@show_asset_names ? 1 : 0}' /></Settings>)
  xml << '</ReportTemplate>'
end