prometheus-splash 0.8.3 → 0.8.6

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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -4
  3. data/README.md +400 -178
  4. data/config/splash.yml +15 -13
  5. data/lib/splash/backends/file.rb +1 -1
  6. data/lib/splash/backends.rb +7 -1
  7. data/lib/splash/cli/commands.rb +45 -80
  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 +34 -2
  11. data/lib/splash/cli/process.rb +33 -0
  12. data/lib/splash/cli/webadmin.rb +2 -1
  13. data/lib/splash/commands.rb +31 -22
  14. data/lib/splash/config/flush.rb +2 -2
  15. data/lib/splash/config.rb +15 -8
  16. data/lib/splash/constants.rb +1 -1
  17. data/lib/splash/daemon/orchestrator/grammar.rb +1 -1
  18. data/lib/splash/daemon/orchestrator.rb +6 -7
  19. data/lib/splash/dependencies.rb +1 -0
  20. data/lib/splash/logs.rb +5 -1
  21. data/lib/splash/monkeys.rb +5 -0
  22. data/lib/splash/processes.rb +4 -0
  23. data/lib/splash/sequences.rb +6 -1
  24. data/lib/splash/webadmin/api/routes/commands.rb +13 -1
  25. data/lib/splash/webadmin/api/routes/config.rb +95 -8
  26. data/lib/splash/webadmin/api/routes/process.rb +21 -9
  27. data/lib/splash/webadmin/main.rb +15 -1
  28. data/lib/splash/webadmin/portal/controllers/commands.rb +99 -1
  29. data/lib/splash/webadmin/portal/controllers/logs.rb +31 -4
  30. data/lib/splash/webadmin/portal/controllers/processes.rb +74 -4
  31. data/lib/splash/webadmin/portal/views/command_form.slim +45 -0
  32. data/lib/splash/webadmin/portal/views/command_history.slim +27 -0
  33. data/lib/splash/webadmin/portal/views/commands.slim +69 -19
  34. data/lib/splash/webadmin/portal/views/{logs_form.slim → log_form.slim} +3 -0
  35. data/lib/splash/webadmin/portal/views/log_history.slim +24 -0
  36. data/lib/splash/webadmin/portal/views/logs.slim +34 -7
  37. data/lib/splash/webadmin/portal/views/process_form.slim +24 -0
  38. data/lib/splash/webadmin/portal/views/process_history.slim +24 -0
  39. data/lib/splash/webadmin/portal/views/processes.slim +79 -6
  40. data/lib/splash/webadmin.rb +3 -1
  41. data/prometheus-splash.gemspec +1 -1
  42. data/templates/.env +0 -0
  43. data/templates/Dockerfile +5 -0
  44. data/templates/docker-compose.yml +14 -0
  45. metadata +18 -9
data/config/splash.yml CHANGED
@@ -73,49 +73,51 @@
73
73
 
74
74
  ### Sample configuration of commands and scheduling
75
75
  :commands:
76
- :id_root:
76
+ - :name: :id_root
77
77
  :desc: run id command on root
78
78
  :command: id root
79
- :true_test:
79
+ - :name: :true_test
80
80
  :desc: "test command returning true : 0"
81
81
  :command: "true"
82
82
  :schedule:
83
83
  :every: "1h"
84
84
  :on_failure: :ls_slash_tmp
85
85
  :on_success: :pwd
86
- :false_test:
86
+ - :name: :false_test
87
87
  :desc: "test command returning false > 0"
88
88
  :command: "false"
89
89
  :schedule:
90
90
  :every: "1h"
91
91
  :on_failure: :ls_slash_tmp
92
92
  :on_success: :pwd
93
- :ls_slash_tmp:
93
+ - :name: :ls_slash_tmp
94
94
  :desc: list file in /tmp
95
95
  :command: ls -al /tmp
96
96
  :user: daemon
97
97
  :on_success: :echo1
98
- :pwd:
98
+ - :name: :pwd
99
99
  :desc: run pwd
100
100
  :command: pwd
101
101
  :on_success: :echo1
102
102
  :on_failure: :echo2
103
- :echo1:
103
+ - :name: :echo1
104
104
  :desc: echo 'foo'
105
105
  :command: echo foo
106
106
  :on_failure: :echo3
107
- :echo2:
107
+ - :name: :echo2
108
108
  :desc: echo 'bar'
109
109
  :command: echo bar
110
- :echo3:
110
+ - :name: :echo3
111
111
  :desc: echo 'been'
112
112
  :command: echo been
113
- :rand_sleep_5:
113
+ - :name: :rand_sleep_5
114
114
  :desc: sleep on a rand 5
115
115
  :command: ruby -e 'sleep rand(5)'
116
116
  :schedule:
117
- :every: "10s"
118
- :test_remote_call:
117
+ :every: "30s"
118
+ :retention:
119
+ :hours: 1
120
+ - :name: :test_remote_call
119
121
  :desc: remote call test
120
122
  :delegate_to:
121
123
  :host: omicron
@@ -138,11 +140,11 @@
138
140
 
139
141
  ### configuration of monitored processes
140
142
  :processes:
141
- - :process: cron
143
+ - :process: :cron
142
144
  :patterns:
143
145
  - cron
144
146
  :retention:
145
- :hours: 5
147
+ :hours: 5
146
148
 
147
149
 
148
150
  ###
@@ -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
@@ -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
@@ -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
@@ -125,7 +125,7 @@ module CLISplash
125
125
  end
126
126
 
127
127
  # Thor method : getting a treeview of sequence of commands
128
- desc "treeview", "Show commands sequence tree"
128
+ desc "treeview COMMAND", "Show commands sequence tree"
129
129
  long_desc <<-LONGDESC
130
130
  Show commands sequence tree\n
131
131
  with --hostname, ask other Splash daemon via transport\n
@@ -159,7 +159,7 @@ module CLISplash
159
159
  end
160
160
  log.info "Command : #{command.to_s}" if depht == 0
161
161
  aproc = Proc::new do |command,depht|
162
- cmd = commands[command.to_sym]
162
+ cmd = commands.select{|item| item[:name] == command.to_sym}.first
163
163
  if cmd[:on_failure] then
164
164
  spacer= " " * depht + " "
165
165
  log.flat "#{spacer}* on failure => #{cmd[:on_failure]}"
@@ -211,16 +211,16 @@ module CLISplash
211
211
  list = get_config.commands
212
212
  end
213
213
  log.info "Splash configured commands :"
214
- log.ko 'No configured commands found' if list.keys.empty?
215
- list.keys.each do |command|
216
- 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}"
217
217
  if options[:detail] then
218
- log.arrow "command line : '#{list[command][:command]}'"
219
- log.arrow "command description : '#{list[command][:desc]}'"
220
- log.arrow "command failure callback : '#{list[command.to_sym][:on_failure]}'" if list[command.to_sym][:on_failure]
221
- log.arrow "command success callback : '#{list[command.to_sym][:on_success]}'" if list[command.to_sym][:on_success]
222
- if list[command.to_sym][:schedule]
223
- 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
224
224
  log.arrow "command scheduled : #{sched} #{val}."
225
225
  end
226
226
  end
@@ -235,7 +235,7 @@ module CLISplash
235
235
  with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)
236
236
  LONGDESC
237
237
  option :hostname, :type => :string, :aliases => "-H"
238
- def show(command)
238
+ def show(name)
239
239
  unless is_root? then
240
240
  splash_exit case: :not_root, :more => "Command show specifications"
241
241
  end
@@ -261,14 +261,15 @@ module CLISplash
261
261
  else
262
262
  list = get_config.commands
263
263
  end
264
- if list.keys.include? command.to_sym then
265
- log.info "Splash command : #{command}"
266
- log.item "command line : '#{list[command.to_sym][:command]}'"
267
- log.item "command description : '#{list[command.to_sym][:desc]}'"
268
- log.item "command failure callback : '#{list[command.to_sym][:on_failure]}'" if list[command.to_sym][:on_failure]
269
- log.item "command success callback : '#{list[command.to_sym][:on_success]}'" if list[command.to_sym][:on_success]
270
- if list[command.to_sym][:schedule]
271
- 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
272
273
  log.item "command scheduled : #{sched} #{val}."
273
274
  end
274
275
  splash_exit case: :quiet_exit
@@ -284,11 +285,11 @@ module CLISplash
284
285
  show commands executions history for LABEL\n
285
286
  LONGDESC
286
287
  option :table, :type => :boolean, :aliases => "-t"
287
- desc "history LABEL", "show commands executions history"
288
+ desc "history COMMAND", "show commands executions history"
288
289
  def history(command)
289
290
  if is_root? then
290
291
  log = get_logger
291
- log.info "Log : #{command}#"
292
+ log.info "Command : #{command}"
292
293
  config = get_config
293
294
  if options[:table] then
294
295
  table = TTY::Table.new do |t|
@@ -301,7 +302,7 @@ module CLISplash
301
302
  value[:end_date],
302
303
  value[:exec_time],
303
304
  value[:stdout].empty?,
304
- value[:stdout].empty?]
305
+ value[:stderr].empty?]
305
306
  end
306
307
  end
307
308
  if check_unicode_term then
@@ -328,52 +329,8 @@ module CLISplash
328
329
  end
329
330
  end
330
331
 
331
- # Thor method : getting information on the last execution of a command
332
- desc "lastrun COMMAND", "Show last running result for specific configured command COMMAND"
333
- long_desc <<-LONGDESC
334
- Show last running result for specific configured command COMMAND\n
335
- with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)
336
- LONGDESC
337
- option :hostname, :type => :string, :aliases => "-H"
338
- def lastrun(command)
339
- unless is_root? then
340
- splash_exit case: :not_root, :more => "Command last execution report"
341
- end
342
- log = get_logger
343
- backend = get_backend :execution_trace
344
- redis = (backend.class == Splash::Backends::Redis)? true : false
345
- if not redis and options[:hostname] then
346
- splash_exit case: :specific_config_required, :more => "Redis backend is requiered for Remote execution report request"
347
- end
348
- splash_exit case: :not_root if not is_root? and not redis
349
- list = get_config.commands.keys
350
- if options[:hostname] then
351
- options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
352
- list = backend.list("*", options[:hostname]).map(&:to_sym)
353
- end
354
- if list.include? command.to_sym then
355
- log.info "Splash command #{command} previous execution report:\n"
356
- req = { :key => command}
357
- req[:hostname] = options[:hostname] if options[:hostname]
358
- if backend.exist? req then
359
- res = backend.get req
360
- tp = Template::new(
361
- list_token: get_config.execution_template_tokens,
362
- template_file: get_config.execution_template_path)
363
- tp.map YAML::load(res).last.values.first
364
- log.flat tp.output
365
- else
366
- log.ko "Command not already runned."
367
- end
368
- splash_exit case: :quiet_exit
369
- else
370
- splash_exit case: :not_found, :more => "Command report never runned remotly" if options[:hostname]
371
- end
372
- end
373
-
374
-
375
332
  # Thor method : getting information on one specific execution of a command
376
- desc "onerun COMMAND", "Show running result for specific configured command COMMAND"
333
+ desc "get_result COMMAND", "Show running result for specific configured command COMMAND"
377
334
  long_desc <<-LONGDESC
378
335
  Show specific running result for specific configured command COMMAND\n
379
336
  with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)
@@ -381,8 +338,8 @@ module CLISplash
381
338
 
382
339
  LONGDESC
383
340
  option :hostname, :type => :string, :aliases => "-H"
384
- option :date, :type => :string, :aliases => "-D", :required => true
385
- def onerun(command)
341
+ option :date, :type => :string, :aliases => "-D"
342
+ def get_result(command)
386
343
  unless is_root? then
387
344
  splash_exit case: :not_root, :more => "Command specific execution report"
388
345
  end
@@ -393,12 +350,12 @@ module CLISplash
393
350
  splash_exit case: :specific_config_required, :more => "Redis backend is requiered for Remote execution report request"
394
351
  end
395
352
  splash_exit case: :not_root if not is_root? and not redis
396
- list = get_config.commands.keys
353
+ list = get_config.commands
397
354
  if options[:hostname] then
398
355
  options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
399
356
  list = backend.list("*", options[:hostname]).map(&:to_sym)
400
357
  end
401
- if list.include? command.to_sym then
358
+ if list.select{|cmd| cmd[:name] == command.to_sym}.count > 0 then
402
359
  log.info "Splash command #{command} previous execution report:\n"
403
360
  req = { :key => command}
404
361
  req[:hostname] = options[:hostname] if options[:hostname]
@@ -407,11 +364,15 @@ module CLISplash
407
364
  tp = Template::new(
408
365
  list_token: get_config.execution_template_tokens,
409
366
  template_file: get_config.execution_template_path)
410
- prov = YAML::load(res).select{|key,value| key.keys.first == options[:date]}
411
- if prov.empty? then
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
412
373
  log.ko "Command not runned one this date or date misformatted."
413
374
  else
414
- tp.map prov.first.values.first
375
+ tp.map prov.values.first
415
376
  log.flat tp.output
416
377
  end
417
378
  else
@@ -419,12 +380,16 @@ module CLISplash
419
380
  end
420
381
  splash_exit case: :quiet_exit
421
382
  else
422
- 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
423
388
  end
424
389
  end
425
390
 
426
391
  # Thor method : getting the list of avaibles executions reports
427
- desc "getreportlist", "list all executions report results "
392
+ desc "reportlist", "list all executions report results "
428
393
  long_desc <<-LONGDESC
429
394
  list all executions report results\n
430
395
  with --pattern <SEARCH>, search type string, wilcard * (group) ? (char)\n
@@ -437,7 +402,7 @@ module CLISplash
437
402
  option :hostname, :type => :string, :aliases => "-H"
438
403
  option :all, :type => :boolean, :negate => false, :aliases => "-A"
439
404
  option :detail, :type => :boolean, :aliases => "-D"
440
- def getreportlist
405
+ def reportlist
441
406
  unless is_root? then
442
407
  splash_exit case: :not_root, :more => "Command execution report list"
443
408
  end
@@ -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"
@@ -63,10 +63,10 @@ module CLISplash
63
63
  end
64
64
 
65
65
 
66
-
66
+
67
67
 
68
68
  # Thor method : display a specific Splash configured log monitor
69
- desc "show LOG", "show Splash configured log monitoring for LOG"
69
+ desc "show LABEL", "show Splash configured log monitoring for LOG"
70
70
  def show(logrecord)
71
71
  if is_root? then
72
72
  log = get_logger
@@ -110,6 +110,38 @@ module CLISplash
110
110
  end
111
111
  end
112
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
113
145
 
114
146
  # Thor method : show logs monitoring history
115
147
  long_desc <<-LONGDESC
@@ -114,6 +114,39 @@ module CLISplash
114
114
  end
115
115
  end
116
116
 
117
+ # Thor method : display the full list of Splash configured process monitors
118
+ desc "get_result PROCESS", "Get last or specific process monitoring report"
119
+ long_desc <<-LONGDESC
120
+ Get last or specific process monitoring report\n
121
+ with --date <DATE>, a date format string (same as in history ouput)
122
+ LONGDESC
123
+ option :date, :type => :string, :aliases => "-D"
124
+ def get_result(process)
125
+ if is_root? then
126
+ log = get_logger
127
+ log.info "Process : #{process}"
128
+ config = get_config
129
+ records = ProcessRecords::new(process).get_all_records
130
+ if options[:date] then
131
+ wanted = records.select{|key,value| key.keys.first == options[:date]}.first
132
+ else
133
+ wanted = records.last
134
+ end
135
+ if wanted.nil? then
136
+ splash_exit case: :not_found, more: "Process never monitored"
137
+ else
138
+ record =wanted.keys.first
139
+ value=wanted[record]
140
+ log.item record
141
+ log.arrow "Status : #{value[:status].to_s}"
142
+ log.arrow "CPU Percent : #{value[:cpu_percent]}"
143
+ log.arrow "MEM Percent : #{value[:mem_percent]}"
144
+ end
145
+ else
146
+ splash_exit case: :not_root, :more => "Process get result"
147
+ end
148
+ end
149
+
117
150
 
118
151
  # Thor method : show logs monitoring history
119
152
  long_desc <<-LONGDESC
@@ -35,9 +35,10 @@ module CLISplash
35
35
  long_desc <<-LONGDESC
36
36
  Starting Splash Daemon\n
37
37
  LONGDESC
38
+ option :foreground, :type => :boolean, :aliases => "-F"
38
39
  desc "start", "Splash WebAdmin Daemon status"
39
40
  def start
40
- acase = run_as_root :startweb
41
+ acase = run_as_root :startweb, options
41
42
  splash_exit acase
42
43
  end
43
44
 
@@ -48,6 +48,11 @@ module Splash
48
48
  @backend = get_backend :execution_trace
49
49
  end
50
50
 
51
+
52
+ def clear
53
+ @backend.del({:key => @name}) if @backend.exist?({key: @name})
54
+ end
55
+
51
56
  def purge(retention)
52
57
  retention = {} if retention.nil?
53
58
  if retention.include? :hours then
@@ -96,7 +101,7 @@ module Splash
96
101
  @config = get_config
97
102
  @url = @config.prometheus_pushgateway_url
98
103
  @name = name
99
- unless @config.commands.keys.include? @name.to_sym then
104
+ unless @config.commands.select{|cmd| cmd[:name] == @name.to_sym }.count > 0 then
100
105
  splash_exit case: :not_found, more: "command #{@name} is not defined in configuration"
101
106
  end
102
107
  end
@@ -139,18 +144,20 @@ module Splash
139
144
  session = (options[:session])? options[:session] : get_session
140
145
  acase = { :case => :quiet_exit }
141
146
  exit_code = 0
142
- if @config.commands[@name.to_sym][:delegate_to] then
147
+ command = @config.commands.select{|command| command[:name] == @name.to_sym}.first
148
+ if command[:delegate_to] then
143
149
  return { :case => :options_incompatibility, :more => '--hostname forbidden with delagate commands'} if options[:hostname]
144
- log.send "Remote command : #{@name} execution delegate to : #{@config.commands[@name.to_sym][:delegate_to][:host]} as : #{@config.commands[@name.to_sym][:delegate_to][:remote_command]}", session
150
+ log.send "Remote command : #{@name} execution delegate to : #{command[:delegate_to][:host]} as : #{command[:delegate_to][:remote_command]}", session
151
+ log.warn "Local command : #{command[:command]} defined but ignored, because delegate have the priority"
145
152
  begin
146
153
  transport = get_default_client
147
154
  if transport.class == Hash and transport.include? :case then
148
155
  return transport
149
156
  else
150
157
  res = transport.execute({ :verb => :execute_command,
151
- payload: {:name => @config.commands[@name.to_sym][:delegate_to][:remote_command].to_s},
158
+ payload: {:name => command[:delegate_to][:remote_command].to_s},
152
159
  :return_to => "splash.#{Socket.gethostname}.return",
153
- :queue => "splash.#{@config.commands[@name.to_sym][:delegate_to][:host]}.input" })
160
+ :queue => "splash.#{command[:delegate_to][:host]}.input" })
154
161
  exit_code = res[:exit_code]
155
162
  log.receive "return with exitcode #{exit_code}", session
156
163
 
@@ -164,35 +171,35 @@ module Splash
164
171
  start_date = DateTime.now.to_s
165
172
  unless options[:trace] then
166
173
  log.item "Traceless execution", session
167
- if @config.commands[@name.to_sym][:user] then
168
- log.item "Execute with user : #{@config.commands[@name.to_sym][:user]}.", session
169
- system("sudo -u #{@config.commands[@name.to_sym][:user]} #{@config.commands[@name.to_sym][:command]} > /dev/null 2>&1")
174
+ if command[:user] then
175
+ log.item "Execute with user : #{command[:user]}.", session
176
+ system("sudo -u #{command[:user]} #{command[:command]} > /dev/null 2>&1")
170
177
  else
171
- system("#{@config.commands[@name.to_sym][:command]} > /dev/null 2>&1")
178
+ system("#{command[:command]} > /dev/null 2>&1")
172
179
  end
173
180
  time = Time.now - start
174
181
  exit_code = $?.exitstatus
175
182
  else
176
183
  log.item "Tracefull execution", session
177
- if @config.commands[@name.to_sym][:user] then
178
- log.item "Execute with user : #{@config.commands[@name.to_sym][:user]}.", session
179
- stdout, stderr, status = Open3.capture3("sudo -u #{@config.commands[@name.to_sym][:user]} #{@config.commands[@name.to_sym][:command]}")
184
+ if command[:user] then
185
+ log.item "Execute with user : #{command[:user]}.", session
186
+ stdout, stderr, status = Open3.capture3("sudo -u #{command[:user]} #{command[:command]}")
180
187
  else
181
- stdout, stderr, status = Open3.capture3(@config.commands[@name.to_sym][:command])
188
+ stdout, stderr, status = Open3.capture3(command[:command])
182
189
  end
183
190
  time = Time.now - start
184
191
  data = Hash::new
185
192
  data[:start_date] = start_date
186
193
  data[:end_date] = DateTime.now.to_s
187
194
  data[:cmd_name] = @name
188
- data[:cmd_line] = @config.commands[@name.to_sym][:command]
189
- data[:desc] = @config.commands[@name.to_sym][:desc]
195
+ data[:cmd_line] = command[:command]
196
+ data[:desc] = command[:desc]
190
197
  data[:status] = status.to_s
191
198
  data[:stdout] = stdout
192
199
  data[:stderr] = stderr
193
200
  data[:exec_time] = time.to_s
194
201
  cmdrec = CmdRecords::new @name
195
- cmdrec.purge(@config.commands[@name.to_sym][:retention])
202
+ cmdrec.purge(command[:retention])
196
203
  cmdrec.add_record data
197
204
  exit_code = status.exitstatus
198
205
  end
@@ -205,24 +212,26 @@ module Splash
205
212
  end
206
213
  end
207
214
  if options[:callback] then
208
- on_failure = (@config.commands[@name.to_sym][:on_failure])? @config.commands[@name.to_sym][:on_failure] : false
209
- on_success = (@config.commands[@name.to_sym][:on_success])? @config.commands[@name.to_sym][:on_success] : false
215
+ on_failure = (command[:on_failure])? command[:on_failure] : false
216
+ on_success = (command[:on_success])? command[:on_success] : false
210
217
  if on_failure and exit_code > 0 then
211
218
  log.item "On failure callback : #{on_failure}", session
212
- if @config.commands.keys.include? on_failure then
219
+ if @config.commands.select {|item| item[:name] == on_failure}.count > 0 then
213
220
  @name = on_failure.to_s
214
221
  call_and_notify options
215
222
  else
216
- acase = { :case => :configuration_error , :more => "on_failure call error : #{on_failure} command inexistant."}
223
+ log.error "on_failure call error : #{on_failure.to_s} command inexistant.", session
224
+ acase = { :case => :configuration_error , :more => "Command #{command[:name]} callback coniguration error"}
217
225
  end
218
226
  end
219
227
  if on_success and exit_code == 0 then
220
228
  log.item "On success callback : #{on_success}", session
221
- if @config.commands.keys.include? on_success then
229
+ if @config.commands.select {|item| item[:name] == on_success}.count > 0 then
222
230
  @name = on_success.to_s
223
231
  call_and_notify options
224
232
  else
225
- acase = { :case => :configuration_error , :more => "on_success call error : #{on_failure} command inexistant."}
233
+ log.error "on_success call error : #{on_success.to_s} command inexistant."
234
+ acase = { :case => :configuration_error , :more => "Command #{command[:name]} callback coniguration error"}
226
235
  end
227
236
  end
228
237
  else
@@ -16,8 +16,8 @@ module Splash
16
16
  self.extend Splash::Backends
17
17
  self.extend Splash::Loggers
18
18
  log = get_logger
19
- log.info "Splash backend flushing"
20
- name = (options[:name])? options[:name] : :execution_trace
19
+ name = (options[:name])? options[:name].to_sym : :execution_trace
20
+ log.info "Splash backend #{name.to_s} flushing"
21
21
  backend = get_backend name
22
22
  if backend.flush then
23
23
  return { :case => :quiet_exit, :more => "Splash backend #{name.to_s} flushed" }