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
|
# File 'lib/collins_notify/command_runner.rb', line 4
def run args
app = CollinsNotify::Application.new
begin
app.configure! args
get_contact_and_asset app, true rescue SystemExit => e
exit e.status
rescue CollinsNotify::ConfigurationError => e
app.logger.fatal "Error with input option - #{e}"
exit 1
rescue StandardError => e
app.logger.fatal "Error parsing CLI options - #{e}"
$stdout.puts CollinsNotify::Options.get_instance(app.config)
exit 2
end
app.config.type = :email if app.config.type.nil?
unless app.valid? then
$stdout.puts CollinsNotify::Options.get_instance(app.config)
exit 3
end
app.logger.trace "Configuration -> #{app.config.to_hash.inspect}"
begin
contact, asset = get_contact_and_asset app
if !app.notify!(asset, contact) then
raise Exception.new "failed"
end
rescue Timeout::Error => e
app.logger.fatal "TIMEOUT sending notification via #{app.type}"
exit 4
rescue Exception => e
app.logger.fatal "ERROR sending notification via #{app.type} - #{e}"
exit 5
end
app.logger.info "Successfully sent #{app.type} notification"
exit 0
end
|