-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus
executable file
·105 lines (84 loc) · 2.55 KB
/
status
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env ruby
require 'json'
require 'optparse'
require_relative 'lib/perseids_status'
options = {
version: 'current',
compare: true,
count: 10,
email: false,
file: 'config.json',
quiet: false,
record: false,
request: true,
save: true,
email_server: 'localhost',
email_port: 25,
email_domain: 'localhost',
}
OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength
opts.banner = 'Usage: test.rb [options]'
opts.on('-v', '--version VERSION', 'Version to compare ("comparison-<date>" or "current", default "current")') do |v|
if v != 'current'
options[:version] = v
options[:request] = false
end
end
opts.on('-c', '--count NUMBER', OptionParser::DecimalInteger, 'Number of records to save (default 10)') do |c|
options[:count] = c
end
opts.on('-e', '--email EMAIL', 'Email address to send reports to (default false)') do |e|
options[:email] = e
end
opts.on('-s', '--email-server SERVER', 'SMTP server address (default localhost)') do |s|
options[:email_server] = s
end
opts.on('-p', '--email-port PORT', OptionParser::DecimalInteger, 'SMTP server port (default 25)') do |p|
options[:email_port] = p
end
opts.on('-d', '--email-domain DOMAIN', 'SMTP HELO domain (default localhost)') do |d|
options[:email_domain] = d
end
opts.on('-f', '--file FILE', 'Configuration file location (default config.json)') do |f|
options[:file] = f
end
opts.on('-q', '--quiet', 'Save files but do not print results (default false)') do
options[:quiet] = true
end
opts.on('-r', '--record', 'Record responses instead of running comparison (default false)') do
options[:record] = true
options[:compare] = false
end
opts.on('-u', '--unsaved', 'Perform comparison but do not save results (default false)') do
options[:save] = false
end
opts.on('-h', '--help', 'Show this message') do
options[:help] = true
puts opts
exit
end
end.parse!
config = JSON.parse(File.read(options[:file]), symbolize_names: true)
status = PerseidsStatus.new(config)
if options[:request]
status.make_requests!
if options[:record]
status.record_canonical!
else
status.record_comparison!
end
end
if options[:compare]
status.read_canonical!
status.read_comparison!(options[:version])
status.write_json_and_html!(options[:count]) if options[:save]
status.print_results unless options[:quiet]
if options[:email]
status.send_email!(
options[:email],
options[:email_server],
options[:email_port],
options[:email_domain],
)
end
end