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/config/splash.yml
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
:splash:
|
3
3
|
|
4
4
|
### Main Configuration
|
5
|
+
:paths:
|
6
|
+
:pid_path: /var/run/splash
|
7
|
+
:trace_path: /var/run/splash/traces
|
5
8
|
:loggers:
|
6
9
|
:level: :info
|
7
10
|
:daemon:
|
@@ -23,6 +26,16 @@
|
|
23
26
|
# :port: 6379
|
24
27
|
# #:auth: "mykey"
|
25
28
|
# :base: 1
|
29
|
+
:transfers_trace:
|
30
|
+
:type: :file
|
31
|
+
:path: /var/run/splash/transfers
|
32
|
+
:logs_trace:
|
33
|
+
:type: :file
|
34
|
+
:path: /var/run/splash/logs
|
35
|
+
:process_trace:
|
36
|
+
:type: :file
|
37
|
+
:path: /var/run/splash/process
|
38
|
+
|
26
39
|
:transports:
|
27
40
|
:active: :rabbitmq
|
28
41
|
:rabbitmq:
|
@@ -39,16 +52,14 @@
|
|
39
52
|
:procmon_scheduling:
|
40
53
|
:every: 20s
|
41
54
|
:process_name: "Splash : daemon."
|
42
|
-
:paths:
|
43
|
-
:pid_path: /var/run/splash
|
44
|
-
:trace_path: /var/run/splash/traces
|
45
55
|
:files:
|
46
56
|
:stdout_trace: stdout.txt
|
47
57
|
:stderr_trace: stderr.txt
|
48
58
|
:pid_file: splash.pid
|
49
59
|
:prometheus:
|
50
|
-
:pushgateway: 'http://localhost:9091
|
51
|
-
:url: 'http://localhost:9090
|
60
|
+
:pushgateway: 'http://localhost:9091'
|
61
|
+
:url: 'http://localhost:9090'
|
62
|
+
:alertmanager: 'http://localhost:9093'
|
52
63
|
:webadmin:
|
53
64
|
:port: 9234
|
54
65
|
:ip: 127.0.0.1
|
@@ -117,15 +128,21 @@
|
|
117
128
|
- :label: :log_app_1
|
118
129
|
:log: /tmp/test
|
119
130
|
:pattern: ERROR
|
131
|
+
:retention:
|
132
|
+
:hours: 5
|
120
133
|
- :label: :log_app_2
|
121
134
|
:log: /tmp/test2
|
122
135
|
:pattern: ERROR
|
136
|
+
:retention:
|
137
|
+
:hours: 5
|
123
138
|
|
124
139
|
### configuration of monitored processes
|
125
140
|
:processes:
|
126
141
|
- :process: cron
|
127
142
|
:patterns:
|
128
143
|
- cron
|
144
|
+
:retention:
|
145
|
+
:hours: 5
|
129
146
|
|
130
147
|
|
131
148
|
###
|
@@ -175,4 +192,27 @@
|
|
175
192
|
- :step: exec echo3
|
176
193
|
:command: :echo3
|
177
194
|
|
195
|
+
### Transfers
|
196
|
+
:transfers:
|
197
|
+
- :name: :transfer_text
|
198
|
+
:desc: "List of text files"
|
199
|
+
:pattern: '*.txt'
|
200
|
+
:backup: true
|
201
|
+
:type: :push
|
202
|
+
:retention:
|
203
|
+
:hours: 1
|
204
|
+
:local:
|
205
|
+
:path: /tmp/transferts
|
206
|
+
:user: root
|
207
|
+
:remote:
|
208
|
+
:user: root
|
209
|
+
:host: localhost
|
210
|
+
:path: /tmp/
|
211
|
+
:post:
|
212
|
+
:remote_command: 'ls'
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
178
218
|
###
|
data/lib/splash/backends.rb
CHANGED
@@ -11,8 +11,9 @@ module Splash
|
|
11
11
|
|
12
12
|
# factory for backend
|
13
13
|
# @param [Symbol] store the name of the store actually in [:execution_trace]
|
14
|
-
# @return [Splash::Backends::<Type>|Hash] with type in [:redis,:file] or Exiter case :configuration_error
|
14
|
+
# @return [Splash::Backends::<Type>|Hash] with type in [:redis,:file] or Exiter case :configuration_error
|
15
15
|
def get_backend(store)
|
16
|
+
splash_exit case: :configuration_error, more: "backend definition failure" if get_config[:backends][:stores][store].nil?
|
16
17
|
backend = get_config[:backends][:stores][store][:type].to_s
|
17
18
|
aclass = "Splash::Backends::#{backend.capitalize}"
|
18
19
|
begin
|
@@ -22,5 +23,11 @@ module Splash
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
26
|
+
# return list of configured backand
|
27
|
+
# @return [Hash] the backends hash list/structure
|
28
|
+
def list_backends
|
29
|
+
return get_config[:backends][:stores]
|
30
|
+
end
|
31
|
+
|
25
32
|
end
|
26
33
|
end
|
data/lib/splash/backends/file.rb
CHANGED
@@ -54,7 +54,7 @@ module Splash
|
|
54
54
|
# @option options [Symbol] :key the name of the record
|
55
55
|
# @return [Boolean] status of the operation
|
56
56
|
def del(options)
|
57
|
-
::File.unlink("#{@path}/#{suffix_trace(options[:key])}") if File.exist?("#{@path}/#{suffix_trace(options[:key])}")
|
57
|
+
::File.unlink("#{@path}/#{suffix_trace(options[:key])}") if ::File.exist?("#{@path}/#{suffix_trace(options[:key])}")
|
58
58
|
end
|
59
59
|
|
60
60
|
# verifiy a specific record existance
|
data/lib/splash/cli.rb
CHANGED
@@ -43,6 +43,7 @@ class CLI < Thor
|
|
43
43
|
subcommand "documentation", Documentation
|
44
44
|
desc "webadmin SUBCOMMAND ...ARGS", "Splash Webadmin daemon controller"
|
45
45
|
subcommand "webadmin", WebAdmin
|
46
|
-
|
46
|
+
desc "transfers SUBCOMMAND ...ARGS", "Managing transfers"
|
47
|
+
subcommand "transfers", Transfers
|
47
48
|
|
48
49
|
end
|
data/lib/splash/cli/commands.rb
CHANGED
@@ -15,7 +15,7 @@ module CLISplash
|
|
15
15
|
|
16
16
|
|
17
17
|
# Thor method : execution of command
|
18
|
-
desc "execute
|
18
|
+
desc "execute COMMAND", "run for command/sequence or ack result"
|
19
19
|
long_desc <<-LONGDESC
|
20
20
|
execute command or sequence or ack result\n
|
21
21
|
with --no-trace prevent storing execution trace in configured backend (see config file)\n
|
@@ -79,7 +79,7 @@ module CLISplash
|
|
79
79
|
|
80
80
|
|
81
81
|
# Thor method : scheduling commands
|
82
|
-
desc "schedule
|
82
|
+
desc "schedule COMMAND", "Schedule excution of command on Splash daemon"
|
83
83
|
long_desc <<-LONGDESC
|
84
84
|
Schedule excution of command on Splash daemon\n
|
85
85
|
with --hostname, Schedule on an other Splash daemon via transport\n
|
@@ -93,6 +93,9 @@ module CLISplash
|
|
93
93
|
option :at, :type => :string
|
94
94
|
option :in, :type => :string
|
95
95
|
def schedule(name)
|
96
|
+
unless is_root? then
|
97
|
+
splash_exit case: :not_root, :more => "Command scheduling"
|
98
|
+
end
|
96
99
|
log = get_logger
|
97
100
|
log.level = :fatal if options[:quiet]
|
98
101
|
hostname = (options[:hostname])? options[:hostname] : Socket.gethostname
|
@@ -122,13 +125,16 @@ module CLISplash
|
|
122
125
|
end
|
123
126
|
|
124
127
|
# Thor method : getting a treeview of sequence of commands
|
125
|
-
desc "treeview", "Show commands sequence tree"
|
128
|
+
desc "treeview COMMAND", "Show commands sequence tree"
|
126
129
|
long_desc <<-LONGDESC
|
127
130
|
Show commands sequence tree\n
|
128
131
|
with --hostname, ask other Splash daemon via transport\n
|
129
132
|
LONGDESC
|
130
133
|
option :hostname, :type => :string, :aliases => "-H"
|
131
134
|
def treeview(command)
|
135
|
+
unless is_root? then
|
136
|
+
splash_exit case: :not_root, :more => "Command treeview"
|
137
|
+
end
|
132
138
|
depht = 0
|
133
139
|
log = get_logger
|
134
140
|
if options[:hostname] then
|
@@ -179,6 +185,9 @@ module CLISplash
|
|
179
185
|
option :detail, :type => :boolean, :aliases => "-D"
|
180
186
|
option :hostname, :type => :string, :aliases => "-H"
|
181
187
|
def list
|
188
|
+
unless is_root? then
|
189
|
+
splash_exit case: :not_root, :more => "Command list"
|
190
|
+
end
|
182
191
|
log = get_logger
|
183
192
|
list = {}
|
184
193
|
if options[:hostname] then
|
@@ -227,6 +236,9 @@ module CLISplash
|
|
227
236
|
LONGDESC
|
228
237
|
option :hostname, :type => :string, :aliases => "-H"
|
229
238
|
def show(command)
|
239
|
+
unless is_root? then
|
240
|
+
splash_exit case: :not_root, :more => "Command show specifications"
|
241
|
+
end
|
230
242
|
log = get_logger
|
231
243
|
list = {}
|
232
244
|
if options[:hostname] then
|
@@ -265,14 +277,71 @@ module CLISplash
|
|
265
277
|
end
|
266
278
|
end
|
267
279
|
|
268
|
-
|
269
|
-
|
280
|
+
|
281
|
+
|
282
|
+
# Thor method : show commands executions history
|
283
|
+
long_desc <<-LONGDESC
|
284
|
+
show commands executions history for LABEL\n
|
285
|
+
LONGDESC
|
286
|
+
option :table, :type => :boolean, :aliases => "-t"
|
287
|
+
desc "history COMMAND", "show commands executions history"
|
288
|
+
def history(command)
|
289
|
+
if is_root? then
|
290
|
+
log = get_logger
|
291
|
+
log.info "Command : #{command}"
|
292
|
+
config = get_config
|
293
|
+
if options[:table] then
|
294
|
+
table = TTY::Table.new do |t|
|
295
|
+
t << ["Start Date","Status", "end_date", "Execution time","STDOUT empty ? ", "STDERR empty ? "]
|
296
|
+
t << ['','','','','','']
|
297
|
+
CmdRecords::new(command).get_all_records.each do |item|
|
298
|
+
record =item.keys.first
|
299
|
+
value=item[record]
|
300
|
+
t << [record, value[:status].to_s,
|
301
|
+
value[:end_date],
|
302
|
+
value[:exec_time],
|
303
|
+
value[:stdout].empty?,
|
304
|
+
value[:stdout].empty?]
|
305
|
+
end
|
306
|
+
end
|
307
|
+
if check_unicode_term then
|
308
|
+
puts table.render(:unicode)
|
309
|
+
else
|
310
|
+
puts table.render(:ascii)
|
311
|
+
end
|
312
|
+
|
313
|
+
else
|
314
|
+
CmdRecords::new(command).get_all_records.each do |item|
|
315
|
+
record =item.keys.first
|
316
|
+
value=item[record]
|
317
|
+
log.item record
|
318
|
+
log.arrow "Status : #{value[:status].to_s}"
|
319
|
+
log.arrow "End date : #{value[:end_date]}"
|
320
|
+
log.arrow "Execution time : #{value[:exec_time]}"
|
321
|
+
log.arrow "STDOUT empty ? : #{value[:stdout].empty?}"
|
322
|
+
log.arrow "STDERR empty ? : #{value[:stderr].empty?}"
|
323
|
+
end
|
324
|
+
end
|
325
|
+
splash_exit case: :quiet_exit
|
326
|
+
else
|
327
|
+
splash_exit case: :not_root, :more => "Command execution history"
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
# Thor method : getting information on one specific execution of a command
|
332
|
+
desc "get_result COMMAND", "Show running result for specific configured command COMMAND"
|
270
333
|
long_desc <<-LONGDESC
|
271
|
-
Show
|
334
|
+
Show specific running result for specific configured command COMMAND\n
|
272
335
|
with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)
|
336
|
+
with --date <DATE>, a date format string (same as in history ouput)
|
337
|
+
|
273
338
|
LONGDESC
|
274
339
|
option :hostname, :type => :string, :aliases => "-H"
|
275
|
-
|
340
|
+
option :date, :type => :string, :aliases => "-D"
|
341
|
+
def get_result(command)
|
342
|
+
unless is_root? then
|
343
|
+
splash_exit case: :not_root, :more => "Command specific execution report"
|
344
|
+
end
|
276
345
|
log = get_logger
|
277
346
|
backend = get_backend :execution_trace
|
278
347
|
redis = (backend.class == Splash::Backends::Redis)? true : false
|
@@ -294,19 +363,32 @@ module CLISplash
|
|
294
363
|
tp = Template::new(
|
295
364
|
list_token: get_config.execution_template_tokens,
|
296
365
|
template_file: get_config.execution_template_path)
|
297
|
-
|
298
|
-
|
366
|
+
if options[:date] then
|
367
|
+
prov = YAML::load(res).select{|key,value| key.keys.first == options[:date]}.first
|
368
|
+
else
|
369
|
+
prov = YAML::load(res).last
|
370
|
+
end
|
371
|
+
if prov.nil? then
|
372
|
+
log.ko "Command not runned one this date or date misformatted."
|
373
|
+
else
|
374
|
+
tp.map prov.values.first
|
375
|
+
log.flat tp.output
|
376
|
+
end
|
299
377
|
else
|
300
378
|
log.ko "Command not already runned."
|
301
379
|
end
|
302
380
|
splash_exit case: :quiet_exit
|
303
381
|
else
|
304
|
-
|
382
|
+
if options[:hostname]
|
383
|
+
splash_exit case: :not_found, :more => "Command never runned remotly"
|
384
|
+
else
|
385
|
+
splash_exit case: :not_found, :more => "Command never runned"
|
386
|
+
end
|
305
387
|
end
|
306
388
|
end
|
307
389
|
|
308
390
|
# Thor method : getting the list of avaibles executions reports
|
309
|
-
desc "
|
391
|
+
desc "reportlist", "list all executions report results "
|
310
392
|
long_desc <<-LONGDESC
|
311
393
|
list all executions report results\n
|
312
394
|
with --pattern <SEARCH>, search type string, wilcard * (group) ? (char)\n
|
@@ -319,7 +401,10 @@ module CLISplash
|
|
319
401
|
option :hostname, :type => :string, :aliases => "-H"
|
320
402
|
option :all, :type => :boolean, :negate => false, :aliases => "-A"
|
321
403
|
option :detail, :type => :boolean, :aliases => "-D"
|
322
|
-
def
|
404
|
+
def reportlist
|
405
|
+
unless is_root? then
|
406
|
+
splash_exit case: :not_root, :more => "Command execution report list"
|
407
|
+
end
|
323
408
|
log = get_logger
|
324
409
|
options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
|
325
410
|
if options[:hostname] and options[:all] then
|
@@ -355,10 +440,9 @@ module CLISplash
|
|
355
440
|
req = { :key => command }
|
356
441
|
req[:hostname] = host if options[:all]
|
357
442
|
res = YAML::load(backend.get(req))
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
log.arrow "Execution time : #{res[:exec_time]}"
|
443
|
+
res.each do |record|
|
444
|
+
log.arrow "#{record.keys.first} : #{record[record.keys.first][:status]}"
|
445
|
+
end
|
362
446
|
end
|
363
447
|
end
|
364
448
|
splash_exit case: :quiet_exit
|
data/lib/splash/cli/config.rb
CHANGED
@@ -9,6 +9,7 @@ module CLISplash
|
|
9
9
|
include Splash::Helpers
|
10
10
|
include Splash::Exiter
|
11
11
|
include Splash::Loggers
|
12
|
+
include Splash::Backends
|
12
13
|
|
13
14
|
# Thor method : running of Splash setup
|
14
15
|
desc "setup", "Setup installation fo Splash"
|
@@ -49,8 +50,18 @@ module CLISplash
|
|
49
50
|
|
50
51
|
# Thor method : flushing configured backend
|
51
52
|
desc "flushbackend", "Flush configured backend"
|
53
|
+
option :name, :type => :string, :aliases => "-N"
|
52
54
|
def flushbackend
|
53
|
-
|
55
|
+
if options[:name] then
|
56
|
+
acase = run_as_root :flush_backend, options
|
57
|
+
else
|
58
|
+
return_cases = {}
|
59
|
+
list_backends.each do |key,value|
|
60
|
+
return_cases[key] = run_as_root :flush_backend, { :name => key }
|
61
|
+
end
|
62
|
+
errors = return_cases.select {|key,value| value[:case] != :quiet_exit}.keys
|
63
|
+
acase = (errors.empty?)? {:case => :quiet_exit, :more => "All backends flushed successfully"}: {:case => :configuration_error, :more => "Backends #{errors.join(',')} flushing failed"}
|
64
|
+
end
|
54
65
|
splash_exit acase
|
55
66
|
end
|
56
67
|
|
data/lib/splash/cli/daemon.rb
CHANGED
@@ -74,7 +74,47 @@ module CLISplash
|
|
74
74
|
splash_exit case: :quiet_exit
|
75
75
|
end
|
76
76
|
rescue Interrupt
|
77
|
-
splash_exit status: :error, case: :interrupt, more: "
|
77
|
+
splash_exit status: :error, case: :interrupt, more: "ping Command"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Thor method : sending get_jobs verb over transport in the input queue of Splashd
|
82
|
+
desc "getjobs", "send a get_jobs verb to HOSTNAME daemon over transport (need an active tranport), Typicallly RabbitMQ"
|
83
|
+
def getjobs(hostname=Socket.gethostname)
|
84
|
+
log = get_logger
|
85
|
+
log.info "ctrl+c for interrupt"
|
86
|
+
begin
|
87
|
+
transport = get_default_client
|
88
|
+
if transport.class == Hash and transport.include? :case then
|
89
|
+
splash_exit transport
|
90
|
+
else
|
91
|
+
log.receive transport.execute({ :verb => :get_jobs,
|
92
|
+
:return_to => "splash.#{Socket.gethostname}.returncli",
|
93
|
+
:queue => "splash.#{hostname}.input" })
|
94
|
+
splash_exit case: :quiet_exit
|
95
|
+
end
|
96
|
+
rescue Interrupt
|
97
|
+
splash_exit status: :error, case: :interrupt, more: "getjobs Command"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Thor method : sending reset verb over transport in the input queue of Splashd
|
102
|
+
desc "getjobs", "send a reset verb to HOSTNAME daemon over transport (need an active tranport), Typicallly RabbitMQ"
|
103
|
+
def reset(hostname=Socket.gethostname)
|
104
|
+
log = get_logger
|
105
|
+
log.info "ctrl+c for interrupt"
|
106
|
+
begin
|
107
|
+
transport = get_default_client
|
108
|
+
if transport.class == Hash and transport.include? :case then
|
109
|
+
splash_exit transport
|
110
|
+
else
|
111
|
+
log.receive transport.execute({ :verb => :reset,
|
112
|
+
:return_to => "splash.#{Socket.gethostname}.returncli",
|
113
|
+
:queue => "splash.#{hostname}.input" })
|
114
|
+
splash_exit case: :quiet_exit
|
115
|
+
end
|
116
|
+
rescue Interrupt
|
117
|
+
splash_exit status: :error, case: :interrupt, more: "reset Command"
|
78
118
|
end
|
79
119
|
end
|
80
120
|
|
data/lib/splash/cli/logs.rb
CHANGED
@@ -12,61 +12,76 @@ module CLISplash
|
|
12
12
|
# Thor method : running Splash configured logs monitors analyse
|
13
13
|
desc "analyse", "analyze logs defined in Splash config"
|
14
14
|
def analyse
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
15
|
+
if is_root? then
|
16
|
+
log = get_logger
|
17
|
+
results = LogScanner::new
|
18
|
+
res = results.analyse
|
19
|
+
log.info "SPlash Configured log monitors :"
|
20
|
+
full_status = true
|
21
|
+
results.output.each do |result|
|
22
|
+
if result[:status] == :clean then
|
23
|
+
log.ok "Log : #{result[:log]} with label : #{result[:label]} : no errors"
|
24
|
+
log.item "Detected pattern : #{result[:pattern]}"
|
25
|
+
log.item "Nb lines = #{result[:lines]}"
|
26
|
+
elsif result[:status] == :missing then
|
27
|
+
log.ko "Log : #{result[:log]} with label : #{result[:label]} : missing !"
|
28
|
+
log.item "Detected pattern : #{result[:pattern]}"
|
29
|
+
else
|
30
|
+
log.ko "Log : #{result[:log]} with label : #{result[:label]} : #{result[:count]} errors"
|
31
|
+
log.item "Detected pattern : #{result[:pattern]}"
|
32
|
+
log.item "Nb lines = #{result[:lines]}"
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
full_status = false unless result[:status] == :clean
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
if full_status then
|
39
|
+
log.ok "Global status : no error found"
|
40
|
+
else
|
41
|
+
log.error "Global status : some error found"
|
42
|
+
end
|
43
|
+
splash_exit case: :quiet_exit
|
39
44
|
else
|
40
|
-
|
45
|
+
splash_exit case: :not_root, :more => "Log analysis"
|
41
46
|
end
|
42
|
-
splash_exit case: :quiet_exit
|
43
47
|
end
|
44
48
|
|
45
49
|
|
46
50
|
# Thor method : running Splash configured logs monitors analyse and sending to Prometheus Pushgateway
|
47
51
|
desc "monitor", "monitor logs defined in Splash config"
|
48
52
|
def monitor
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
if is_root? then
|
54
|
+
log = get_logger
|
55
|
+
log.level = :fatal if options[:quiet]
|
56
|
+
result = LogScanner::new
|
57
|
+
result.analyse
|
58
|
+
splash_exit result.notify
|
59
|
+
else
|
60
|
+
splash_exit case: :not_root, :more => "Log analysis"
|
61
|
+
end
|
54
62
|
|
55
63
|
end
|
56
64
|
|
65
|
+
|
66
|
+
|
67
|
+
|
57
68
|
# Thor method : display a specific Splash configured log monitor
|
58
|
-
desc "show
|
69
|
+
desc "show LABEL", "show Splash configured log monitoring for LOG"
|
59
70
|
def show(logrecord)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
71
|
+
if is_root? then
|
72
|
+
log = get_logger
|
73
|
+
log_record_set = get_config.logs.select{|item| item[:log] == logrecord or item[:label] == logrecord.to_sym}
|
74
|
+
unless log_record_set.empty? then
|
75
|
+
record = log_record_set.first
|
76
|
+
log.info "Splash log monitor : #{record[:log]}"
|
77
|
+
log.item "pattern : /#{record[:pattern]}/"
|
78
|
+
log.item "label : #{record[:label]}"
|
79
|
+
splash_exit case: :quiet_exit
|
80
|
+
else
|
81
|
+
splash_exit case: :not_found, :more => "log not configured"
|
82
|
+
end
|
68
83
|
else
|
69
|
-
splash_exit case: :
|
84
|
+
splash_exit case: :not_root, :more => "Log analysis"
|
70
85
|
end
|
71
86
|
end
|
72
87
|
|
@@ -78,17 +93,98 @@ module CLISplash
|
|
78
93
|
LONGDESC
|
79
94
|
option :detail, :type => :boolean, :aliases => "-D"
|
80
95
|
def list
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
96
|
+
if is_root? then
|
97
|
+
log = get_logger
|
98
|
+
log.info "Splash configured log monitoring :"
|
99
|
+
log_record_set = get_config.logs
|
100
|
+
log.ko 'No configured commands found' if log_record_set.empty?
|
101
|
+
log_record_set.each do |record|
|
102
|
+
log.item "log monitor : #{record[:log]} label : #{record[:label]}"
|
103
|
+
if options[:detail] then
|
104
|
+
log.arrow "pattern : /#{record[:pattern]}/"
|
105
|
+
end
|
89
106
|
end
|
107
|
+
splash_exit case: :quiet_exit
|
108
|
+
else
|
109
|
+
splash_exit case: :not_root, :more => "Log analysis"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Thor method : display the full list of Splash configured log monitors
|
114
|
+
desc "get_result LABEL", "Get last or specific log monitoring report"
|
115
|
+
long_desc <<-LONGDESC
|
116
|
+
Get last or specific log monitoring report\n
|
117
|
+
with --date <DATE>, a date format string (same as in history ouput)
|
118
|
+
LONGDESC
|
119
|
+
option :date, :type => :string, :aliases => "-D"
|
120
|
+
def get_result(label)
|
121
|
+
if is_root? then
|
122
|
+
log = get_logger
|
123
|
+
log.info "Log : #{label}"
|
124
|
+
config = get_config
|
125
|
+
records = LogsRecords::new(label).get_all_records
|
126
|
+
if options[:date] then
|
127
|
+
wanted = records.select{|key,value| key.keys.first == options[:date]}.first
|
128
|
+
else
|
129
|
+
wanted = records.last
|
130
|
+
end
|
131
|
+
if wanted.nil? then
|
132
|
+
splash_exit case: :not_found, more: "Log never monitored"
|
133
|
+
else
|
134
|
+
record =wanted.keys.first
|
135
|
+
value=wanted[record]
|
136
|
+
log.item record
|
137
|
+
log.arrow "Status : #{value[:status].to_s}"
|
138
|
+
log.arrow "nb files : #{value[:errors]}"
|
139
|
+
log.arrow "nb lines : #{value[:lines]}"
|
140
|
+
end
|
141
|
+
else
|
142
|
+
splash_exit case: :not_root, :more => "Log get result"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Thor method : show logs monitoring history
|
147
|
+
long_desc <<-LONGDESC
|
148
|
+
show logs monitoring history for LABEL\n
|
149
|
+
LONGDESC
|
150
|
+
option :table, :type => :boolean, :aliases => "-t"
|
151
|
+
desc "history LABEL", "show logs monitoring history"
|
152
|
+
def history(label)
|
153
|
+
if is_root? then
|
154
|
+
log = get_logger
|
155
|
+
log.info "Log : #{label}"
|
156
|
+
config = get_config
|
157
|
+
if options[:table] then
|
158
|
+
table = TTY::Table.new do |t|
|
159
|
+
t << ["Start Date", "File","Status", "Nb errors", "Nb lines"]
|
160
|
+
t << ['','','','','']
|
161
|
+
LogsRecords::new(label).get_all_records.each do |item|
|
162
|
+
record =item.keys.first
|
163
|
+
value=item[record]
|
164
|
+
|
165
|
+
t << [record, value[:file], value[:status].to_s, value[:errors], value[:lines]]
|
166
|
+
end
|
167
|
+
end
|
168
|
+
if check_unicode_term then
|
169
|
+
puts table.render(:unicode)
|
170
|
+
else
|
171
|
+
puts table.render(:ascii)
|
172
|
+
end
|
173
|
+
|
174
|
+
else
|
175
|
+
LogsRecords::new(label).get_all_records.each do |item|
|
176
|
+
record =item.keys.first
|
177
|
+
value=item[record]
|
178
|
+
log.item record
|
179
|
+
log.arrow "Status : #{value[:status].to_s}"
|
180
|
+
log.arrow "nb files : #{value[:errors]}"
|
181
|
+
log.arrow "nb lines : #{value[:lines]}"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
splash_exit case: :quiet_exit
|
185
|
+
else
|
186
|
+
splash_exit case: :not_root, :more => "Log analysis"
|
90
187
|
end
|
91
|
-
splash_exit case: :quiet_exit
|
92
188
|
end
|
93
189
|
|
94
190
|
end
|