Class: Nexpose::ReportTemplate
- Inherits:
-
Object
- Object
- Nexpose::ReportTemplate
- Includes:
- Sanitize
- Defined in:
- lib/nexpose/report.rb
Overview
Definition object for a report template.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Array of report attributes, in the order they will be present in a report.
-
#built_in ⇒ Object
The report template is built-in, and cannot be modified.
-
#description ⇒ Object
Description of this report template.
-
#id ⇒ Object
The ID of the report template.
-
#name ⇒ Object
The name of the report template.
-
#properties ⇒ Object
Map of report properties.
-
#scope ⇒ Object
The visibility (scope) of the report template.
-
#sections ⇒ Object
Array of report sections.
-
#show_device_names ⇒ Object
Display asset names with IPs.
-
#type ⇒ Object
With a data template, you can export comma-separated value (CSV) files with vulnerability-based data.
Class Method Summary collapse
-
.load(connection, template_id) ⇒ Object
Retrieve the configuration for a report template.
- .parse(xml) ⇒ Object
Instance Method Summary collapse
- #delete(connection) ⇒ Object
-
#initialize(name, type = 'document', id = -1,, scope = 'silo', built_in = false) ⇒ ReportTemplate
constructor
A new instance of ReportTemplate.
-
#save(connection) ⇒ Object
Save the configuration for a report template.
- #to_xml ⇒ Object
Methods included from Sanitize
Constructor Details
#initialize(name, type = 'document', id = -1,, scope = 'silo', built_in = false) ⇒ ReportTemplate
Returns a new instance of ReportTemplate.
665 666 667 668 669 670 671 672 673 674 675 676 |
# File 'lib/nexpose/report.rb', line 665 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_device_names = false end |
Instance Attribute Details
#attributes ⇒ Object
Array of report attributes, in the order they will be present in a report.
661 662 663 |
# File 'lib/nexpose/report.rb', line 661 def attributes @attributes end |
#built_in ⇒ Object
The report template is built-in, and cannot be modified.
652 653 654 |
# File 'lib/nexpose/report.rb', line 652 def built_in @built_in end |
#description ⇒ Object
Description of this report template.
654 655 656 |
# File 'lib/nexpose/report.rb', line 654 def description @description end |
#id ⇒ Object
The ID of the report template.
637 638 639 |
# File 'lib/nexpose/report.rb', line 637 def id @id end |
#name ⇒ Object
The name of the report template.
639 640 641 |
# File 'lib/nexpose/report.rb', line 639 def name @name end |
#properties ⇒ Object
Map of report properties.
659 660 661 |
# File 'lib/nexpose/report.rb', line 659 def properties @properties end |
#scope ⇒ Object
The visibility (scope) of the report template. One of: global|silo
650 651 652 |
# File 'lib/nexpose/report.rb', line 650 def scope @scope end |
#sections ⇒ Object
Array of report sections.
657 658 659 |
# File 'lib/nexpose/report.rb', line 657 def sections @sections end |
#show_device_names ⇒ Object
Display asset names with IPs.
663 664 665 |
# File 'lib/nexpose/report.rb', line 663 def show_device_names @show_device_names end |
#type ⇒ Object
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.
647 648 649 |
# File 'lib/nexpose/report.rb', line 647 def type @type end |
Class Method Details
.load(connection, template_id) ⇒ Object
Retrieve the configuration for a report template.
699 700 701 |
# File 'lib/nexpose/report.rb', line 699 def self.load(connection, template_id) connection.get_report_template(template_id) end |
.parse(xml) ⇒ Object
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 |
# File 'lib/nexpose/report.rb', line 735 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_device_names = show.attributes['enabled'] == '1' end return template end nil end |
Instance Method Details
#delete(connection) ⇒ Object
689 690 691 692 693 694 695 696 |
# File 'lib/nexpose/report.rb', line 689 def delete(connection) xml = %Q{<ReportTemplateDeleteRequest session-id='#{connection.session_id}' template-id='#{@id}'>} xml << '</ReportTemplateDeleteRequest>' response = connection.execute(xml) if response.success @id = response.attributes['template-id'] end end |
#save(connection) ⇒ Object
Save the configuration for a report template.
679 680 681 682 683 684 685 686 687 |
# File 'lib/nexpose/report.rb', line 679 def save(connection) xml = %Q{<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 ⇒ Object
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 |
# File 'lib/nexpose/report.rb', line 707 def to_xml xml = %Q{<ReportTemplate id='#{@id}' name='#{@name}' type='#{@type}'} xml << %Q{ scope='#{@scope}'} if @scope xml << %Q{ builtin='#{@built_in}'} if @built_in xml << '>' xml << %Q{<description>#{@description}</description>} if @description unless @attributes.empty? xml << '<ReportAttributes>' @attributes.each do |attr| xml << %Q(<ReportAttribute name='#{attr}'/>) end xml << '</ReportAttributes>' end unless @sections.empty? xml << '<ReportSections>' properties.each_pair do |name, value| xml << %Q{<property name='#{name}'>#{replace_entities(value)}</property>} end @sections.each { |section| xml << section.to_xml } xml << '</ReportSections>' end xml << %Q{<Settings><showDeviceNames enabled='#{@show_device_names ? 1 : 0}' /></Settings>} xml << '</ReportTemplate>' end |