prometheus-splash 0.6.0 → 0.8.2
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 +38 -1
- data/README.md +1 -1
- data/config/splash.yml +97 -11
- data/lib/splash/backends.rb +1 -0
- data/lib/splash/cli.rb +4 -1
- data/lib/splash/cli/commands.rb +127 -7
- data/lib/splash/cli/daemon.rb +41 -1
- data/lib/splash/cli/logs.rb +111 -47
- data/lib/splash/cli/process.rb +112 -52
- data/lib/splash/cli/sequences.rb +114 -0
- data/lib/splash/cli/transfers.rb +213 -0
- data/lib/splash/cli/webadmin.rb +3 -3
- data/lib/splash/commands.rb +89 -22
- data/lib/splash/config.rb +149 -62
- data/lib/splash/config/sanitycheck.rb +1 -1
- data/lib/splash/constants.rb +11 -11
- data/lib/splash/daemon/controller.rb +10 -10
- data/lib/splash/daemon/metrics.rb +8 -8
- data/lib/splash/daemon/orchestrator.rb +96 -35
- data/lib/splash/daemon/orchestrator/grammar.rb +16 -1
- data/lib/splash/dependencies.rb +8 -0
- data/lib/splash/exiter.rb +1 -1
- data/lib/splash/helpers.rb +22 -4
- data/lib/splash/loggers/cli.rb +2 -10
- data/lib/splash/logs.rb +91 -17
- data/lib/splash/processes.rb +88 -17
- data/lib/splash/sequences.rb +105 -0
- data/lib/splash/transfers.rb +229 -0
- data/lib/splash/transports/rabbitmq.rb +0 -1
- data/lib/splash/webadmin.rb +4 -4
- data/lib/splash/webadmin/api/routes/commands.rb +2 -2
- data/lib/splash/webadmin/api/routes/config.rb +53 -2
- data/lib/splash/webadmin/api/routes/logs.rb +32 -17
- data/lib/splash/webadmin/api/routes/process.rb +4 -4
- data/lib/splash/webadmin/api/routes/sequences.rb +28 -0
- data/lib/splash/webadmin/main.rb +3 -2
- data/lib/splash/webadmin/portal/controllers/commands.rb +2 -0
- data/lib/splash/webadmin/portal/controllers/documentation.rb +3 -1
- data/lib/splash/webadmin/portal/controllers/home.rb +24 -0
- data/lib/splash/webadmin/portal/controllers/logs.rb +44 -1
- data/lib/splash/webadmin/portal/controllers/processes.rb +2 -0
- data/lib/splash/webadmin/portal/controllers/proxy.rb +15 -8
- data/lib/splash/webadmin/portal/controllers/restclient.rb +7 -2
- data/lib/splash/webadmin/portal/controllers/sequences.rb +9 -0
- data/lib/splash/webadmin/portal/init.rb +2 -2
- 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/commands.slim +1 -1
- data/lib/splash/webadmin/portal/views/documentation.slim +1 -1
- data/lib/splash/webadmin/portal/views/home.slim +53 -9
- data/lib/splash/webadmin/portal/views/layout.slim +2 -2
- data/lib/splash/webadmin/portal/views/logs.slim +68 -21
- data/lib/splash/webadmin/portal/views/logs_form.slim +24 -0
- 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/processes.slim +1 -1
- data/lib/splash/webadmin/portal/views/proxy.slim +5 -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 +50 -0
- data/prometheus-splash.gemspec +5 -2
- metadata +69 -4
@@ -0,0 +1,213 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# module for all Thor subcommands
|
4
|
+
module CLISplash
|
5
|
+
|
6
|
+
# Thor inherited class for transfers management
|
7
|
+
class Transfers < Thor
|
8
|
+
include Splash::Transfers
|
9
|
+
include Splash::Helpers
|
10
|
+
include Splash::Exiter
|
11
|
+
include Splash::Loggers
|
12
|
+
include Splash::Transfers
|
13
|
+
|
14
|
+
|
15
|
+
# Thor method : running transfer prepare
|
16
|
+
long_desc <<-LONGDESC
|
17
|
+
Prepare transfer with RSA Public key for NAME\n
|
18
|
+
Warning : interactive command only (prompt for passwd)
|
19
|
+
LONGDESC
|
20
|
+
desc "prepare", "Prepare transfers with RSA Public key"
|
21
|
+
def prepare(name)
|
22
|
+
acase = run_as_root :prepare_tx, name
|
23
|
+
splash_exit acase
|
24
|
+
end
|
25
|
+
|
26
|
+
# Thor method : Execute all transfers
|
27
|
+
long_desc <<-LONGDESC
|
28
|
+
Execute all transfers\n
|
29
|
+
Warning : interactive command only (prompt for passwd)
|
30
|
+
LONGDESC
|
31
|
+
desc "full_execute", "Execute all transfers"
|
32
|
+
def full_execute
|
33
|
+
acase = run_as_root :run_txs
|
34
|
+
splash_exit acase
|
35
|
+
end
|
36
|
+
|
37
|
+
# Thor method : Get specific result for a transfers
|
38
|
+
long_desc <<-LONGDESC
|
39
|
+
Get specific result for a transfers\n
|
40
|
+
LONGDESC
|
41
|
+
option :date, :type => :string, :aliases => "-d"
|
42
|
+
desc "get_result TRANSFER", "Get specific result for a transfers "
|
43
|
+
def get_result(name)
|
44
|
+
log = get_logger
|
45
|
+
log.item "Transfer : #{name}"
|
46
|
+
config = get_config
|
47
|
+
data = TxRecords::new(name).get_all_records.select {|item|
|
48
|
+
record =item.keys.first
|
49
|
+
value=item[record]
|
50
|
+
record == options[:date]}.first
|
51
|
+
if data.nil? then
|
52
|
+
log.ko "Result for #{name} on date #{options[:date]} not found"
|
53
|
+
splash_exit case: :not_found, :more => "Result inexistant"
|
54
|
+
else
|
55
|
+
record = options[:date]
|
56
|
+
value = data[record]
|
57
|
+
failed = (value[:count].nil? or value[:done].nil?)? 'undef': value[:count].to_i - value[:done].count
|
58
|
+
if value[:end_date].nil? then
|
59
|
+
log.item "Event : #{record} STATUS : #{value[:status]}"
|
60
|
+
else
|
61
|
+
log.item "Tx Begin : #{record} => end : #{value[:end_date]} STATUS : #{value[:status]}"
|
62
|
+
end
|
63
|
+
log.arrow "Tx Time : #{value[:time]}" unless value[:time].nil?
|
64
|
+
log.arrow "nb files : #{value[:count]}" unless value[:count].nil?
|
65
|
+
unless value[:wanted].nil?
|
66
|
+
log.arrow "Files wanted :" unless value[:wanted].empty?
|
67
|
+
value[:wanted].each do |file|
|
68
|
+
log.flat " * #{file}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
unless value[:done].nil?
|
72
|
+
log.arrow "Files done :" unless value[:done].empty?
|
73
|
+
value[:done].each do |file|
|
74
|
+
log.flat " * #{file}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
unless failed then
|
78
|
+
log.arrow "Nb failure : #{failed}"
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
splash_exit case: :quiet_exit
|
83
|
+
end
|
84
|
+
|
85
|
+
# Thor method : show specfic transfers history
|
86
|
+
long_desc <<-LONGDESC
|
87
|
+
show transfers history for transfer NAME\n
|
88
|
+
LONGDESC
|
89
|
+
option :table, :type => :boolean, :aliases => "-t"
|
90
|
+
desc "history", "Show transfers history"
|
91
|
+
def history(name)
|
92
|
+
log = get_logger
|
93
|
+
log.item "Transfer : #{name}"
|
94
|
+
config = get_config
|
95
|
+
if options[:table] then
|
96
|
+
table = TTY::Table.new do |t|
|
97
|
+
t << ["Start Date", "End date", "time", "Files count","File count error","Status"]
|
98
|
+
t << ['','','','','','']
|
99
|
+
TxRecords::new(name).get_all_records.each do |item|
|
100
|
+
record =item.keys.first
|
101
|
+
value=item[record]
|
102
|
+
start_date = record
|
103
|
+
end_date = (value[:end_date].nil?)? '': value[:end_date]
|
104
|
+
time = (value[:time].nil?)? '': value[:time]
|
105
|
+
count = (value[:count].nil?)? '': value[:count]
|
106
|
+
failed = (value[:count].nil? or value[:done].nil?)? '': value[:count].to_i - value[:done].count
|
107
|
+
status = value[:status]
|
108
|
+
t << [start_date, end_date, time, count, failed, status]
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
if check_unicode_term then
|
113
|
+
puts table.render(:unicode)
|
114
|
+
else
|
115
|
+
puts table.render(:ascii)
|
116
|
+
end
|
117
|
+
|
118
|
+
else
|
119
|
+
TxRecords::new(name).get_all_records.each do |item|
|
120
|
+
record =item.keys.first
|
121
|
+
value=item[record]
|
122
|
+
failed = (value[:count].nil? or value[:done].nil?)? 'undef': value[:count].to_i - value[:done].count
|
123
|
+
if value[:end_date].nil? then
|
124
|
+
log.item "Event : #{record} STATUS : #{value[:status]}"
|
125
|
+
else
|
126
|
+
log.item "Tx Begin : #{record} => end : #{value[:end_date]} STATUS : #{value[:status]}"
|
127
|
+
end
|
128
|
+
log.arrow "Tx Time : #{value[:time]}" unless value[:time].nil?
|
129
|
+
log.arrow "nb files : #{value[:count]}" unless value[:count].nil?
|
130
|
+
unless value[:wanted].nil?
|
131
|
+
log.arrow "Files wanted :" unless value[:wanted].empty?
|
132
|
+
value[:wanted].each do |file|
|
133
|
+
log.flat " * #{file}"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
unless value[:done].nil?
|
137
|
+
log.arrow "Files done :" unless value[:done].empty?
|
138
|
+
value[:done].each do |file|
|
139
|
+
log.flat " * #{file}"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
unless failed then
|
143
|
+
log.arrow "Nb failure : #{failed}"
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
148
|
+
splash_exit case: :quiet_exit
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
# Thor method : display a specific Splash configured transfer
|
153
|
+
desc "show TRANSFER", "show Splash configured transfer TRANSFER"
|
154
|
+
def show(transfer)
|
155
|
+
log = get_logger
|
156
|
+
transfer_record_set = get_config.transfers.select{|item| item[:name] == transfer.to_sym }
|
157
|
+
unless transfer_record_set.empty? then
|
158
|
+
record = transfer_record_set.first
|
159
|
+
log.info "Splash transfer : #{record[:name]}"
|
160
|
+
log.item "Description : /#{record[:desc]}/"
|
161
|
+
log.item "Type : #{record[:type].to_s}"
|
162
|
+
log.item "Backup file after copy : #{record[:backup].to_s}"
|
163
|
+
log.item "Local spool"
|
164
|
+
log.arrow "Path : #{record[:local][:path]}"
|
165
|
+
log.arrow "User : #{record[:local][:user]}"
|
166
|
+
log.item "Remote spool"
|
167
|
+
log.arrow "Path : #{record[:remote][:path]}"
|
168
|
+
log.arrow "User : #{record[:remote][:user]}"
|
169
|
+
log.arrow "Host : #{record[:remote][:host]}"
|
170
|
+
log.item "Post execution"
|
171
|
+
log.arrow "Remote command : #{record[:post][:remote_command]}" unless record[:post][:remote_command].nil?
|
172
|
+
log.arrow "Local command : #{record[:post][:local_command]}" unless record[:post][:local_command].nil?
|
173
|
+
splash_exit case: :quiet_exit
|
174
|
+
else
|
175
|
+
splash_exit case: :not_found, :more => "log not configured"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# Thor method : display the full list of Splash configured transfers
|
180
|
+
desc "list", "List all Splash configured transfers"
|
181
|
+
long_desc <<-LONGDESC
|
182
|
+
Show configured transfers\n
|
183
|
+
with --detail, show transfers details
|
184
|
+
LONGDESC
|
185
|
+
option :detail, :type => :boolean, :aliases => "-D"
|
186
|
+
def list
|
187
|
+
log = get_logger
|
188
|
+
log.info "Splash configured transfer :"
|
189
|
+
tx_record_set = get_config.transfers
|
190
|
+
log.ko 'No configured transfers found' if tx_record_set.empty?
|
191
|
+
tx_record_set.each do |record|
|
192
|
+
log.item "Transfer : #{record[:name]} Description : #{record[:desc]}"
|
193
|
+
if options[:detail] then
|
194
|
+
log.arrow "Type : #{record[:type].to_s}"
|
195
|
+
log.arrow "Backup file after copy : #{record[:backup].to_s}"
|
196
|
+
log.arrow "Local spool"
|
197
|
+
log.flat " * Path : #{record[:local][:path]}"
|
198
|
+
log.flat " * User : #{record[:local][:user]}"
|
199
|
+
log.arrow "Remote spool"
|
200
|
+
log.flat " * Path : #{record[:remote][:path]}"
|
201
|
+
log.flat " * User : #{record[:remote][:user]}"
|
202
|
+
log.flat " * Host : #{record[:remote][:host]}"
|
203
|
+
log.arrow "Post execution"
|
204
|
+
log.flat " * Remote command : #{record[:post][:remote_command]}" unless record[:post][:remote_command].nil?
|
205
|
+
log.flat " * Local command : #{record[:post][:local_command]}" unless record[:post][:local_command].nil?
|
206
|
+
end
|
207
|
+
end
|
208
|
+
splash_exit case: :quiet_exit
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
data/lib/splash/cli/webadmin.rb
CHANGED
@@ -14,14 +14,14 @@ module CLISplash
|
|
14
14
|
# Thor method : stopping Splash Webadmin
|
15
15
|
desc "stop", "Stopping Splash Webadmin Daemon"
|
16
16
|
def stop
|
17
|
-
acase = run_as_root :
|
17
|
+
acase = run_as_root :stopweb, options
|
18
18
|
splash_exit acase
|
19
19
|
end
|
20
20
|
|
21
21
|
# Thor method : getting execution status of Splashd
|
22
22
|
desc "status", "Splash WebAdmin Daemon status"
|
23
23
|
def status
|
24
|
-
acase = run_as_root :
|
24
|
+
acase = run_as_root :statusweb, options
|
25
25
|
splash_exit acase
|
26
26
|
end
|
27
27
|
|
@@ -37,7 +37,7 @@ module CLISplash
|
|
37
37
|
LONGDESC
|
38
38
|
desc "start", "Splash WebAdmin Daemon status"
|
39
39
|
def start
|
40
|
-
acase = run_as_root :
|
40
|
+
acase = run_as_root :startweb
|
41
41
|
splash_exit acase
|
42
42
|
end
|
43
43
|
|
data/lib/splash/commands.rb
CHANGED
@@ -6,6 +6,78 @@ 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
|
+
def purge(retention)
|
52
|
+
retention = {} if retention.nil?
|
53
|
+
if retention.include? :hours then
|
54
|
+
adjusted_datetime = DateTime.now - retention[:hours].to_f / 24
|
55
|
+
elsif retention.include? :hours then
|
56
|
+
adjusted_datetime = DateTime.now - retention[:days].to_i
|
57
|
+
else
|
58
|
+
adjusted_datetime = DateTime.now - DEFAULT_RETENTION
|
59
|
+
end
|
60
|
+
|
61
|
+
data = get_all_records
|
62
|
+
|
63
|
+
data.delete_if { |item|
|
64
|
+
DateTime.parse(item.keys.first) <= (adjusted_datetime)}
|
65
|
+
@backend.put key: @name, value: data.to_yaml
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_record(record)
|
69
|
+
data = get_all_records
|
70
|
+
data.push({ DateTime.now.to_s => record })
|
71
|
+
@backend.put key: @name, value: data.to_yaml
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_all_records(options={})
|
75
|
+
return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : []
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
9
81
|
# command execution wrapper
|
10
82
|
class CommandWrapper
|
11
83
|
include Splash::Templates
|
@@ -16,17 +88,13 @@ module Splash
|
|
16
88
|
include Splash::Transports
|
17
89
|
|
18
90
|
|
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)
|
91
|
+
|
24
92
|
|
25
93
|
# Constructor
|
26
94
|
# @param [String] name the name of the command
|
27
95
|
def initialize(name)
|
28
96
|
@config = get_config
|
29
|
-
@url =
|
97
|
+
@url = @config.prometheus_pushgateway_url
|
30
98
|
@name = name
|
31
99
|
unless @config.commands.keys.include? @name.to_sym then
|
32
100
|
splash_exit case: :not_found, more: "command #{@name} is not defined in configuration"
|
@@ -43,14 +111,17 @@ module Splash
|
|
43
111
|
# @param [String] value numeric.to_s
|
44
112
|
# @param [String] time execution time numeric.to_s
|
45
113
|
# @return [Hash] Exiter case :quiet_exit
|
46
|
-
def notify(value,time)
|
47
|
-
|
114
|
+
def notify(value,time, session)
|
115
|
+
log = get_logger
|
116
|
+
unless verify_service url: @config.prometheus_pushgateway_url then
|
48
117
|
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
|
49
118
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
119
|
+
cmdmonitor = CmdNotifier::new({name: @name, exitcode: value, time: time})
|
120
|
+
if cmdmonitor.notify then
|
121
|
+
log.ok "Sending metrics to Prometheus Pushgateway",session
|
122
|
+
else
|
123
|
+
log.ko "Failed to send metrics to Prometheus Pushgateway",session
|
124
|
+
end
|
54
125
|
return { :case => :quiet_exit}
|
55
126
|
end
|
56
127
|
|
@@ -84,6 +155,8 @@ module Splash
|
|
84
155
|
log.receive "return with exitcode #{exit_code}", session
|
85
156
|
|
86
157
|
end
|
158
|
+
rescue Interrupt
|
159
|
+
splash_exit case: :interrupt, more: "Remote command exection"
|
87
160
|
end
|
88
161
|
else
|
89
162
|
log.info "Executing command : '#{@name}' ", session
|
@@ -108,9 +181,6 @@ module Splash
|
|
108
181
|
stdout, stderr, status = Open3.capture3(@config.commands[@name.to_sym][:command])
|
109
182
|
end
|
110
183
|
time = Time.now - start
|
111
|
-
tp = Template::new(
|
112
|
-
list_token: @config.execution_template_tokens,
|
113
|
-
template_file: @config.execution_template_path)
|
114
184
|
data = Hash::new
|
115
185
|
data[:start_date] = start_date
|
116
186
|
data[:end_date] = DateTime.now.to_s
|
@@ -121,22 +191,19 @@ module Splash
|
|
121
191
|
data[:stdout] = stdout
|
122
192
|
data[:stderr] = stderr
|
123
193
|
data[:exec_time] = time.to_s
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
backend.put key: key, value: data.to_yaml
|
194
|
+
cmdrec = CmdRecords::new @name
|
195
|
+
cmdrec.purge(@config.commands[@name.to_sym][:retention])
|
196
|
+
cmdrec.add_record data
|
128
197
|
exit_code = status.exitstatus
|
129
198
|
end
|
130
199
|
log.ok "Command executed", session
|
131
200
|
log.arrow "exitcode #{exit_code}", session
|
132
201
|
if options[:notify] then
|
133
|
-
acase = notify(exit_code,time.to_i)
|
134
|
-
get_logger.ok "Prometheus Gateway notified.",session
|
202
|
+
acase = notify(exit_code,time.to_i,session)
|
135
203
|
else
|
136
204
|
log.item "Without Prometheus notification", session
|
137
205
|
end
|
138
206
|
end
|
139
|
-
|
140
207
|
if options[:callback] then
|
141
208
|
on_failure = (@config.commands[@name.to_sym][:on_failure])? @config.commands[@name.to_sym][:on_failure] : false
|
142
209
|
on_success = (@config.commands[@name.to_sym][:on_success])? @config.commands[@name.to_sym][:on_success] : false
|
data/lib/splash/config.rb
CHANGED
@@ -11,55 +11,124 @@ module Splash
|
|
11
11
|
include Splash::ConfigUtilities
|
12
12
|
|
13
13
|
|
14
|
+
class ConfigLinter
|
15
|
+
def initialize
|
16
|
+
@lints_present = {:logs => [:label, :log, :pattern ]}
|
17
|
+
@lints_types = {:logs => {:label => Symbol, :log => String, :pattern => String, :retention => Hash}}
|
18
|
+
end
|
19
|
+
|
20
|
+
def verify(options ={})
|
21
|
+
status = :success
|
22
|
+
missings = []
|
23
|
+
type_errors = []
|
24
|
+
useless = []
|
25
|
+
options[:record].each do |key,value|
|
26
|
+
useless.push key unless @lints_present[options[:type]].include? key or @lints_types[options[:type]].keys.include? key
|
27
|
+
type_errors.push key if @lints_types[options[:type]][key] != value.class and (@lints_present[options[:type]].include? key or @lints_types[options[:type]].keys.include? key)
|
28
|
+
end
|
29
|
+
@lints_present[options[:type]].each do |item|
|
30
|
+
missings.push item unless options[:record].keys.include? item
|
31
|
+
end
|
32
|
+
|
33
|
+
status = :failure if (missings.count > 0) or (type_errors.count > 0)
|
34
|
+
return {:missings => missings, :type_errors => type_errors, :useless => useless, :status => status}
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
14
39
|
# Class to manage configuration in Splash from Splash::Constants override by Yaml CONFIG
|
15
40
|
class Configuration < Hash
|
16
41
|
include Splash::Constants
|
17
42
|
|
43
|
+
attr_accessor :config_from_file
|
44
|
+
|
18
45
|
# constructor : read config file and map against Constants
|
19
46
|
def initialize(config_file=CONFIG_FILE)
|
20
|
-
|
47
|
+
@config_file = config_file
|
48
|
+
hash_config_to_default
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def hash_config_to_default
|
54
|
+
@config_from_file = readconf @config_file
|
21
55
|
self[:version] = VERSION
|
22
56
|
self[:author] = "#{AUTHOR} <#{EMAIL}>"
|
23
57
|
self[:copyright] = "#{COPYRIGHT} #{LICENSE}"
|
24
58
|
|
25
|
-
self[:prometheus_url] = (config_from_file[:prometheus][:url])? config_from_file[:prometheus][:url] : PROMETHEUS_URL
|
59
|
+
self[:prometheus_url] = (@config_from_file[:prometheus][:url])? @config_from_file[:prometheus][:url] : PROMETHEUS_URL
|
60
|
+
self[:prometheus_pushgateway_url] = (@config_from_file[:prometheus][:pushgateway])? @config_from_file[:prometheus][:pushgateway] : PROMETHEUS_PUSHGATEWAY_URL
|
61
|
+
self[:prometheus_alertmanager_url] = (@config_from_file[:prometheus][:alertmanager])? @config_from_file[:prometheus][:alertmanager] : PROMETHEUS_ALERTMANAGER_URL
|
26
62
|
|
27
|
-
self[:
|
28
|
-
self[:
|
29
|
-
self[:
|
30
|
-
self[:
|
31
|
-
self[:
|
32
|
-
self[:
|
33
|
-
self[:
|
63
|
+
self[:daemon_process_name] = (@config_from_file[:daemon][:process_name])? @config_from_file[:daemon][:process_name] : DAEMON_PROCESS_NAME
|
64
|
+
self[:daemon_logmon_scheduling] = (@config_from_file[:daemon][:logmon_scheduling])? @config_from_file[:daemon][:logmon_scheduling] : DAEMON_LOGMON_SCHEDULING
|
65
|
+
self[:daemon_metrics_scheduling] = (@config_from_file[:daemon][:metrics_scheduling])? @config_from_file[:daemon][:metrics_scheduling] : DAEMON_METRICS_SCHEDULING
|
66
|
+
self[:daemon_procmon_scheduling] = (@config_from_file[:daemon][:procmon_scheduling])? @config_from_file[:daemon][:procmon_scheduling] : DAEMON_PROCMON_SCHEDULING
|
67
|
+
self[:daemon_pid_file] = (@config_from_file[:daemon][:files][:pid_file])? @config_from_file[:daemon][:files][:pid_file] : DAEMON_PID_FILE
|
68
|
+
self[:daemon_stdout_trace] = (@config_from_file[:daemon][:files][:stdout_trace])? @config_from_file[:daemon][:files][:stdout_trace] : DAEMON_STDOUT_TRACE
|
69
|
+
self[:daemon_stderr_trace] = (@config_from_file[:daemon][:files][:stderr_trace])? @config_from_file[:daemon][:files][:stderr_trace] : DAEMON_STDERR_TRACE
|
34
70
|
|
35
71
|
|
36
|
-
self[:webadmin_port] = (config_from_file[:webadmin][:port])? config_from_file[:webadmin][:port] : WEBADMIN_PORT
|
37
|
-
self[:webadmin_ip] = (config_from_file[:webadmin][:ip])? config_from_file[:webadmin][:ip] : WEBADMIN_IP
|
38
|
-
self[:webadmin_proxy] = (config_from_file[:webadmin][:proxy])? config_from_file[:webadmin][:proxy] : WEBADMIN_PROXY
|
39
|
-
self[:webadmin_process_name] = (config_from_file[:webadmin][:process_name])? config_from_file[:webadmin][:process_name] : WEBADMIN_PROCESS_NAME
|
40
|
-
self[:webadmin_pid_file] = (config_from_file[:webadmin][:files][:pid_file])? config_from_file[:webadmin][:files][:pid_file] : WEBADMIN_PID_FILE
|
41
|
-
self[:webadmin_stdout_trace] = (config_from_file[:webadmin][:files][:stdout_trace])? config_from_file[:webadmin][:files][:stdout_trace] : WEBADMIN_STDOUT_TRACE
|
42
|
-
self[:webadmin_stderr_trace] = (config_from_file[:webadmin][:files][:stderr_trace])? config_from_file[:webadmin][:files][:stderr_trace] : WEBADMIN_STDERR_TRACE
|
72
|
+
self[:webadmin_port] = (@config_from_file[:webadmin][:port])? @config_from_file[:webadmin][:port] : WEBADMIN_PORT
|
73
|
+
self[:webadmin_ip] = (@config_from_file[:webadmin][:ip])? @config_from_file[:webadmin][:ip] : WEBADMIN_IP
|
74
|
+
self[:webadmin_proxy] = (@config_from_file[:webadmin][:proxy])? @config_from_file[:webadmin][:proxy] : WEBADMIN_PROXY
|
75
|
+
self[:webadmin_process_name] = (@config_from_file[:webadmin][:process_name])? @config_from_file[:webadmin][:process_name] : WEBADMIN_PROCESS_NAME
|
76
|
+
self[:webadmin_pid_file] = (@config_from_file[:webadmin][:files][:pid_file])? @config_from_file[:webadmin][:files][:pid_file] : WEBADMIN_PID_FILE
|
77
|
+
self[:webadmin_stdout_trace] = (@config_from_file[:webadmin][:files][:stdout_trace])? @config_from_file[:webadmin][:files][:stdout_trace] : WEBADMIN_STDOUT_TRACE
|
78
|
+
self[:webadmin_stderr_trace] = (@config_from_file[:webadmin][:files][:stderr_trace])? @config_from_file[:webadmin][:files][:stderr_trace] : WEBADMIN_STDERR_TRACE
|
79
|
+
|
80
|
+
|
81
|
+
self[:pid_path] = (@config_from_file[:paths][:pid_path])? @config_from_file[:paths][:pid_path] : PID_PATH
|
82
|
+
self[:trace_path] = (@config_from_file[:paths][:trace_path])? @config_from_file[:paths][:trace_path] : TRACE_PATH
|
43
83
|
|
44
84
|
|
45
85
|
self[:execution_template_tokens] = EXECUTION_TEMPLATE_TOKENS_LIST
|
46
|
-
self[:execution_template_path] = (config_from_file[:templates][:execution][:path])? config_from_file[:templates][:execution][:path] : EXECUTION_TEMPLATE
|
47
|
-
|
48
|
-
self[:
|
49
|
-
self[:
|
50
|
-
self[:
|
51
|
-
self[:stderr_trace] = (config_from_file[:daemon][:files][:stderr_trace])? config_from_file[:daemon][:files][:stderr_trace] : DAEMON_STDERR_TRACE
|
86
|
+
self[:execution_template_path] = (@config_from_file[:templates][:execution][:path])? @config_from_file[:templates][:execution][:path] : EXECUTION_TEMPLATE
|
87
|
+
|
88
|
+
self[:transports] = {} ; self[:transports].merge! TRANSPORTS_STRUCT ; self[:transports].merge! @config_from_file[:transports] if @config_from_file[:transports]
|
89
|
+
self[:backends] = {} ; self[:backends].merge! BACKENDS_STRUCT ; self[:backends].merge! @config_from_file[:backends] if @config_from_file[:backends]
|
90
|
+
self[:loggers] = {} ; self[:loggers].merge! LOGGERS_STRUCT ; self[:loggers].merge! @config_from_file[:loggers] if @config_from_file[:loggers]
|
52
91
|
|
53
|
-
self[:
|
54
|
-
self[:
|
55
|
-
self[:
|
92
|
+
self[:processes] = (@config_from_file[:processes])? @config_from_file[:processes] : {}
|
93
|
+
self[:logs] = (@config_from_file[:logs])? @config_from_file[:logs] : {}
|
94
|
+
self[:commands] = (@config_from_file[:commands])? @config_from_file[:commands] : {}
|
95
|
+
self[:sequences] = (@config_from_file[:sequences])? @config_from_file[:sequences] : {}
|
96
|
+
self[:transfers] = (@config_from_file[:transfers])? @config_from_file[:transfers] : {}
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def add_log(options = {})
|
101
|
+
@config_from_file = readconf @config_file
|
102
|
+
res = ConfigLinter::new.verify(options)
|
103
|
+
if res[:status] == :success then
|
104
|
+
if @config_from_file[:logs].select{|item| item[:label] == options[:record][:label]}.count > 0 then
|
105
|
+
return {:status => :already_exist}
|
106
|
+
else
|
107
|
+
res[:useless].each {|item| options[:record].delete item} if options[:clean]
|
108
|
+
@config_from_file[:logs].push options[:record]
|
109
|
+
writeconf
|
110
|
+
hash_config_to_default
|
111
|
+
return {:status => :success}
|
112
|
+
end
|
113
|
+
else
|
114
|
+
return res
|
115
|
+
end
|
116
|
+
end
|
56
117
|
|
57
|
-
self[:processes] = (config_from_file[:processes])? config_from_file[:processes] : {}
|
58
|
-
self[:logs] = (config_from_file[:logs])? config_from_file[:logs] : {}
|
59
|
-
self[:commands] = (config_from_file[:commands])? config_from_file[:commands] : {}
|
60
118
|
|
119
|
+
def delete_log(options = {})
|
120
|
+
@config_from_file = readconf @config_file
|
121
|
+
unless @config_from_file[:logs].select{|item| item[:label] == options[:label]}.count > 0 then
|
122
|
+
return {:status => :not_found}
|
123
|
+
else
|
124
|
+
@config_from_file[:logs].delete_if {|value| options[:label] == value[:label] }
|
125
|
+
writeconf
|
126
|
+
hash_config_to_default
|
127
|
+
return {:status => :success}
|
128
|
+
end
|
61
129
|
end
|
62
130
|
|
131
|
+
|
63
132
|
# @!group accessors on configurations Items
|
64
133
|
|
65
134
|
# getter for full Config Hash
|
@@ -86,6 +155,12 @@ module Splash
|
|
86
155
|
return self[:transports]
|
87
156
|
end
|
88
157
|
|
158
|
+
# getter for transfers Hash Config sample
|
159
|
+
# @return [Hash]
|
160
|
+
def transfers
|
161
|
+
return self[:transfers]
|
162
|
+
end
|
163
|
+
|
89
164
|
# getter for daemon_logmon_scheduling Hash Config sample
|
90
165
|
# @return [Hash]
|
91
166
|
def daemon_logmon_scheduling
|
@@ -104,6 +179,31 @@ module Splash
|
|
104
179
|
return self[:daemon_metrics_scheduling]
|
105
180
|
end
|
106
181
|
|
182
|
+
# getter for daemon_process_name Config sample
|
183
|
+
# @return [String]
|
184
|
+
def daemon_process_name
|
185
|
+
return self[:daemon_process_name]
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
# getter for daemon_full_pid_path Config sample
|
190
|
+
# @return [String]
|
191
|
+
def daemon_full_pid_path
|
192
|
+
return "#{self[:pid_path]}/#{self[:daemon_pid_file]}"
|
193
|
+
end
|
194
|
+
|
195
|
+
# getter for daemon_full_stdout_trace_path Config sample
|
196
|
+
# @return [String]
|
197
|
+
def daemon_full_stdout_trace_path
|
198
|
+
return "#{self[:trace_path]}/#{self[:daemon_stdout_trace]}"
|
199
|
+
end
|
200
|
+
|
201
|
+
# getter for daemon_full_stderr_trace_path Config sample
|
202
|
+
# @return [String]
|
203
|
+
def daemon_full_stderr_trace_path
|
204
|
+
return "#{self[:trace_path]}/#{self[:daemon_stderr_trace]}"
|
205
|
+
end
|
206
|
+
|
107
207
|
# getter for execution_template_path Hash Config sample
|
108
208
|
# @return [String]
|
109
209
|
def execution_template_path
|
@@ -180,6 +280,11 @@ module Splash
|
|
180
280
|
return self[:processes]
|
181
281
|
end
|
182
282
|
|
283
|
+
# getter for sequences Hash Config sample
|
284
|
+
# @return [Hash]
|
285
|
+
def sequences
|
286
|
+
return self[:sequences]
|
287
|
+
end
|
183
288
|
|
184
289
|
# getter for author Config sample
|
185
290
|
# @return [String]
|
@@ -202,29 +307,19 @@ module Splash
|
|
202
307
|
|
203
308
|
|
204
309
|
|
205
|
-
# getter for daemon_process_name Config sample
|
206
|
-
# @return [String]
|
207
|
-
def daemon_process_name
|
208
|
-
return self[:daemon_process_name]
|
209
|
-
end
|
210
310
|
|
211
|
-
# getter for
|
311
|
+
# getter for prometheus_pushgateway_url Config sample
|
212
312
|
# @return [String]
|
213
|
-
def
|
214
|
-
return self[:
|
313
|
+
def prometheus_pushgateway_url
|
314
|
+
return self[:prometheus_pushgateway_url]
|
215
315
|
end
|
216
316
|
|
217
|
-
# getter for
|
317
|
+
# getter for prometheus_alertmanager_url Config sample
|
218
318
|
# @return [String]
|
219
|
-
def
|
220
|
-
return self[:
|
319
|
+
def prometheus_alertmanager_url
|
320
|
+
return self[:prometheus_alertmanager_url]
|
221
321
|
end
|
222
322
|
|
223
|
-
# getter for prometheus_pushgateway_path Config sample
|
224
|
-
# @return [String]
|
225
|
-
def prometheus_pushgateway_path
|
226
|
-
return self[:prometheus_pushgateway_path]
|
227
|
-
end
|
228
323
|
|
229
324
|
# getter for prometheus_url Config sample
|
230
325
|
# @return [String]
|
@@ -232,24 +327,6 @@ module Splash
|
|
232
327
|
return self[:prometheus_url]
|
233
328
|
end
|
234
329
|
|
235
|
-
# getter for full_pid_path Config sample
|
236
|
-
# @return [String]
|
237
|
-
def full_pid_path
|
238
|
-
return "#{self[:pid_path]}/#{self[:pid_file]}"
|
239
|
-
end
|
240
|
-
|
241
|
-
# getter for full_stdout_trace_path Config sample
|
242
|
-
# @return [String]
|
243
|
-
def full_stdout_trace_path
|
244
|
-
return "#{self[:trace_path]}/#{self[:stdout_trace]}"
|
245
|
-
end
|
246
|
-
|
247
|
-
# getter for full_stderr_trace_path Config sample
|
248
|
-
# @return [String]
|
249
|
-
def full_stderr_trace_path
|
250
|
-
return "#{self[:trace_path]}/#{self[:stderr_trace]}"
|
251
|
-
end
|
252
|
-
|
253
330
|
# @!endgroup
|
254
331
|
|
255
332
|
private
|
@@ -261,6 +338,16 @@ module Splash
|
|
261
338
|
return YAML.load_file(file)[:splash]
|
262
339
|
end
|
263
340
|
|
341
|
+
# write config to file from @config_from_file
|
342
|
+
# @param [String] file default from CONFIG_FILE
|
343
|
+
# @return [Bool] if ok
|
344
|
+
def writeconf(file = CONFIG_FILE)
|
345
|
+
File.open(file,"w") do |f|
|
346
|
+
data = {}
|
347
|
+
data[:splash] = @config_from_file
|
348
|
+
f.write(data.to_yaml)
|
349
|
+
end
|
350
|
+
end
|
264
351
|
|
265
352
|
end
|
266
353
|
|