-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathreport_distlist.rb
55 lines (42 loc) · 1.31 KB
/
report_distlist.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env ruby
# Date Created: 05.21.2018
# Written by: BrianWGray
# Written for
# https://kb.help.rapid7.com/discuss/5b031d8a01b0ff00038d8b9b
## Script performs the following tasks
## 1.) pull report configuration
## 2.) generate list of report recipients
require 'yaml'
require 'nexpose'
require 'pp'
include Nexpose
# Default Values from yaml file
config_path = File.expand_path("../conf/nexpose.yaml", __FILE__)
config = YAML.load_file(config_path)
host = config["hostname"]
userid = config["username"]
password = config["passwordkey"]
port = config["port"]
nsc = Nexpose::Connection.new(host, userid, password, port)
begin
nsc.login
rescue ::Nexpose::APIError => err
$stderr.puts("Connection failed: #{err.reason}")
exit(1)
end
at_exit { nsc.logout }
# Pull a list of all reports
reportList = nsc.list_reports
# Iterate through each report
reportList.each do |reportDetails|
# Load report information for each report
reportInfo = ReportConfig.load(nsc, reportDetails.config_id)
# If the report has external recipients configured, print the recipient list
if(reportInfo.delivery.email.respond_to? :recipients) then
puts("Report: #{reportInfo.name}")
reportInfo.delivery.email.recipients.each do |eachRecipient|
puts(eachRecipient)
end
end
end
exit