-
Notifications
You must be signed in to change notification settings - Fork 103
Using Reports
Gavin Schneider edited this page Mar 1, 2016
·
4 revisions
Here's a walk-through of how to use a Reports, as of version 0.1.0 of the gem.
In order to keep verbosity to a minimum, all of the examples assume that the Nexpose module has been included:
include Nexpose
As with all uses of the gem, in order to interact with a Nexpose console you will need an active, valid connection. The following line can be assumed for all code below:
nsc = Connection.new('10.2.0.1', 'nxadmin', 'secret-password')
nsc.login
This can be useful, particularly as a building block for other operations that depend upon a report's status.
last = nsc.last_report(15)
puts "Report ID 15 last run on #{last.generated_on} with a status of #{last.status}."
template = ReportTemplate.load(nsc, 'audit-report')
template.name = "#{template.name} Copy"
template.id = -1
template.built_in = false
template.show_device_names = true
id = template.save(nsc)
puts "New template saved with ID: #{id}"
config = ReportConfig.load(nsc, 15)
summary = config.generate(nsc)
unless summary.status == 'Started'
puts "Report ID 15 finished on #{summary.generated_on} with a status of #{summary.status}."
else
puts 'Report ID 15 started.'
end
This example copies the existing configuration, but does not auto-generate the report when saved.
config.id = -1
config.name = "#{config.name} Copy"
id = config.save(nsc, false)
puts "Saved report with report ID #{id}."
Simple way of cleaning out old, invalid report attempts.
bad_reports = nsc.report_history(15).select do |summary|
summary.status == 'Failed'
|| summary.status == 'Aborted'
|| summary.status == 'Unknown'
end
bad_reports.each do |report|
report.delete(nsc)
end
pci_templates = nsc.report_templates.select { |tmp| tmp.name =~ /PCI/ }
pci_templates.each { |tmp| puts tmp.id }
reports = nsc.reports.select do |report|
report.status == 'Generated' && report.generated_on > '20120813T000000000'
end
reports.each { |report| puts report.config_id }
report = ReportConfig.new('CSV Export', 'basic-vulnerability-check-results', 'csv')
report.add_filter('site', 31)
id = report.save(nsc, true)
puts "Report saved with ID #{id}"
until nsc.last_report(id)
puts 'waiting . . .'
end
last = nsc.last_report(id)
data = nsc.download(last.uri)
puts data.inspect
adhoc = AdhocReportConfig.new('audit-report', 'pdf', 31)
data = adhoc.generate(nsc)
File.open('site-31-audit.pdf', 'w') { |file| file.write(data) }
Project Home 🔹 Release Notes 🔹 Wiki 🔹 Issues 🔹 Pull Requests