prometheus-splash 0.7.0 → 0.8.4
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 +61 -1
- data/README.md +400 -178
- data/config/splash.yml +45 -5
- data/lib/splash/backends.rb +8 -1
- data/lib/splash/backends/file.rb +1 -1
- data/lib/splash/cli.rb +2 -1
- data/lib/splash/cli/commands.rb +100 -16
- data/lib/splash/cli/config.rb +12 -1
- data/lib/splash/cli/daemon.rb +41 -1
- data/lib/splash/cli/logs.rb +144 -48
- data/lib/splash/cli/process.rb +145 -52
- data/lib/splash/cli/transfers.rb +213 -0
- data/lib/splash/cli/webadmin.rb +3 -3
- data/lib/splash/commands.rb +85 -19
- data/lib/splash/config.rb +145 -52
- data/lib/splash/config/flush.rb +2 -2
- data/lib/splash/constants.rb +7 -3
- data/lib/splash/daemon/metrics.rb +6 -6
- data/lib/splash/daemon/orchestrator.rb +76 -36
- data/lib/splash/daemon/orchestrator/grammar.rb +16 -1
- data/lib/splash/dependencies.rb +6 -1
- data/lib/splash/exiter.rb +1 -1
- data/lib/splash/helpers.rb +12 -3
- data/lib/splash/loggers/cli.rb +2 -10
- data/lib/splash/logs.rb +94 -16
- data/lib/splash/processes.rb +91 -16
- data/lib/splash/transfers.rb +229 -0
- data/lib/splash/webadmin.rb +3 -3
- data/lib/splash/webadmin/api/routes/commands.rb +2 -2
- data/lib/splash/webadmin/api/routes/config.rb +95 -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 +3 -0
- data/lib/splash/webadmin/portal/controllers/commands.rb +2 -0
- data/lib/splash/webadmin/portal/controllers/documentation.rb +2 -0
- data/lib/splash/webadmin/portal/controllers/home.rb +24 -0
- data/lib/splash/webadmin/portal/controllers/logs.rb +57 -1
- data/lib/splash/webadmin/portal/controllers/processes.rb +61 -3
- data/lib/splash/webadmin/portal/controllers/proxy.rb +12 -3
- 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/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/log_form.slim +24 -0
- data/lib/splash/webadmin/portal/views/log_history.slim +24 -0
- data/lib/splash/webadmin/portal/views/logs.slim +93 -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 +21 -0
- data/lib/splash/webadmin/portal/views/process_history.slim +24 -0
- data/lib/splash/webadmin/portal/views/processes.slim +73 -3
- 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 +1 -1
- data/prometheus-splash.gemspec +7 -4
- data/ultragreen_roodi_coding_convention.yml +4 -4
- metadata +71 -8
data/lib/splash/processes.rb
CHANGED
@@ -6,6 +6,85 @@ module Splash
|
|
6
6
|
# Processes namespace
|
7
7
|
module Processes
|
8
8
|
|
9
|
+
|
10
|
+
class ProcessNotifier
|
11
|
+
|
12
|
+
@@registry = Prometheus::Client::Registry::new
|
13
|
+
@@metric_status = Prometheus::Client::Gauge.new(:process_status, docstring: 'SPLASH metric process status', labels: [:process ])
|
14
|
+
@@metric_cpu_percent = Prometheus::Client::Gauge.new(:process_cpu_percent, docstring: 'SPLASH metric process CPU usage in percent', labels: [:process ])
|
15
|
+
@@metric_mem_percent = Prometheus::Client::Gauge.new(:process_mem_percent, docstring: 'SPLASH metric process MEM usage in percent', labels: [:process ])
|
16
|
+
@@registry.register(@@metric_status)
|
17
|
+
@@registry.register(@@metric_cpu_percent)
|
18
|
+
@@registry.register(@@metric_mem_percent)
|
19
|
+
|
20
|
+
|
21
|
+
def initialize(options={})
|
22
|
+
@config = get_config
|
23
|
+
@url = @config.prometheus_pushgateway_url
|
24
|
+
@name = options[:name]
|
25
|
+
@status = options[:status]
|
26
|
+
@cpu_percent = options[:cpu_percent]
|
27
|
+
@mem_percent = options[:mem_percent]
|
28
|
+
end
|
29
|
+
|
30
|
+
# send metrics to Prometheus PushGateway
|
31
|
+
# @return [Bool]
|
32
|
+
def notify
|
33
|
+
unless verify_service url: @url then
|
34
|
+
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
|
35
|
+
end
|
36
|
+
@@metric_mem_percent.set(@mem_percent, labels: { process: @name })
|
37
|
+
@@metric_cpu_percent.set(@cpu_percent, labels: { process: @name })
|
38
|
+
@@metric_status.set(@status, labels: { process: @name })
|
39
|
+
hostname = Socket.gethostname
|
40
|
+
return Prometheus::Client::Push.new("Splash", hostname, @url).add(@@registry)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
class ProcessRecords
|
47
|
+
include Splash::Backends
|
48
|
+
include Splash::Constants
|
49
|
+
|
50
|
+
def initialize(name)
|
51
|
+
@name = name
|
52
|
+
@backend = get_backend :process_trace
|
53
|
+
end
|
54
|
+
|
55
|
+
def clear
|
56
|
+
@backend.del({:key => @name}) if @backend.exist?({key: @name})
|
57
|
+
end
|
58
|
+
|
59
|
+
def purge(retention)
|
60
|
+
retention = {} if retention.nil?
|
61
|
+
if retention.include? :hours then
|
62
|
+
adjusted_datetime = DateTime.now - retention[:hours].to_f / 24
|
63
|
+
elsif retention.include? :hours then
|
64
|
+
adjusted_datetime = DateTime.now - retention[:days].to_i
|
65
|
+
else
|
66
|
+
adjusted_datetime = DateTime.now - DEFAULT_RETENTION
|
67
|
+
end
|
68
|
+
|
69
|
+
data = get_all_records
|
70
|
+
|
71
|
+
data.delete_if { |item|
|
72
|
+
DateTime.parse(item.keys.first) <= (adjusted_datetime)}
|
73
|
+
@backend.put key: @name, value: data.to_yaml
|
74
|
+
end
|
75
|
+
|
76
|
+
def add_record(record)
|
77
|
+
data = get_all_records
|
78
|
+
data.push({ DateTime.now.to_s => record })
|
79
|
+
@backend.put key: @name, value: data.to_yaml
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_all_records(options={})
|
83
|
+
return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : []
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
9
88
|
# Processes scanner and notifier
|
10
89
|
class ProcessScanner
|
11
90
|
include Splash::Constants
|
@@ -17,14 +96,6 @@ module Splash
|
|
17
96
|
def initialize
|
18
97
|
@processes_target = Marshal.load(Marshal.dump(get_config.processes))
|
19
98
|
@config = get_config
|
20
|
-
@registry = Prometheus::Client::Registry::new
|
21
|
-
@metric_status = Prometheus::Client::Gauge.new(:process_status, docstring: 'SPLASH metric process status', labels: [:process ])
|
22
|
-
@metric_cpu_percent = Prometheus::Client::Gauge.new(:process_cpu_percent, docstring: 'SPLASH metric process CPU usage in percent', labels: [:process ])
|
23
|
-
@metric_mem_percent = Prometheus::Client::Gauge.new(:process_mem_percent, docstring: 'SPLASH metric process MEM usage in percent', labels: [:process ])
|
24
|
-
@registry.register(@metric_status)
|
25
|
-
@registry.register(@metric_cpu_percent)
|
26
|
-
@registry.register(@metric_mem_percent)
|
27
|
-
|
28
99
|
end
|
29
100
|
|
30
101
|
|
@@ -64,17 +135,21 @@ module Splash
|
|
64
135
|
session = (options[:session]) ? options[:session] : log.get_session
|
65
136
|
log.info "Sending metrics to Prometheus Pushgateway", session
|
66
137
|
@processes_target.each do |item|
|
138
|
+
processrec = ProcessRecords::new item[:process]
|
67
139
|
missing = (item[:status] == :missing)? 1 : 0
|
68
|
-
log.item "Sending metrics for #{item[:process]}", session
|
69
140
|
val = (item[:status] == :running )? 1 : 0
|
70
|
-
|
71
|
-
|
72
|
-
|
141
|
+
processrec.purge(item[:retention])
|
142
|
+
processrec.add_record :status => item[:status],
|
143
|
+
:cpu_percent => item[:cpu],
|
144
|
+
:mem_percent => item[:mem] ,
|
145
|
+
:process => item[:process]
|
146
|
+
processmonitor = ProcessNotifier::new({name: item[:process], status: val , cpu_percent: item[:cpu], mem_percent: item[:mem]})
|
147
|
+
if processmonitor.notify then
|
148
|
+
log.ok "Sending metrics for process #{item[:process]} to Prometheus Pushgateway", session
|
149
|
+
else
|
150
|
+
log.ko "Failed to send metrics for process #{item[:process]} to Prometheus Pushgateway", session
|
151
|
+
end
|
73
152
|
end
|
74
|
-
hostname = Socket.gethostname
|
75
|
-
url = @config.prometheus_pushgateway_url
|
76
|
-
Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
|
77
|
-
log.ok "Sending to Prometheus PushGateway done.", session
|
78
153
|
return {:case => :quiet_exit }
|
79
154
|
end
|
80
155
|
|
@@ -0,0 +1,229 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash Module
|
4
|
+
module Splash
|
5
|
+
|
6
|
+
# Transfers module
|
7
|
+
module Transfers
|
8
|
+
|
9
|
+
include Splash::Config
|
10
|
+
include Splash::Loggers
|
11
|
+
include Splash::Helpers
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
class TxNotifier
|
16
|
+
@@registry = Prometheus::Client::Registry::new
|
17
|
+
@@metric_nbfiles = Prometheus::Client::Gauge.new(:txnbfiles, docstring: 'SPLASH metric transfer number of files')
|
18
|
+
@@metric_nbfiles_failed = Prometheus::Client::Gauge.new(:txnbfilesfailed, docstring: 'SPLASH metric transfer number of failed files')
|
19
|
+
@@metric_time = Prometheus::Client::Gauge.new(:txtime, docstring: 'SPLASH metric transfer execution time')
|
20
|
+
@@registry.register(@@metric_nbfiles)
|
21
|
+
@@registry.register(@@metric_nbfiles_failed)
|
22
|
+
@@registry.register(@@metric_time)
|
23
|
+
|
24
|
+
def initialize(options={})
|
25
|
+
@config = get_config
|
26
|
+
@url = @config.prometheus_pushgateway_url
|
27
|
+
@name = "tx_#{options[:name].to_s}"
|
28
|
+
@nbfiles = options[:nbfiles]
|
29
|
+
@nbfiles_failed = options[:nbfiles_failed]
|
30
|
+
@time = options[:time]
|
31
|
+
end
|
32
|
+
|
33
|
+
# send metrics to Prometheus PushGateway
|
34
|
+
# @return [Bool]
|
35
|
+
def notify
|
36
|
+
unless verify_service url: @url then
|
37
|
+
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
|
38
|
+
end
|
39
|
+
@@metric_nbfiles.set(@nbfiles)
|
40
|
+
@@metric_nbfiles_failed.set(@nbfiles_failed)
|
41
|
+
@@metric_time.set(@time)
|
42
|
+
hostname = Socket.gethostname
|
43
|
+
return Prometheus::Client::Push.new(@name, hostname, @url).add(@@registry)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
class TxRecords
|
51
|
+
include Splash::Backends
|
52
|
+
include Splash::Constants
|
53
|
+
|
54
|
+
def initialize(name)
|
55
|
+
@name = name
|
56
|
+
@backend = get_backend :transfers_trace
|
57
|
+
end
|
58
|
+
|
59
|
+
def purge(retention)
|
60
|
+
retention = {} if retention.nil?
|
61
|
+
if retention.include? :hours then
|
62
|
+
adjusted_datetime = DateTime.now - retention[:hours].to_f / 24
|
63
|
+
elsif retention.include? :hours then
|
64
|
+
adjusted_datetime = DateTime.now - retention[:days].to_i
|
65
|
+
else
|
66
|
+
adjusted_datetime = DateTime.now - DEFAULT_RETENTION
|
67
|
+
end
|
68
|
+
|
69
|
+
data = get_all_records
|
70
|
+
|
71
|
+
data.delete_if { |item|
|
72
|
+
DateTime.parse(item.keys.first) <= (adjusted_datetime)}
|
73
|
+
@backend.put key: @name, value: data.to_yaml
|
74
|
+
end
|
75
|
+
|
76
|
+
def add_record(record)
|
77
|
+
data = get_all_records
|
78
|
+
data.push({ DateTime.now.to_s => record })
|
79
|
+
@backend.put key: @name, value: data.to_yaml
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_all_records(options={})
|
83
|
+
return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : []
|
84
|
+
end
|
85
|
+
|
86
|
+
def check_prepared
|
87
|
+
return :never_run_prepare unless @backend.exist?({key: @name})
|
88
|
+
return :never_prepare unless YAML::load(@backend.get({key: @name})).select {|item|
|
89
|
+
record =item.keys.first
|
90
|
+
value=item[record]
|
91
|
+
value[:status] == :prepared
|
92
|
+
}.count > 0
|
93
|
+
return :prepared
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
def run_txs(options = {})
|
99
|
+
log = get_logger
|
100
|
+
log.info 'Running Transfers'
|
101
|
+
count=0
|
102
|
+
get_config.transfers.each do |record|
|
103
|
+
txrec = TxRecords::new record[:name]
|
104
|
+
txrec.purge(record[:retention])
|
105
|
+
log.item "Execute : #{record[:name]}, #{record[:desc]}"
|
106
|
+
case txrec.check_prepared
|
107
|
+
when :prepared
|
108
|
+
if record[:type] == :push then
|
109
|
+
unless push record
|
110
|
+
count += 1
|
111
|
+
end
|
112
|
+
elsif record[:type] == :pull then
|
113
|
+
unless pull record
|
114
|
+
count += 1
|
115
|
+
end
|
116
|
+
else
|
117
|
+
log.ko "Transfer type unkown"
|
118
|
+
count += 1
|
119
|
+
end
|
120
|
+
when :never_prepare
|
121
|
+
log.ko "#{record[:name]} : Never prepared, ignored"
|
122
|
+
txrec.add_record :status => :never_prepared
|
123
|
+
count += 1
|
124
|
+
when :never_run_prepare
|
125
|
+
log.ko "#{record[:name]} : Never Executed and never prepared, ignored"
|
126
|
+
txrec.add_record :status => :never_prepared
|
127
|
+
count += 1
|
128
|
+
end
|
129
|
+
end
|
130
|
+
return {:case => :error_exit, :more => "#{count} Transfer(s) failed"} if count > 0
|
131
|
+
return {:case => :quiet_exit }
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
def prepare_tx(name)
|
137
|
+
log = get_logger
|
138
|
+
record = get_config.transfers.select { |item| item[:name] == name.to_sym }.first
|
139
|
+
home = Etc.getpwnam(record[:local][:user]).dir
|
140
|
+
identity = ::File::readlines("#{home}/.ssh/id_rsa.pub").first.chomp
|
141
|
+
folder = {:mode => "755",
|
142
|
+
:owner => record[:local][:user] ,
|
143
|
+
:group => Etc.getgrgid(Etc.getpwnam(record[:local][:user]).gid).name,
|
144
|
+
:name => record[:local][:path],
|
145
|
+
:path => record[:local][:path]}
|
146
|
+
log.info "Ensure local folder : #{record[:local][:path]}"
|
147
|
+
make_folder(folder) unless verify_folder(folder).empty?
|
148
|
+
begin
|
149
|
+
log.info "Ensure RSA Key sharing for local user : #{record[:local][:user]} to remote user : #{record[:remote][:user]}@#{record[:remote][:host]}"
|
150
|
+
ssh = Net::SSH.start(record[:remote][:host],record[:remote][:user])
|
151
|
+
output = ssh.exec!(%[
|
152
|
+
/bin/bash -cl '
|
153
|
+
umask 077;
|
154
|
+
mkdir #{record[:remote][:path]};
|
155
|
+
test -d ~/.ssh || mkdir ~/.ssh;
|
156
|
+
if [ ! -f ~/.ssh/authorized_keys -o `grep "#{identity}" ~/.ssh/authorized_keys 2> /dev/null | wc -l` -eq 0 ]; then echo "#{identity}" >> ~/.ssh/authorized_keys
|
157
|
+
fi'])
|
158
|
+
log.info "Prepare remote folder : #{record[:remote][:path]}"
|
159
|
+
log.info "Prepare data file for transfer : #{record[:name]}"
|
160
|
+
txrec = TxRecords::new record[:name]
|
161
|
+
txrec.add_record :status => :prepared
|
162
|
+
log.ok "Transfer : #{record[:name]} prepared successfully"
|
163
|
+
return {:case => :quiet_exit }
|
164
|
+
rescue Interrupt
|
165
|
+
splash_exit case: :interrupt, more: "Remote command exection"
|
166
|
+
rescue TTY::Reader::InputInterrupt
|
167
|
+
splash_exit case: :interrupt, more: "Remote command exection"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
def save_data
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
def push(record)
|
180
|
+
config = get_config
|
181
|
+
log = get_logger
|
182
|
+
txrec = TxRecords::new record[:name]
|
183
|
+
start = Time.now
|
184
|
+
res = true
|
185
|
+
count = 0
|
186
|
+
done =[]
|
187
|
+
start_date = DateTime.now.to_s
|
188
|
+
list = Dir.glob("#{record[:local][:path]}/#{record[:pattern]}")
|
189
|
+
count = list.count
|
190
|
+
log.arrow "Transfering #{count} file(s)"
|
191
|
+
|
192
|
+
begin
|
193
|
+
scp = Net::SCP.start(record[:remote][:host],record[:remote][:user])
|
194
|
+
list.each do|f|
|
195
|
+
log.arrow "Copy file : #{f} to #{record[:remote][:user]}@#{record[:remote][:host]}:#{record[:remote][:path]}"
|
196
|
+
scp.upload! f, record[:remote][:path]
|
197
|
+
done.push f
|
198
|
+
if record[:backup] then
|
199
|
+
log.arrow "File #{f} backuped"
|
200
|
+
FileUtils::mv(f, "#{f}.#{Time.now.getutc.to_i}")
|
201
|
+
else
|
202
|
+
FileUtils::unlink(f)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
rescue
|
207
|
+
res = false
|
208
|
+
end
|
209
|
+
|
210
|
+
end_date = DateTime.now.to_s
|
211
|
+
time = Time.now - start
|
212
|
+
status = (res)? :success : :failure
|
213
|
+
txrec.add_record :status => status,
|
214
|
+
:end_date => end_date,
|
215
|
+
:time => time,
|
216
|
+
:count => count,
|
217
|
+
:wanted => list,
|
218
|
+
:done => done
|
219
|
+
count_failed = list.count - done.count
|
220
|
+
txmonitor = TxNotifier::new({name: record[:name], nbfiles: count,nbfiles_failed: count_failed, time: time})
|
221
|
+
if txmonitor.notify then
|
222
|
+
log.ok "Sending metrics to Prometheus Pushgateway"
|
223
|
+
else
|
224
|
+
log.ko "Failed to send metrics to Prometheus Pushgateway"
|
225
|
+
end
|
226
|
+
return res
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
data/lib/splash/webadmin.rb
CHANGED
@@ -21,7 +21,7 @@ module Splash
|
|
21
21
|
# @param [Hash] options
|
22
22
|
# @option options [Symbol] :quiet activate quiet mode for log (limit to :fatal)
|
23
23
|
# @return [Hash] Exiter Case (:quiet_exit, :already_exist, :unknown_error or other)
|
24
|
-
def
|
24
|
+
def startweb(options = {})
|
25
25
|
require 'splash/webadmin/main'
|
26
26
|
config = get_config
|
27
27
|
log = get_logger
|
@@ -64,7 +64,7 @@ module Splash
|
|
64
64
|
# @param [Hash] options
|
65
65
|
# @option options [Symbol] :quiet activate quiet mode for log (limit to :fatal)
|
66
66
|
# @return [Hash] Exiter Case (:quiet_exit, :not_found, other)
|
67
|
-
def
|
67
|
+
def stopweb(options = {})
|
68
68
|
config = get_config
|
69
69
|
log = get_logger
|
70
70
|
log.level = :fatal if options[:quiet]
|
@@ -86,7 +86,7 @@ module Splash
|
|
86
86
|
# Status of the Splash WebAdmin, display status
|
87
87
|
# @param [Hash] options ignored
|
88
88
|
# @return [Hash] Exiter Case (:status_ko, :status_ok)
|
89
|
-
def
|
89
|
+
def statusweb(options = {})
|
90
90
|
log = get_logger
|
91
91
|
config = get_config
|
92
92
|
pid = realpid = ''
|
@@ -5,7 +5,7 @@
|
|
5
5
|
WebAdminApp.get '/api/commands/list.?:format?' do
|
6
6
|
log = get_logger
|
7
7
|
format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
|
8
|
-
log.call "
|
8
|
+
log.call "API : commands, verb : GET, route : list, format : #{format}"
|
9
9
|
obj = splash_return case: :quiet_exit, :more => "Commands list"
|
10
10
|
obj[:data] = get_config.commands
|
11
11
|
content_type format
|
@@ -15,7 +15,7 @@ WebAdminApp.get '/api/commands/list.?:format?' do
|
|
15
15
|
WebAdminApp.get '/api/commands/show/:name.?:format?' do
|
16
16
|
log = get_logger
|
17
17
|
format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
|
18
|
-
log.call "
|
18
|
+
log.call "API : commands, verb : GET, route : show, item : #{params[:name]} , format : #{format}"
|
19
19
|
commands_recordset = get_config.commands[params[:name].to_sym]
|
20
20
|
unless commands_recordset.nil? then
|
21
21
|
obj = splash_return case: :quiet_exit
|
@@ -1,10 +1,103 @@
|
|
1
1
|
WebAdminApp.get '/api/config/full.?:format?' do
|
2
2
|
log = get_logger
|
3
3
|
format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
|
4
|
-
log.call "
|
4
|
+
log.call "API : config, verb : GET, route : full, format : #{format}"
|
5
5
|
config = get_config.full
|
6
|
-
obj = splash_return case: :quiet_exit, :more => "
|
6
|
+
obj = splash_return case: :quiet_exit, :more => "Show internal Splash Config"
|
7
7
|
obj[:data] = config
|
8
8
|
content_type format
|
9
9
|
format_response(obj, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
|
10
10
|
end
|
11
|
+
|
12
|
+
WebAdminApp.get '/api/config/fromfile.?:format?' do
|
13
|
+
log = get_logger
|
14
|
+
fromfile = {}
|
15
|
+
format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
|
16
|
+
log.call "API : config, verb : GET, route : fromfile, format : #{format}"
|
17
|
+
config = get_config.config_from_file
|
18
|
+
fromfile = splash_return case: :quiet_exit, :more => "Show config from file"
|
19
|
+
fromfile[:data] = config
|
20
|
+
content_type format
|
21
|
+
format_response(fromfile, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
WebAdminApp.post '/api/config/addlog.?:format?' do
|
26
|
+
log = get_logger
|
27
|
+
addlog = {}
|
28
|
+
format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
|
29
|
+
log.call "API : config, verb : POST, route : addlog, format : #{format}"
|
30
|
+
res = get_config.add_record :record => YAML::load(request.body.read), :key => :label, :type => :logs, :clean => true
|
31
|
+
case res[:status]
|
32
|
+
when :success
|
33
|
+
addlog = splash_return case: :quiet_exit, :more => "add log done"
|
34
|
+
when :already_exist
|
35
|
+
addlog = splash_return case: :already_exist, :more => "add log twice nto allowed"
|
36
|
+
when :failure
|
37
|
+
addlog = splash_return case: :configuration_error, :more => "add log failed"
|
38
|
+
addlog[:data] = res
|
39
|
+
end
|
40
|
+
content_type format
|
41
|
+
format_response(addlog, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
|
42
|
+
end
|
43
|
+
|
44
|
+
WebAdminApp.post '/api/config/addprocess.?:format?' do
|
45
|
+
log = get_logger
|
46
|
+
addprocess = {}
|
47
|
+
format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
|
48
|
+
log.call "API : config, verb : POST, route : addprocess, format : #{format}"
|
49
|
+
res = get_config.add_record :record => YAML::load(request.body.read), :type => :processes, :key => :process, :clean => true
|
50
|
+
case res[:status]
|
51
|
+
when :success
|
52
|
+
addprocess = splash_return case: :quiet_exit, :more => "add process done"
|
53
|
+
when :already_exist
|
54
|
+
addprocess = splash_return case: :already_exist, :more => "add process twice not allowed"
|
55
|
+
when :failure
|
56
|
+
addprocess = splash_return case: :configuration_error, :more => "add process failed"
|
57
|
+
addprocess[:data] = res
|
58
|
+
end
|
59
|
+
content_type format
|
60
|
+
format_response(addprocess, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
WebAdminApp.delete '/api/config/deletelog/:label.?:format?' do
|
66
|
+
log = get_logger
|
67
|
+
format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
|
68
|
+
log.call "API : config, verb : DELETE, route : deletelog, format : #{format}"
|
69
|
+
deletelog = {}
|
70
|
+
logsrec = Splash::Logs::LogsRecords::new params[:label].to_sym
|
71
|
+
logsrec.clear
|
72
|
+
res = get_config.delete_record :type => :logs, key: :label, label: params[:label].to_sym
|
73
|
+
case res[:status]
|
74
|
+
when :success
|
75
|
+
deletelog = splash_return case: :quiet_exit, :more => "delete log done"
|
76
|
+
when :not_found
|
77
|
+
deletelog = splash_return case: :not_found, :more => "nothing done for logs"
|
78
|
+
else
|
79
|
+
deletelog = splash_return case: :configuration_error, :more => "delete log failed"
|
80
|
+
end
|
81
|
+
content_type format
|
82
|
+
format_response(deletelog, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
|
83
|
+
end
|
84
|
+
|
85
|
+
WebAdminApp.delete '/api/config/deleteprocess/:process.?:format?' do
|
86
|
+
log = get_logger
|
87
|
+
format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
|
88
|
+
log.call "API : config, verb : DELETE, route : deleteprocess, format : #{format}"
|
89
|
+
deleteprocess = {}
|
90
|
+
procrec = Splash::Processes::ProcessRecords::new params[:process].to_sym
|
91
|
+
procrec.clear
|
92
|
+
res = get_config.delete_record :type => :processes, :key => :process, process: params[:process].to_sym
|
93
|
+
case res[:status]
|
94
|
+
when :success
|
95
|
+
deleteprocess = splash_return case: :quiet_exit, :more => "delete process done"
|
96
|
+
when :not_found
|
97
|
+
deleteprocess = splash_return case: :not_found, :more => "nothing done for processes"
|
98
|
+
else
|
99
|
+
deleteprocess = splash_return case: :configuration_error, :more => "delete process failed"
|
100
|
+
end
|
101
|
+
content_type format
|
102
|
+
format_response(deleteprocess, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
|
103
|
+
end
|