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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -3
  3. data/README.md +400 -178
  4. data/config/splash.yml +28 -14
  5. data/lib/splash/backends.rb +7 -1
  6. data/lib/splash/backends/file.rb +1 -1
  7. data/lib/splash/cli/commands.rb +122 -37
  8. data/lib/splash/cli/config.rb +12 -1
  9. data/lib/splash/cli/daemon.rb +1 -1
  10. data/lib/splash/cli/logs.rb +144 -48
  11. data/lib/splash/cli/process.rb +145 -52
  12. data/lib/splash/cli/transfers.rb +10 -3
  13. data/lib/splash/commands.rb +115 -40
  14. data/lib/splash/config.rb +112 -29
  15. data/lib/splash/config/flush.rb +2 -2
  16. data/lib/splash/constants.rb +3 -4
  17. data/lib/splash/daemon/orchestrator.rb +6 -7
  18. data/lib/splash/daemon/orchestrator/grammar.rb +1 -1
  19. data/lib/splash/dependencies.rb +1 -0
  20. data/lib/splash/exiter.rb +1 -1
  21. data/lib/splash/helpers.rb +1 -1
  22. data/lib/splash/logs.rb +94 -16
  23. data/lib/splash/monkeys.rb +5 -0
  24. data/lib/splash/processes.rb +91 -16
  25. data/lib/splash/sequences.rb +6 -1
  26. data/lib/splash/transfers.rb +13 -8
  27. data/lib/splash/webadmin/api/routes/commands.rb +15 -3
  28. data/lib/splash/webadmin/api/routes/config.rb +140 -2
  29. data/lib/splash/webadmin/api/routes/logs.rb +32 -17
  30. data/lib/splash/webadmin/api/routes/process.rb +21 -9
  31. data/lib/splash/webadmin/api/routes/sequences.rb +2 -2
  32. data/lib/splash/webadmin/main.rb +15 -1
  33. data/lib/splash/webadmin/portal/controllers/commands.rb +101 -1
  34. data/lib/splash/webadmin/portal/controllers/documentation.rb +2 -0
  35. data/lib/splash/webadmin/portal/controllers/home.rb +6 -1
  36. data/lib/splash/webadmin/portal/controllers/logs.rb +71 -1
  37. data/lib/splash/webadmin/portal/controllers/processes.rb +75 -3
  38. data/lib/splash/webadmin/portal/controllers/proxy.rb +2 -1
  39. data/lib/splash/webadmin/portal/controllers/restclient.rb +6 -1
  40. data/lib/splash/webadmin/portal/controllers/sequences.rb +2 -0
  41. data/lib/splash/webadmin/portal/public/css/ultragreen.css +6 -0
  42. data/lib/splash/webadmin/portal/public/favicon.ico +0 -0
  43. data/lib/splash/webadmin/portal/views/command_form.slim +45 -0
  44. data/lib/splash/webadmin/portal/views/command_history.slim +27 -0
  45. data/lib/splash/webadmin/portal/views/commands.slim +70 -20
  46. data/lib/splash/webadmin/portal/views/documentation.slim +1 -1
  47. data/lib/splash/webadmin/portal/views/home.slim +19 -20
  48. data/lib/splash/webadmin/portal/views/layout.slim +2 -2
  49. data/lib/splash/webadmin/portal/views/log_form.slim +27 -0
  50. data/lib/splash/webadmin/portal/views/log_history.slim +24 -0
  51. data/lib/splash/webadmin/portal/views/logs.slim +95 -21
  52. data/lib/splash/webadmin/portal/views/nav.slim +1 -1
  53. data/lib/splash/webadmin/portal/views/not_found.slim +1 -1
  54. data/lib/splash/webadmin/portal/views/process_form.slim +24 -0
  55. data/lib/splash/webadmin/portal/views/process_history.slim +24 -0
  56. data/lib/splash/webadmin/portal/views/processes.slim +80 -7
  57. data/lib/splash/webadmin/portal/views/proxy.slim +2 -2
  58. data/lib/splash/webadmin/portal/views/restclient.slim +7 -4
  59. data/lib/splash/webadmin/portal/views/restclient_result.slim +24 -20
  60. data/lib/splash/webadmin/portal/views/sequences.slim +1 -1
  61. data/prometheus-splash.gemspec +4 -4
  62. data/ultragreen_roodi_coding_convention.yml +4 -4
  63. metadata +18 -10
@@ -26,9 +26,15 @@
26
26
  # :port: 6379
27
27
  # #:auth: "mykey"
28
28
  # :base: 1
29
- :transferts_trace:
29
+ :transfers_trace:
30
30
  :type: :file
31
- :path: /var/run/splash/transferts
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
32
38
 
33
39
  :transports:
34
40
  :active: :rabbitmq
@@ -67,49 +73,51 @@
67
73
 
68
74
  ### Sample configuration of commands and scheduling
69
75
  :commands:
70
- :id_root:
76
+ - :name: :id_root
71
77
  :desc: run id command on root
72
78
  :command: id root
73
- :true_test:
79
+ - :name: :true_test
74
80
  :desc: "test command returning true : 0"
75
81
  :command: "true"
76
82
  :schedule:
77
83
  :every: "1h"
78
84
  :on_failure: :ls_slash_tmp
79
85
  :on_success: :pwd
80
- :false_test:
86
+ - :name: :false_test
81
87
  :desc: "test command returning false > 0"
82
88
  :command: "false"
83
89
  :schedule:
84
90
  :every: "1h"
85
91
  :on_failure: :ls_slash_tmp
86
92
  :on_success: :pwd
87
- :ls_slash_tmp:
93
+ - :name: :ls_slash_tmp
88
94
  :desc: list file in /tmp
89
95
  :command: ls -al /tmp
90
96
  :user: daemon
91
97
  :on_success: :echo1
92
- :pwd:
98
+ - :name: :pwd
93
99
  :desc: run pwd
94
100
  :command: pwd
95
101
  :on_success: :echo1
96
102
  :on_failure: :echo2
97
- :echo1:
103
+ - :name: :echo1
98
104
  :desc: echo 'foo'
99
105
  :command: echo foo
100
106
  :on_failure: :echo3
101
- :echo2:
107
+ - :name: :echo2
102
108
  :desc: echo 'bar'
103
109
  :command: echo bar
104
- :echo3:
110
+ - :name: :echo3
105
111
  :desc: echo 'been'
106
112
  :command: echo been
107
- :rand_sleep_5:
113
+ - :name: :rand_sleep_5
108
114
  :desc: sleep on a rand 5
109
115
  :command: ruby -e 'sleep rand(5)'
110
116
  :schedule:
111
- :every: "10s"
112
- :test_remote_call:
117
+ :every: "30s"
118
+ :retention:
119
+ :hours: 1
120
+ - :name: :test_remote_call
113
121
  :desc: remote call test
114
122
  :delegate_to:
115
123
  :host: omicron
@@ -122,15 +130,21 @@
122
130
  - :label: :log_app_1
123
131
  :log: /tmp/test
124
132
  :pattern: ERROR
133
+ :retention:
134
+ :hours: 5
125
135
  - :label: :log_app_2
126
136
  :log: /tmp/test2
127
137
  :pattern: ERROR
138
+ :retention:
139
+ :hours: 5
128
140
 
129
141
  ### configuration of monitored processes
130
142
  :processes:
131
- - :process: cron
143
+ - :process: :cron
132
144
  :patterns:
133
145
  - cron
146
+ :retention:
147
+ :hours: 5
134
148
 
135
149
 
136
150
  ###
@@ -11,7 +11,7 @@ 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
16
  splash_exit case: :configuration_error, more: "backend definition failure" if get_config[:backends][:stores][store].nil?
17
17
  backend = get_config[:backends][:stores][store][:type].to_s
@@ -23,5 +23,11 @@ module Splash
23
23
  end
24
24
  end
25
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
+
26
32
  end
27
33
  end
@@ -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
@@ -15,7 +15,7 @@ module CLISplash
15
15
 
16
16
 
17
17
  # Thor method : execution of command
18
- desc "execute NAME", "run for command/sequence or ack result"
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 NAME", "Schedule excution of command on Splash daemon"
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
@@ -153,7 +159,7 @@ module CLISplash
153
159
  end
154
160
  log.info "Command : #{command.to_s}" if depht == 0
155
161
  aproc = Proc::new do |command,depht|
156
- cmd = commands[command.to_sym]
162
+ cmd = commands.select{|item| item[:name] == command.to_sym}.first
157
163
  if cmd[:on_failure] then
158
164
  spacer= " " * depht + " "
159
165
  log.flat "#{spacer}* on failure => #{cmd[:on_failure]}"
@@ -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
@@ -202,16 +211,16 @@ module CLISplash
202
211
  list = get_config.commands
203
212
  end
204
213
  log.info "Splash configured commands :"
205
- log.ko 'No configured commands found' if list.keys.empty?
206
- list.keys.each do |command|
207
- log.item "#{command.to_s}"
214
+ log.ko 'No configured commands found' if list.empty?
215
+ list.each do |command|
216
+ log.item "#{command[:name].to_s}"
208
217
  if options[:detail] then
209
- log.arrow "command line : '#{list[command][:command]}'"
210
- log.arrow "command description : '#{list[command][:desc]}'"
211
- log.arrow "command failure callback : '#{list[command.to_sym][:on_failure]}'" if list[command.to_sym][:on_failure]
212
- log.arrow "command success callback : '#{list[command.to_sym][:on_success]}'" if list[command.to_sym][:on_success]
213
- if list[command.to_sym][:schedule]
214
- sched,val = list[command.to_sym][:schedule].flatten
218
+ log.arrow "command line : '#{command[:command]}'"
219
+ log.arrow "command description : '#{command[:desc]}'"
220
+ log.arrow "command failure callback : '#{command[:on_failure]}'" if command[:on_failure]
221
+ log.arrow "command success callback : '#{command[:on_success]}'" if command[:on_success]
222
+ if command[:schedule] then
223
+ sched,val = command[:schedule].flatten
215
224
  log.arrow "command scheduled : #{sched} #{val}."
216
225
  end
217
226
  end
@@ -226,7 +235,10 @@ module CLISplash
226
235
  with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)
227
236
  LONGDESC
228
237
  option :hostname, :type => :string, :aliases => "-H"
229
- def show(command)
238
+ def show(name)
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
@@ -249,14 +261,15 @@ module CLISplash
249
261
  else
250
262
  list = get_config.commands
251
263
  end
252
- if list.keys.include? command.to_sym then
253
- log.info "Splash command : #{command}"
254
- log.item "command line : '#{list[command.to_sym][:command]}'"
255
- log.item "command description : '#{list[command.to_sym][:desc]}'"
256
- log.item "command failure callback : '#{list[command.to_sym][:on_failure]}'" if list[command.to_sym][:on_failure]
257
- log.item "command success callback : '#{list[command.to_sym][:on_success]}'" if list[command.to_sym][:on_success]
258
- if list[command.to_sym][:schedule]
259
- sched,val = list[command.to_sym][:schedule].flatten
264
+ command = list.select{|item| item[:name] == name.to_sym}.first
265
+ unless command.nil? then
266
+ log.info "Splash command : #{command[:name]}"
267
+ log.item "command line : '#{command[:command]}'"
268
+ log.item "command description : '#{command[:desc]}'"
269
+ log.item "command failure callback : '#{command[:on_failure]}'" if command[:on_failure]
270
+ log.item "command success callback : '#{command[:on_success]}'" if command[:on_success]
271
+ if command[:schedule]
272
+ sched,val = command[:schedule].flatten
260
273
  log.item "command scheduled : #{sched} #{val}."
261
274
  end
262
275
  splash_exit case: :quiet_exit
@@ -265,14 +278,71 @@ module CLISplash
265
278
  end
266
279
  end
267
280
 
268
- # Thor method : getting information on the last execution of a command
269
- desc "lastrun COMMAND", "Show last running result for specific configured command COMMAND"
281
+
282
+
283
+ # Thor method : show commands executions history
284
+ long_desc <<-LONGDESC
285
+ show commands executions history for LABEL\n
286
+ LONGDESC
287
+ option :table, :type => :boolean, :aliases => "-t"
288
+ desc "history COMMAND", "show commands executions history"
289
+ def history(command)
290
+ if is_root? then
291
+ log = get_logger
292
+ log.info "Command : #{command}"
293
+ config = get_config
294
+ if options[:table] then
295
+ table = TTY::Table.new do |t|
296
+ t << ["Start Date","Status", "end_date", "Execution time","STDOUT empty ? ", "STDERR empty ? "]
297
+ t << ['','','','','','']
298
+ CmdRecords::new(command).get_all_records.each do |item|
299
+ record =item.keys.first
300
+ value=item[record]
301
+ t << [record, value[:status].to_s,
302
+ value[:end_date],
303
+ value[:exec_time],
304
+ value[:stdout].empty?,
305
+ value[:stderr].empty?]
306
+ end
307
+ end
308
+ if check_unicode_term then
309
+ puts table.render(:unicode)
310
+ else
311
+ puts table.render(:ascii)
312
+ end
313
+
314
+ else
315
+ CmdRecords::new(command).get_all_records.each do |item|
316
+ record =item.keys.first
317
+ value=item[record]
318
+ log.item record
319
+ log.arrow "Status : #{value[:status].to_s}"
320
+ log.arrow "End date : #{value[:end_date]}"
321
+ log.arrow "Execution time : #{value[:exec_time]}"
322
+ log.arrow "STDOUT empty ? : #{value[:stdout].empty?}"
323
+ log.arrow "STDERR empty ? : #{value[:stderr].empty?}"
324
+ end
325
+ end
326
+ splash_exit case: :quiet_exit
327
+ else
328
+ splash_exit case: :not_root, :more => "Command execution history"
329
+ end
330
+ end
331
+
332
+ # Thor method : getting information on one specific execution of a command
333
+ desc "get_result COMMAND", "Show running result for specific configured command COMMAND"
270
334
  long_desc <<-LONGDESC
271
- Show last running result for specific configured command COMMAND\n
335
+ Show specific running result for specific configured command COMMAND\n
272
336
  with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)
337
+ with --date <DATE>, a date format string (same as in history ouput)
338
+
273
339
  LONGDESC
274
340
  option :hostname, :type => :string, :aliases => "-H"
275
- def lastrun(command)
341
+ option :date, :type => :string, :aliases => "-D"
342
+ def get_result(command)
343
+ unless is_root? then
344
+ splash_exit case: :not_root, :more => "Command specific execution report"
345
+ end
276
346
  log = get_logger
277
347
  backend = get_backend :execution_trace
278
348
  redis = (backend.class == Splash::Backends::Redis)? true : false
@@ -280,12 +350,12 @@ module CLISplash
280
350
  splash_exit case: :specific_config_required, :more => "Redis backend is requiered for Remote execution report request"
281
351
  end
282
352
  splash_exit case: :not_root if not is_root? and not redis
283
- list = get_config.commands.keys
353
+ list = get_config.commands
284
354
  if options[:hostname] then
285
355
  options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
286
356
  list = backend.list("*", options[:hostname]).map(&:to_sym)
287
357
  end
288
- if list.include? command.to_sym then
358
+ if list.select{|cmd| cmd[:name] == command.to_sym}.count > 0 then
289
359
  log.info "Splash command #{command} previous execution report:\n"
290
360
  req = { :key => command}
291
361
  req[:hostname] = options[:hostname] if options[:hostname]
@@ -294,19 +364,32 @@ module CLISplash
294
364
  tp = Template::new(
295
365
  list_token: get_config.execution_template_tokens,
296
366
  template_file: get_config.execution_template_path)
297
- tp.map YAML::load(res)
298
- log.flat tp.output
367
+ if options[:date] then
368
+ prov = YAML::load(res).select{|key,value| key.keys.first == options[:date]}.first
369
+ else
370
+ prov = YAML::load(res).last
371
+ end
372
+ if prov.nil? then
373
+ log.ko "Command not runned one this date or date misformatted."
374
+ else
375
+ tp.map prov.values.first
376
+ log.flat tp.output
377
+ end
299
378
  else
300
379
  log.ko "Command not already runned."
301
380
  end
302
381
  splash_exit case: :quiet_exit
303
382
  else
304
- splash_exit case: :not_found, :more => "Command report never runned remotly" if options[:hostname]
383
+ if options[:hostname]
384
+ splash_exit case: :not_found, :more => "Command never runned remotly"
385
+ else
386
+ splash_exit case: :not_found, :more => "Command never runned"
387
+ end
305
388
  end
306
389
  end
307
390
 
308
391
  # Thor method : getting the list of avaibles executions reports
309
- desc "getreportlist", "list all executions report results "
392
+ desc "reportlist", "list all executions report results "
310
393
  long_desc <<-LONGDESC
311
394
  list all executions report results\n
312
395
  with --pattern <SEARCH>, search type string, wilcard * (group) ? (char)\n
@@ -319,7 +402,10 @@ module CLISplash
319
402
  option :hostname, :type => :string, :aliases => "-H"
320
403
  option :all, :type => :boolean, :negate => false, :aliases => "-A"
321
404
  option :detail, :type => :boolean, :aliases => "-D"
322
- def getreportlist
405
+ def reportlist
406
+ unless is_root? then
407
+ splash_exit case: :not_root, :more => "Command execution report list"
408
+ end
323
409
  log = get_logger
324
410
  options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
325
411
  if options[:hostname] and options[:all] then
@@ -355,10 +441,9 @@ module CLISplash
355
441
  req = { :key => command }
356
442
  req[:hostname] = host if options[:all]
357
443
  res = YAML::load(backend.get(req))
358
- log.arrow "Status : #{res[:status]}"
359
- log.arrow "Start date : #{res[:start_date]}"
360
- log.arrow "End date : #{res[:end_date]}"
361
- log.arrow "Execution time : #{res[:exec_time]}"
444
+ res.each do |record|
445
+ log.arrow "#{record.keys.first} : #{record[record.keys.first][:status]}"
446
+ end
362
447
  end
363
448
  end
364
449
  splash_exit case: :quiet_exit
@@ -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
- acase = run_as_root :flush_backend
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
 
@@ -99,7 +99,7 @@ module CLISplash
99
99
  end
100
100
 
101
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"
102
+ desc "reset", "send a reset verb to HOSTNAME daemon over transport (need an active tranport), Typicallly RabbitMQ"
103
103
  def reset(hostname=Socket.gethostname)
104
104
  log = get_logger
105
105
  log.info "ctrl+c for interrupt"
@@ -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
- log = get_logger
16
- results = LogScanner::new
17
- res = results.analyse
18
- log.info "SPlash Configured log monitors :"
19
- full_status = true
20
- results.output.each do |result|
21
- if result[:status] == :clean then
22
- log.ok "Log : #{result[:log]} with label : #{result[:label]} : no errors"
23
- log.item "Detected pattern : #{result[:pattern]}"
24
- log.item "Nb lines = #{result[:lines]}"
25
- elsif result[:status] == :missing then
26
- log.ko "Log : #{result[:log]} with label : #{result[:label]} : missing !"
27
- log.item "Detected pattern : #{result[:pattern]}"
28
- else
29
- log.ko "Log : #{result[:log]} with label : #{result[:label]} : #{result[:count]} errors"
30
- log.item "Detected pattern : #{result[:pattern]}"
31
- log.item "Nb lines = #{result[:lines]}"
32
- end
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
- full_status = false unless result[:status] == :clean
35
- end
35
+ full_status = false unless result[:status] == :clean
36
+ end
36
37
 
37
- if full_status then
38
- log.ok "Global status : no error found"
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
- log.error "Global status : some error found"
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
- log = get_logger
50
- log.level = :fatal if options[:quiet]
51
- result = LogScanner::new
52
- result.analyse
53
- splash_exit result.notify
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 LOG", "show Splash configured log monitoring for LOG"
69
+ desc "show LABEL", "show Splash configured log monitoring for LOG"
59
70
  def show(logrecord)
60
- log = get_logger
61
- log_record_set = get_config.logs.select{|item| item[:log] == logrecord or item[:label] == logrecord.to_sym}
62
- unless log_record_set.empty? then
63
- record = log_record_set.first
64
- log.info "Splash log monitor : #{record[:log]}"
65
- log.item "pattern : /#{record[:pattern]}/"
66
- log.item "label : #{record[:label]}"
67
- splash_exit case: :quiet_exit
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: :not_found, :more => "log not configured"
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
- log = get_logger
82
- log.info "Splash configured log monitoring :"
83
- log_record_set = get_config.logs
84
- log.ko 'No configured commands found' if log_record_set.empty?
85
- log_record_set.each do |record|
86
- log.item "log monitor : #{record[:log]} label : #{record[:label]}"
87
- if options[:detail] then
88
- log.arrow "pattern : /#{record[:pattern]}/"
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