prometheus-splash 0.8.0 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +47 -3
- data/README.md +400 -178
- data/config/splash.yml +28 -14
- data/lib/splash/backends.rb +7 -1
- data/lib/splash/backends/file.rb +1 -1
- data/lib/splash/cli/commands.rb +122 -37
- data/lib/splash/cli/config.rb +12 -1
- data/lib/splash/cli/daemon.rb +1 -1
- data/lib/splash/cli/logs.rb +144 -48
- data/lib/splash/cli/process.rb +145 -52
- data/lib/splash/cli/transfers.rb +10 -3
- data/lib/splash/commands.rb +115 -40
- data/lib/splash/config.rb +112 -29
- data/lib/splash/config/flush.rb +2 -2
- data/lib/splash/constants.rb +3 -4
- data/lib/splash/daemon/orchestrator.rb +6 -7
- data/lib/splash/daemon/orchestrator/grammar.rb +1 -1
- data/lib/splash/dependencies.rb +1 -0
- data/lib/splash/exiter.rb +1 -1
- data/lib/splash/helpers.rb +1 -1
- data/lib/splash/logs.rb +94 -16
- data/lib/splash/monkeys.rb +5 -0
- data/lib/splash/processes.rb +91 -16
- data/lib/splash/sequences.rb +6 -1
- data/lib/splash/transfers.rb +13 -8
- data/lib/splash/webadmin/api/routes/commands.rb +15 -3
- data/lib/splash/webadmin/api/routes/config.rb +140 -2
- data/lib/splash/webadmin/api/routes/logs.rb +32 -17
- data/lib/splash/webadmin/api/routes/process.rb +21 -9
- data/lib/splash/webadmin/api/routes/sequences.rb +2 -2
- data/lib/splash/webadmin/main.rb +15 -1
- data/lib/splash/webadmin/portal/controllers/commands.rb +101 -1
- data/lib/splash/webadmin/portal/controllers/documentation.rb +2 -0
- data/lib/splash/webadmin/portal/controllers/home.rb +6 -1
- data/lib/splash/webadmin/portal/controllers/logs.rb +71 -1
- data/lib/splash/webadmin/portal/controllers/processes.rb +75 -3
- data/lib/splash/webadmin/portal/controllers/proxy.rb +2 -1
- data/lib/splash/webadmin/portal/controllers/restclient.rb +6 -1
- data/lib/splash/webadmin/portal/controllers/sequences.rb +2 -0
- data/lib/splash/webadmin/portal/public/css/ultragreen.css +6 -0
- data/lib/splash/webadmin/portal/public/favicon.ico +0 -0
- data/lib/splash/webadmin/portal/views/command_form.slim +45 -0
- data/lib/splash/webadmin/portal/views/command_history.slim +27 -0
- data/lib/splash/webadmin/portal/views/commands.slim +70 -20
- data/lib/splash/webadmin/portal/views/documentation.slim +1 -1
- data/lib/splash/webadmin/portal/views/home.slim +19 -20
- data/lib/splash/webadmin/portal/views/layout.slim +2 -2
- data/lib/splash/webadmin/portal/views/log_form.slim +27 -0
- data/lib/splash/webadmin/portal/views/log_history.slim +24 -0
- data/lib/splash/webadmin/portal/views/logs.slim +95 -21
- data/lib/splash/webadmin/portal/views/nav.slim +1 -1
- data/lib/splash/webadmin/portal/views/not_found.slim +1 -1
- data/lib/splash/webadmin/portal/views/process_form.slim +24 -0
- data/lib/splash/webadmin/portal/views/process_history.slim +24 -0
- data/lib/splash/webadmin/portal/views/processes.slim +80 -7
- data/lib/splash/webadmin/portal/views/proxy.slim +2 -2
- data/lib/splash/webadmin/portal/views/restclient.slim +7 -4
- data/lib/splash/webadmin/portal/views/restclient_result.slim +24 -20
- data/lib/splash/webadmin/portal/views/sequences.slim +1 -1
- data/prometheus-splash.gemspec +4 -4
- data/ultragreen_roodi_coding_convention.yml +4 -4
- metadata +18 -10
data/lib/splash/cli/process.rb
CHANGED
@@ -12,65 +12,77 @@ module CLISplash
|
|
12
12
|
# Thor method : unning Splash configured processes monitors analyse
|
13
13
|
desc "analyse", "analyze processes defined in Splash config"
|
14
14
|
def analyse
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
15
|
+
if is_root? then
|
16
|
+
log = get_logger
|
17
|
+
results = ProcessScanner::new
|
18
|
+
res = results.analyse
|
19
|
+
log.info "Splash Configured process records :"
|
20
|
+
full_status = true
|
21
|
+
results.output.each do |result|
|
22
|
+
if result[:status] == :running then
|
23
|
+
log.ok "Process : #{result[:process]} : running"
|
24
|
+
log.item "Detected patterns : "
|
25
|
+
result[:patterns].each do |pattern|
|
26
|
+
log.arrow "/#{pattern}/"
|
27
|
+
end
|
28
|
+
log.item "CPU usage in % : #{result[:cpu]} "
|
29
|
+
log.item "Memory usage in % : #{result[:mem]} "
|
30
|
+
else
|
31
|
+
log.ko "Process : #{result[:process]} : inexistant"
|
32
|
+
log.item "Detected patterns : "
|
33
|
+
result[:patterns].each do |pattern|
|
34
|
+
log.arrow "/#{pattern}/"
|
35
|
+
end
|
26
36
|
end
|
27
|
-
log.item "CPU usage in % : #{result[:cpu]} "
|
28
|
-
log.item "Memory usage in % : #{result[:mem]} "
|
29
|
-
else
|
30
|
-
log.ko "Process : #{result[:process]} : inexistant"
|
31
|
-
log.item "Detected patterns : "
|
32
|
-
result[:patterns].each do |pattern|
|
33
|
-
log.arrow "/#{pattern}/"
|
34
|
-
end
|
35
|
-
end
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
full_status = false unless result[:status] == :running
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
if full_status then
|
42
|
+
log.ok "Global status : no error found"
|
43
|
+
else
|
44
|
+
log.error "Global status : some error found"
|
45
|
+
end
|
46
|
+
splash_exit case: :quiet_exit
|
42
47
|
else
|
43
|
-
|
48
|
+
splash_exit case: :not_root, :more => "Process analysis"
|
44
49
|
end
|
45
|
-
splash_exit case: :quiet_exit
|
46
50
|
end
|
47
51
|
|
48
52
|
|
49
53
|
# Thor method : running Splash configured processes monitors analyse and sending to Prometheus Pushgateway
|
50
54
|
desc "monitor", "monitor processes defined in Splash config"
|
51
55
|
def monitor
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
if is_root? then
|
57
|
+
log = get_logger
|
58
|
+
log.level = :fatal if options[:quiet]
|
59
|
+
result = ProcessScanner::new
|
60
|
+
result.analyse
|
61
|
+
splash_exit result.notify
|
62
|
+
else
|
63
|
+
splash_exit case: :not_root, :more => "Process analysis"
|
64
|
+
end
|
57
65
|
end
|
58
66
|
|
59
67
|
# Thor method : display a specific Splash configured process monitor
|
60
68
|
desc "show PROCESS", "show Splash configured process record for PROCESS"
|
61
69
|
def show(record)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
if is_root? then
|
71
|
+
log = get_logger
|
72
|
+
process_recordset = get_config.processes.select{|item| item[:process] == record }
|
73
|
+
unless process_recordset.empty? then
|
74
|
+
record = process_recordset.first
|
75
|
+
log.item "Process monitor : #{record[:process]}"
|
76
|
+
log.arrow "patterns :"
|
77
|
+
record[:patterns].each do |pattern|
|
78
|
+
log.flat " - /#{pattern}/"
|
79
|
+
end
|
80
|
+
splash_exit case: :quiet_exit
|
81
|
+
else
|
82
|
+
splash_exit case: :not_found, :more => "Process not configured"
|
70
83
|
end
|
71
|
-
splash_exit case: :quiet_exit
|
72
84
|
else
|
73
|
-
splash_exit case: :
|
85
|
+
splash_exit case: :not_root, :more => "Process analysis"
|
74
86
|
end
|
75
87
|
end
|
76
88
|
|
@@ -82,20 +94,101 @@ module CLISplash
|
|
82
94
|
LONGDESC
|
83
95
|
option :detail, :type => :boolean, :aliases => "-D"
|
84
96
|
def list
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
97
|
+
if is_root? then
|
98
|
+
log = get_logger
|
99
|
+
log.info "Splash configured process records :"
|
100
|
+
process_recordset = get_config.processes
|
101
|
+
log.ko 'No configured process found' if process_recordset.empty?
|
102
|
+
process_recordset.each do |record|
|
103
|
+
log.item "Process monitor : #{record[:process]}"
|
104
|
+
if options[:detail] then
|
105
|
+
log.arrow "patterns :"
|
106
|
+
record[:patterns].each do |pattern|
|
107
|
+
log.flat " - /#{pattern}/"
|
108
|
+
end
|
95
109
|
end
|
96
110
|
end
|
111
|
+
splash_exit case: :quiet_exit
|
112
|
+
else
|
113
|
+
splash_exit case: :not_root, :more => "Process analysis"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Thor method : display the full list of Splash configured process monitors
|
118
|
+
desc "get_result PROCESS", "Get last or specific process monitoring report"
|
119
|
+
long_desc <<-LONGDESC
|
120
|
+
Get last or specific process monitoring report\n
|
121
|
+
with --date <DATE>, a date format string (same as in history ouput)
|
122
|
+
LONGDESC
|
123
|
+
option :date, :type => :string, :aliases => "-D"
|
124
|
+
def get_result(process)
|
125
|
+
if is_root? then
|
126
|
+
log = get_logger
|
127
|
+
log.info "Process : #{process}"
|
128
|
+
config = get_config
|
129
|
+
records = ProcessRecords::new(process).get_all_records
|
130
|
+
if options[:date] then
|
131
|
+
wanted = records.select{|key,value| key.keys.first == options[:date]}.first
|
132
|
+
else
|
133
|
+
wanted = records.last
|
134
|
+
end
|
135
|
+
if wanted.nil? then
|
136
|
+
splash_exit case: :not_found, more: "Process never monitored"
|
137
|
+
else
|
138
|
+
record =wanted.keys.first
|
139
|
+
value=wanted[record]
|
140
|
+
log.item record
|
141
|
+
log.arrow "Status : #{value[:status].to_s}"
|
142
|
+
log.arrow "CPU Percent : #{value[:cpu_percent]}"
|
143
|
+
log.arrow "MEM Percent : #{value[:mem_percent]}"
|
144
|
+
end
|
145
|
+
else
|
146
|
+
splash_exit case: :not_root, :more => "Process get result"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
# Thor method : show logs monitoring history
|
152
|
+
long_desc <<-LONGDESC
|
153
|
+
show Process monitoring history for LABEL\n
|
154
|
+
LONGDESC
|
155
|
+
option :table, :type => :boolean, :aliases => "-t"
|
156
|
+
desc "history PROCESS", "show process monitoring history"
|
157
|
+
def history(process)
|
158
|
+
if is_root? then
|
159
|
+
log = get_logger
|
160
|
+
log.info "Process : #{process}"
|
161
|
+
config = get_config
|
162
|
+
if options[:table] then
|
163
|
+
table = TTY::Table.new do |t|
|
164
|
+
t << ["Start Date", "Status", "CPU Percent", "MEM Percent"]
|
165
|
+
t << ['','','','']
|
166
|
+
ProcessRecords::new(process).get_all_records.each do |item|
|
167
|
+
record =item.keys.first
|
168
|
+
value=item[record]
|
169
|
+
t << [record, value[:status].to_s, value[:cpu_percent], value[:mem_percent]]
|
170
|
+
end
|
171
|
+
end
|
172
|
+
if check_unicode_term then
|
173
|
+
puts table.render(:unicode)
|
174
|
+
else
|
175
|
+
puts table.render(:ascii)
|
176
|
+
end
|
177
|
+
|
178
|
+
else
|
179
|
+
ProcessRecords::new(process).get_all_records.each do |item|
|
180
|
+
record =item.keys.first
|
181
|
+
value=item[record]
|
182
|
+
log.item record
|
183
|
+
log.arrow "Status : #{value[:status].to_s}"
|
184
|
+
log.arrow "CPU Percent : #{value[:cpu_percent]}"
|
185
|
+
log.arrow "MEM Percent : #{value[:mem_percent]}"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
splash_exit case: :quiet_exit
|
189
|
+
else
|
190
|
+
splash_exit case: :not_root, :more => "Process analysis"
|
97
191
|
end
|
98
|
-
splash_exit case: :quiet_exit
|
99
192
|
end
|
100
193
|
|
101
194
|
end
|
data/lib/splash/cli/transfers.rb
CHANGED
@@ -44,7 +44,10 @@ module CLISplash
|
|
44
44
|
log = get_logger
|
45
45
|
log.item "Transfer : #{name}"
|
46
46
|
config = get_config
|
47
|
-
data = TxRecords::new(name).get_all_records.select {|
|
47
|
+
data = TxRecords::new(name).get_all_records.select {|item|
|
48
|
+
record =item.keys.first
|
49
|
+
value=item[record]
|
50
|
+
record == options[:date]}.first
|
48
51
|
if data.nil? then
|
49
52
|
log.ko "Result for #{name} on date #{options[:date]} not found"
|
50
53
|
splash_exit case: :not_found, :more => "Result inexistant"
|
@@ -93,7 +96,9 @@ module CLISplash
|
|
93
96
|
table = TTY::Table.new do |t|
|
94
97
|
t << ["Start Date", "End date", "time", "Files count","File count error","Status"]
|
95
98
|
t << ['','','','','','']
|
96
|
-
TxRecords::new(name).get_all_records.each do |
|
99
|
+
TxRecords::new(name).get_all_records.each do |item|
|
100
|
+
record =item.keys.first
|
101
|
+
value=item[record]
|
97
102
|
start_date = record
|
98
103
|
end_date = (value[:end_date].nil?)? '': value[:end_date]
|
99
104
|
time = (value[:time].nil?)? '': value[:time]
|
@@ -111,7 +116,9 @@ module CLISplash
|
|
111
116
|
end
|
112
117
|
|
113
118
|
else
|
114
|
-
TxRecords::new(name).get_all_records.each do |
|
119
|
+
TxRecords::new(name).get_all_records.each do |item|
|
120
|
+
record =item.keys.first
|
121
|
+
value=item[record]
|
115
122
|
failed = (value[:count].nil? or value[:done].nil?)? 'undef': value[:count].to_i - value[:done].count
|
116
123
|
if value[:end_date].nil? then
|
117
124
|
log.item "Event : #{record} STATUS : #{value[:status]}"
|
data/lib/splash/commands.rb
CHANGED
@@ -6,6 +6,83 @@ module Splash
|
|
6
6
|
# Splash Commands module/namespace
|
7
7
|
module Commands
|
8
8
|
|
9
|
+
|
10
|
+
class CmdNotifier
|
11
|
+
|
12
|
+
@@registry = Prometheus::Client::Registry::new
|
13
|
+
@@metric_exitcode = Prometheus::Client::Gauge.new(:exitcode, docstring: 'SPLASH metric batch exitcode')
|
14
|
+
@@metric_time = Prometheus::Client::Gauge.new(:exectime, docstring: 'SPLASH metric batch execution time')
|
15
|
+
@@registry.register(@@metric_exitcode)
|
16
|
+
@@registry.register(@@metric_time)
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
def initialize(options={})
|
21
|
+
@config = get_config
|
22
|
+
@url = @config.prometheus_pushgateway_url
|
23
|
+
@name = "cmd_#{options[:name].to_s}"
|
24
|
+
@exitcode = options[:exitcode]
|
25
|
+
@time = options[:time]
|
26
|
+
end
|
27
|
+
|
28
|
+
# send metrics to Prometheus PushGateway
|
29
|
+
# @return [Bool]
|
30
|
+
def notify
|
31
|
+
unless verify_service url: @url then
|
32
|
+
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
|
33
|
+
end
|
34
|
+
@@metric_exitcode.set(@exitcode)
|
35
|
+
@@metric_time.set(@time)
|
36
|
+
hostname = Socket.gethostname
|
37
|
+
return Prometheus::Client::Push.new(@name, hostname, @url).add(@@registry)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
class CmdRecords
|
44
|
+
include Splash::Backends
|
45
|
+
include Splash::Constants
|
46
|
+
def initialize(name)
|
47
|
+
@name = name
|
48
|
+
@backend = get_backend :execution_trace
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def clear
|
53
|
+
@backend.del({:key => @name}) if @backend.exist?({key: @name})
|
54
|
+
end
|
55
|
+
|
56
|
+
def purge(retention)
|
57
|
+
retention = {} if retention.nil?
|
58
|
+
if retention.include? :hours then
|
59
|
+
adjusted_datetime = DateTime.now - retention[:hours].to_f / 24
|
60
|
+
elsif retention.include? :hours then
|
61
|
+
adjusted_datetime = DateTime.now - retention[:days].to_i
|
62
|
+
else
|
63
|
+
adjusted_datetime = DateTime.now - DEFAULT_RETENTION
|
64
|
+
end
|
65
|
+
|
66
|
+
data = get_all_records
|
67
|
+
|
68
|
+
data.delete_if { |item|
|
69
|
+
DateTime.parse(item.keys.first) <= (adjusted_datetime)}
|
70
|
+
@backend.put key: @name, value: data.to_yaml
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_record(record)
|
74
|
+
data = get_all_records
|
75
|
+
data.push({ DateTime.now.to_s => record })
|
76
|
+
@backend.put key: @name, value: data.to_yaml
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_all_records(options={})
|
80
|
+
return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : []
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
9
86
|
# command execution wrapper
|
10
87
|
class CommandWrapper
|
11
88
|
include Splash::Templates
|
@@ -16,11 +93,7 @@ module Splash
|
|
16
93
|
include Splash::Transports
|
17
94
|
|
18
95
|
|
19
|
-
|
20
|
-
@@metric_exitcode = Prometheus::Client::Gauge.new(:errorcode, docstring: 'SPLASH metric batch errorcode')
|
21
|
-
@@metric_time = Prometheus::Client::Gauge.new(:exectime, docstring: 'SPLASH metric batch execution time')
|
22
|
-
@@registry.register(@@metric_exitcode)
|
23
|
-
@@registry.register(@@metric_time)
|
96
|
+
|
24
97
|
|
25
98
|
# Constructor
|
26
99
|
# @param [String] name the name of the command
|
@@ -28,7 +101,7 @@ module Splash
|
|
28
101
|
@config = get_config
|
29
102
|
@url = @config.prometheus_pushgateway_url
|
30
103
|
@name = name
|
31
|
-
unless @config.commands.
|
104
|
+
unless @config.commands.select{|cmd| cmd[:name] == @name.to_sym }.count > 0 then
|
32
105
|
splash_exit case: :not_found, more: "command #{@name} is not defined in configuration"
|
33
106
|
end
|
34
107
|
end
|
@@ -43,14 +116,17 @@ module Splash
|
|
43
116
|
# @param [String] value numeric.to_s
|
44
117
|
# @param [String] time execution time numeric.to_s
|
45
118
|
# @return [Hash] Exiter case :quiet_exit
|
46
|
-
def notify(value,time)
|
119
|
+
def notify(value,time, session)
|
120
|
+
log = get_logger
|
47
121
|
unless verify_service url: @config.prometheus_pushgateway_url then
|
48
122
|
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
|
49
123
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
124
|
+
cmdmonitor = CmdNotifier::new({name: @name, exitcode: value, time: time})
|
125
|
+
if cmdmonitor.notify then
|
126
|
+
log.ok "Sending metrics to Prometheus Pushgateway",session
|
127
|
+
else
|
128
|
+
log.ko "Failed to send metrics to Prometheus Pushgateway",session
|
129
|
+
end
|
54
130
|
return { :case => :quiet_exit}
|
55
131
|
end
|
56
132
|
|
@@ -68,18 +144,20 @@ module Splash
|
|
68
144
|
session = (options[:session])? options[:session] : get_session
|
69
145
|
acase = { :case => :quiet_exit }
|
70
146
|
exit_code = 0
|
71
|
-
|
147
|
+
command = @config.commands.select{|command| command[:name] == @name.to_sym}.first
|
148
|
+
if command[:delegate_to] then
|
72
149
|
return { :case => :options_incompatibility, :more => '--hostname forbidden with delagate commands'} if options[:hostname]
|
73
|
-
log.send "Remote command : #{@name} execution delegate to : #{
|
150
|
+
log.send "Remote command : #{@name} execution delegate to : #{command[:delegate_to][:host]} as : #{command[:delegate_to][:remote_command]}", session
|
151
|
+
log.warn "Local command : #{command[:command]} defined but ignored, because delegate have the priority"
|
74
152
|
begin
|
75
153
|
transport = get_default_client
|
76
154
|
if transport.class == Hash and transport.include? :case then
|
77
155
|
return transport
|
78
156
|
else
|
79
157
|
res = transport.execute({ :verb => :execute_command,
|
80
|
-
payload: {:name =>
|
158
|
+
payload: {:name => command[:delegate_to][:remote_command].to_s},
|
81
159
|
:return_to => "splash.#{Socket.gethostname}.return",
|
82
|
-
:queue => "splash.#{
|
160
|
+
:queue => "splash.#{command[:delegate_to][:host]}.input" })
|
83
161
|
exit_code = res[:exit_code]
|
84
162
|
log.receive "return with exitcode #{exit_code}", session
|
85
163
|
|
@@ -93,70 +171,67 @@ module Splash
|
|
93
171
|
start_date = DateTime.now.to_s
|
94
172
|
unless options[:trace] then
|
95
173
|
log.item "Traceless execution", session
|
96
|
-
if
|
97
|
-
log.item "Execute with user : #{
|
98
|
-
system("sudo -u #{
|
174
|
+
if command[:user] then
|
175
|
+
log.item "Execute with user : #{command[:user]}.", session
|
176
|
+
system("sudo -u #{command[:user]} #{command[:command]} > /dev/null 2>&1")
|
99
177
|
else
|
100
|
-
system("#{
|
178
|
+
system("#{command[:command]} > /dev/null 2>&1")
|
101
179
|
end
|
102
180
|
time = Time.now - start
|
103
181
|
exit_code = $?.exitstatus
|
104
182
|
else
|
105
183
|
log.item "Tracefull execution", session
|
106
|
-
if
|
107
|
-
log.item "Execute with user : #{
|
108
|
-
stdout, stderr, status = Open3.capture3("sudo -u #{
|
184
|
+
if command[:user] then
|
185
|
+
log.item "Execute with user : #{command[:user]}.", session
|
186
|
+
stdout, stderr, status = Open3.capture3("sudo -u #{command[:user]} #{command[:command]}")
|
109
187
|
else
|
110
|
-
stdout, stderr, status = Open3.capture3(
|
188
|
+
stdout, stderr, status = Open3.capture3(command[:command])
|
111
189
|
end
|
112
190
|
time = Time.now - start
|
113
|
-
tp = Template::new(
|
114
|
-
list_token: @config.execution_template_tokens,
|
115
|
-
template_file: @config.execution_template_path)
|
116
191
|
data = Hash::new
|
117
192
|
data[:start_date] = start_date
|
118
193
|
data[:end_date] = DateTime.now.to_s
|
119
194
|
data[:cmd_name] = @name
|
120
|
-
data[:cmd_line] =
|
121
|
-
data[:desc] =
|
195
|
+
data[:cmd_line] = command[:command]
|
196
|
+
data[:desc] = command[:desc]
|
122
197
|
data[:status] = status.to_s
|
123
198
|
data[:stdout] = stdout
|
124
199
|
data[:stderr] = stderr
|
125
200
|
data[:exec_time] = time.to_s
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
backend.put key: key, value: data.to_yaml
|
201
|
+
cmdrec = CmdRecords::new @name
|
202
|
+
cmdrec.purge(command[:retention])
|
203
|
+
cmdrec.add_record data
|
130
204
|
exit_code = status.exitstatus
|
131
205
|
end
|
132
206
|
log.ok "Command executed", session
|
133
207
|
log.arrow "exitcode #{exit_code}", session
|
134
208
|
if options[:notify] then
|
135
|
-
acase = notify(exit_code,time.to_i)
|
136
|
-
get_logger.ok "Prometheus Gateway notified.",session
|
209
|
+
acase = notify(exit_code,time.to_i,session)
|
137
210
|
else
|
138
211
|
log.item "Without Prometheus notification", session
|
139
212
|
end
|
140
213
|
end
|
141
214
|
if options[:callback] then
|
142
|
-
on_failure = (
|
143
|
-
on_success = (
|
215
|
+
on_failure = (command[:on_failure])? command[:on_failure] : false
|
216
|
+
on_success = (command[:on_success])? command[:on_success] : false
|
144
217
|
if on_failure and exit_code > 0 then
|
145
218
|
log.item "On failure callback : #{on_failure}", session
|
146
|
-
if @config.commands.
|
219
|
+
if @config.commands.select {|item| item[:name] == on_failure}.count > 0 then
|
147
220
|
@name = on_failure.to_s
|
148
221
|
call_and_notify options
|
149
222
|
else
|
150
|
-
|
223
|
+
log.error "on_failure call error : #{on_failure.to_s} command inexistant.", session
|
224
|
+
acase = { :case => :configuration_error , :more => "Command #{command[:name]} callback coniguration error"}
|
151
225
|
end
|
152
226
|
end
|
153
227
|
if on_success and exit_code == 0 then
|
154
228
|
log.item "On success callback : #{on_success}", session
|
155
|
-
if @config.commands.
|
229
|
+
if @config.commands.select {|item| item[:name] == on_success}.count > 0 then
|
156
230
|
@name = on_success.to_s
|
157
231
|
call_and_notify options
|
158
232
|
else
|
159
|
-
|
233
|
+
log.error "on_success call error : #{on_success.to_s} command inexistant."
|
234
|
+
acase = { :case => :configuration_error , :more => "Command #{command[:name]} callback coniguration error"}
|
160
235
|
end
|
161
236
|
end
|
162
237
|
else
|