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
-
.get(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.
659 660 661 662 663 664 665 666 667 668 669 670 |
# File 'lib/nexpose/report.rb', line 659 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.
655 656 657 |
# File 'lib/nexpose/report.rb', line 655 def attributes @attributes end |
#built_in ⇒ Object
The report template is built-in, and cannot be modified.
646 647 648 |
# File 'lib/nexpose/report.rb', line 646 def built_in @built_in end |
#description ⇒ Object
Description of this report template.
648 649 650 |
# File 'lib/nexpose/report.rb', line 648 def description @description end |
#id ⇒ Object
The ID of the report template.
631 632 633 |
# File 'lib/nexpose/report.rb', line 631 def id @id end |
#name ⇒ Object
The name of the report template.
633 634 635 |
# File 'lib/nexpose/report.rb', line 633 def name @name end |
#properties ⇒ Object
Map of report properties.
653 654 655 |
# File 'lib/nexpose/report.rb', line 653 def properties @properties end |
#scope ⇒ Object
The visibility (scope) of the report template. One of: global|silo
644 645 646 |
# File 'lib/nexpose/report.rb', line 644 def scope @scope end |
#sections ⇒ Object
Array of report sections.
651 652 653 |
# File 'lib/nexpose/report.rb', line 651 def sections @sections end |
#show_device_names ⇒ Object
Display asset names with IPs.
657 658 659 |
# File 'lib/nexpose/report.rb', line 657 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.
641 642 643 |
# File 'lib/nexpose/report.rb', line 641 def type @type end |
Class Method Details
.get(connection, template_id) ⇒ Object
Retrieve the configuration for a report template.
693 694 695 |
# File 'lib/nexpose/report.rb', line 693 def self.get(connection, template_id) connection.get_report_template(template_id) end |
.parse(xml) ⇒ Object
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 |
# File 'lib/nexpose/report.rb', line 727 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
683 684 685 686 687 688 689 690 |
# File 'lib/nexpose/report.rb', line 683 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.
673 674 675 676 677 678 679 680 681 |
# File 'lib/nexpose/report.rb', line 673 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
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
# File 'lib/nexpose/report.rb', line 699 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 |