prometheus-splash 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -0
  3. data/README.md +58 -60
  4. data/bin/splash +3 -0
  5. data/config/splash.yml +77 -7
  6. data/lib/splash/backends.rb +6 -0
  7. data/lib/splash/backends/file.rb +40 -0
  8. data/lib/splash/backends/redis.rb +47 -4
  9. data/lib/splash/cli.rb +18 -5
  10. data/lib/splash/cli/commands.rb +26 -18
  11. data/lib/splash/cli/config.rb +16 -2
  12. data/lib/splash/cli/daemon.rb +10 -3
  13. data/lib/splash/cli/documentation.rb +5 -2
  14. data/lib/splash/cli/logs.rb +25 -16
  15. data/lib/splash/cli/process.rb +103 -0
  16. data/lib/splash/cli/sequences.rb +114 -0
  17. data/lib/splash/cli/webadmin.rb +46 -0
  18. data/lib/splash/commands.rb +146 -122
  19. data/lib/splash/config.rb +166 -14
  20. data/lib/splash/config/flush.rb +30 -0
  21. data/lib/splash/config/sanitycheck.rb +7 -2
  22. data/lib/splash/config/service.rb +8 -1
  23. data/lib/splash/config/setup.rb +8 -3
  24. data/lib/splash/constants.rb +37 -8
  25. data/lib/splash/daemon.rb +6 -0
  26. data/lib/splash/{controller.rb → daemon/controller.rb} +34 -14
  27. data/lib/splash/daemon/metrics.rb +103 -0
  28. data/lib/splash/daemon/orchestrator.rb +182 -0
  29. data/lib/splash/daemon/orchestrator/grammar.rb +76 -0
  30. data/lib/splash/daemon/orchestrator/hooks.rb +28 -0
  31. data/lib/splash/dependencies.rb +16 -2
  32. data/lib/splash/exiter.rb +14 -0
  33. data/lib/splash/helpers.rb +84 -48
  34. data/lib/splash/loggers.rb +40 -13
  35. data/lib/splash/loggers/cli.rb +18 -3
  36. data/lib/splash/loggers/daemon.rb +14 -3
  37. data/lib/splash/loggers/dual.rb +35 -2
  38. data/lib/splash/loggers/web.rb +51 -0
  39. data/lib/splash/logs.rb +67 -54
  40. data/lib/splash/processes.rb +83 -0
  41. data/lib/splash/sequences.rb +105 -0
  42. data/lib/splash/templates.rb +10 -0
  43. data/lib/splash/transports.rb +9 -0
  44. data/lib/splash/transports/rabbitmq.rb +33 -4
  45. data/lib/splash/webadmin.rb +122 -0
  46. data/lib/splash/webadmin/api/routes/commands.rb +28 -0
  47. data/lib/splash/webadmin/api/routes/config.rb +10 -0
  48. data/lib/splash/webadmin/api/routes/init.rb +2 -0
  49. data/lib/splash/webadmin/api/routes/logs.rb +59 -0
  50. data/lib/splash/webadmin/api/routes/process.rb +60 -0
  51. data/lib/splash/webadmin/api/routes/sequences.rb +28 -0
  52. data/lib/splash/webadmin/main.rb +26 -0
  53. data/lib/splash/webadmin/portal/controllers/commands.rb +7 -0
  54. data/lib/splash/webadmin/portal/controllers/documentation.rb +6 -0
  55. data/lib/splash/webadmin/portal/controllers/home.rb +12 -0
  56. data/lib/splash/webadmin/portal/controllers/logs.rb +14 -0
  57. data/lib/splash/webadmin/portal/controllers/notfound.rb +5 -0
  58. data/lib/splash/webadmin/portal/controllers/processes.rb +14 -0
  59. data/lib/splash/webadmin/portal/controllers/proxy.rb +28 -0
  60. data/lib/splash/webadmin/portal/controllers/restclient.rb +19 -0
  61. data/lib/splash/webadmin/portal/controllers/sequences.rb +7 -0
  62. data/lib/splash/webadmin/portal/init.rb +11 -0
  63. data/lib/splash/webadmin/portal/public/css/ultragreen.css +8544 -0
  64. data/lib/splash/webadmin/portal/public/fonts/FontAwesome.otf +0 -0
  65. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.ttf +0 -0
  66. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff +0 -0
  67. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff2 +0 -0
  68. data/lib/splash/webadmin/portal/public/images/logo_splash.png +0 -0
  69. data/lib/splash/webadmin/portal/public/images/logo_splash_reduce.png +0 -0
  70. data/lib/splash/webadmin/portal/public/images/logo_splash_tiny.png +0 -0
  71. data/lib/splash/webadmin/portal/views/commands.slim +49 -0
  72. data/lib/splash/webadmin/portal/views/documentation.slim +3 -0
  73. data/lib/splash/webadmin/portal/views/home.slim +78 -0
  74. data/lib/splash/webadmin/portal/views/layout.slim +43 -0
  75. data/lib/splash/webadmin/portal/views/logs.slim +32 -0
  76. data/lib/splash/webadmin/portal/views/nav.slim +17 -0
  77. data/lib/splash/webadmin/portal/views/not_found.slim +3 -0
  78. data/lib/splash/webadmin/portal/views/processes.slim +29 -0
  79. data/lib/splash/webadmin/portal/views/proxy.slim +13 -0
  80. data/lib/splash/webadmin/portal/views/restclient.slim +41 -0
  81. data/lib/splash/webadmin/portal/views/restclient_result.slim +29 -0
  82. data/lib/splash/webadmin/portal/views/sequences.slim +50 -0
  83. data/prometheus-splash.gemspec +7 -1
  84. data/spec/helpers_spec.rb +119 -0
  85. data/templates/ansible-splash/roles/splash/handlers/main.yml +4 -0
  86. data/templates/ansible-splash/roles/splash/tasks/main.yml +24 -1
  87. data/templates/ansible-splash/roles/splash/templates/logrotate.splash.j2 +11 -0
  88. data/templates/ansible-splash/roles/splash/templates/splash.yml.j2 +1 -1
  89. metadata +145 -10
  90. data/lib/splash/orchestrator.rb +0 -100
  91. data/lib/splash/orchestrator/grammar.rb +0 -54
  92. data/lib/splash/orchestrator/hooks.rb +0 -16
@@ -1,11 +1,17 @@
1
1
  # coding: utf-8
2
+
3
+ # base Splash module
2
4
  module Splash
5
+
6
+ # Splash Loggers module
3
7
  module Loggers
4
8
 
9
+ # Cli specific logger
5
10
  class Cli < Splash::Loggers::LoggerTemplate
6
11
 
7
12
  include Splash::Config
8
13
 
14
+ # mapping of UTf-8 emoji for log levels or alias
9
15
  EMOJI = { :unknown => "\u{1F4A5}",
10
16
  :fatal => "\u{26D4}",
11
17
  :error => "\u{1F6AB}",
@@ -22,6 +28,7 @@ module Splash
22
28
  :success => "\u{1F4AA}",
23
29
  :debug => "\u{1F41B}"}
24
30
 
31
+ # mapping of colors for log levels or alias
25
32
  COLORS = { :unknown => :red,
26
33
  :fatal => :red,
27
34
  :error => :red,
@@ -39,7 +46,11 @@ module Splash
39
46
  :debug => :magenta}
40
47
 
41
48
 
42
-
49
+ # log wrapper
50
+ # @param [Hash] options
51
+ # @option options [Symbol] :level defined in Splash::Loggers::LEVEL or Splash::Loggers::ALIAS
52
+ # @option options [String] :message
53
+ # display formatted string to STDOUT
43
54
  def log(options)
44
55
  level = (ALIAS.keys.include? options[:level])? ALIAS[options[:level]] : options[:level]
45
56
  if @active_levels.include? level then
@@ -59,14 +70,20 @@ module Splash
59
70
  end
60
71
  end
61
72
 
73
+ # setter in configuration for emoji display
74
+ # @param [Boolean] status
62
75
  def emoji=(status)
63
76
  get_config.loggers[:cli][:emoji] = status
64
77
  end
65
78
 
79
+ # setter in configuration for color display
80
+ # @param [Boolean] status
66
81
  def color=(status)
67
82
  get_config.loggers[:cli][:color] = status
68
83
  end
69
84
 
85
+ # check if unicode must be used with term ENV
86
+ # @return [Boolean]
70
87
  def check_unicode_term
71
88
  return false unless ENV.include? "TERM"
72
89
  if ENV.values_at("LC_ALL","LC_CTYPE","LANG").compact.first.include?("UTF-8") and ENV.values_at('TERM').first.include? "xterm" then
@@ -78,7 +95,5 @@ module Splash
78
95
 
79
96
  end
80
97
 
81
- class BadLevel < Exception; end
82
-
83
98
  end
84
99
  end
@@ -1,12 +1,17 @@
1
1
  # coding: utf-8
2
+
3
+ # base Splash module
2
4
  module Splash
3
- module Loggers
4
5
 
6
+ # Splash Loggers module
7
+ module Loggers
5
8
 
9
+ # Daemon specific logger
6
10
  class Daemon < Splash::Loggers::LoggerTemplate
7
11
 
8
12
 
9
-
13
+ # contructor, open log file
14
+ # @return [Splash::Loggers::Daemon]
10
15
  def initialize
11
16
  self.level = get_config.loggers[:level]
12
17
  @log_file = get_config.loggers[:daemon][:file]
@@ -14,7 +19,12 @@ module Splash
14
19
  @stream.sync = true
15
20
  end
16
21
 
17
-
22
+ # log wrapper
23
+ # @param [Hash] options
24
+ # @option options [Symbol] :level defined in Splash::Loggers::LEVEL or Splash::Loggers::ALIAS
25
+ # @option options [String] :message
26
+ # @option options [String] :session a session number
27
+ # write formatted string to log file
18
28
  def log(options)
19
29
  pid = Process.pid.to_s
20
30
  date = DateTime.now.to_s
@@ -28,6 +38,7 @@ module Splash
28
38
  end
29
39
  end
30
40
 
41
+ # close log file descriptor
31
42
  def close
32
43
  @stream.close
33
44
  end
@@ -1,11 +1,31 @@
1
+ # coding: utf-8
2
+
3
+ # base Splash module
1
4
  module Splash
5
+
6
+ # Splash Loggers module
2
7
  module Loggers
3
8
 
4
- class Dual < Splash::Loggers::LoggerTemplate
5
- include Splash::Config
9
+ # Dual multiplexer specific logger
10
+ # log against CLi and Daemon
11
+ class Dual #< Splash::Loggers::LoggerTemplate
6
12
 
7
13
 
14
+ include Splash::Config
15
+
16
+ # build levels and alias forwarders
17
+ LEVELS.each do |method|
18
+ define_method(method) do |message,session = ''|
19
+ self.log({ :level => method, :message => message, :session => session})
20
+ end
21
+ end
22
+ ALIAS.keys.each do |method|
23
+ define_method(method) do |message,session = ''|
24
+ self.log({ :level => method, :message => message, :session => session})
25
+ end
26
+ end
8
27
 
28
+ # Constructor build two attributes for each loggers : Cli, Daemon
9
29
  def initialize
10
30
  super
11
31
  @log1 = Splash::Loggers::Cli::new
@@ -17,6 +37,19 @@ module Splash
17
37
  @log2.log options
18
38
  end
19
39
 
40
+ # getter for root level
41
+ # @return [Symbol] a level
42
+ def level
43
+ @level
44
+ end
45
+
46
+ # setter for global level, both Cli and Daemon
47
+ # @param [Symbol] level a level in Splash::Loggers::LEVELS or Splash::Loggers::ALIAS
48
+ def level=(level)
49
+ @level = level
50
+ @log1.level=level
51
+ @log2.level=level
52
+ end
20
53
  end
21
54
  end
22
55
  end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+
3
+ # base Splash module
4
+ module Splash
5
+
6
+ # Splash Loggers module
7
+ module Loggers
8
+
9
+ # Web specific logger
10
+ class Web < Splash::Loggers::LoggerTemplate
11
+
12
+
13
+ # contructor, open log file
14
+ # @return [Splash::Loggers::Web]
15
+ def initialize
16
+ self.level = get_config.loggers[:level]
17
+ @log_file = get_config.loggers[:web][:file]
18
+ @stream = File::open(@log_file, 'a')
19
+ @stream.sync = true
20
+ end
21
+
22
+ # log wrapper
23
+ # @param [Hash] options
24
+ # @option options [Symbol] :level defined in Splash::Loggers::LEVEL or Splash::Loggers::ALIAS
25
+ # @option options [String] :message
26
+ # @option options [String] :session a session number
27
+ # write formatted string to log file
28
+ def log(options)
29
+ pid = Process.pid.to_s
30
+ date = DateTime.now.to_s
31
+ level = (ALIAS.keys.include? options[:level])? ALIAS[options[:level]] : options[:level]
32
+ if @active_levels.include? level then
33
+ unless options[:session].empty? then
34
+ @stream.puts "[#{date}] (#{pid}) (#{options[:session]}) #{alt(options[:level])} : #{options[:message]}"
35
+ else
36
+ @stream.puts "[#{date}] (#{pid}) #{alt(options[:level])} : #{options[:message]}"
37
+ end
38
+ end
39
+ end
40
+
41
+ # close log file descriptor
42
+ def close
43
+ @stream.close
44
+ end
45
+
46
+
47
+
48
+ end
49
+
50
+ end
51
+ end
@@ -1,68 +1,81 @@
1
1
  # coding: utf-8
2
+
3
+ # base Splash module
2
4
  module Splash
3
- class LogScanner
4
- include Splash::Constants
5
- include Splash::Config
6
5
 
6
+ # Logs namespace
7
+ module Logs
7
8
 
8
- # LogScanner Constructor
9
- # return [LogScanner]
10
- def initialize
11
- @logs_target = get_config.logs
12
- @config = get_config
13
- @registry = Prometheus::Client.registry
14
- @metric_count = Prometheus::Client::Gauge.new(:logerrors, docstring: 'SPLASH metric log error', labels: [:log ])
15
- @metric_missing = Prometheus::Client::Gauge.new(:logmissing, docstring: 'SPLASH metric log missing', labels: [:log ])
16
- @metric_lines = Prometheus::Client::Gauge.new(:loglines, docstring: 'SPLASH metric log lines numbers', labels: [:log ])
17
- @registry.register(@metric_count)
18
- @registry.register(@metric_missing)
19
- @registry.register(@metric_lines)
20
- end
9
+ # Log scanner and notifier
10
+ class LogScanner
11
+ include Splash::Constants
12
+ include Splash::Config
21
13
 
22
14
 
23
- # start log analyse for log target in config
24
- def analyse
25
- @logs_target.each do |record|
26
- record[:count]=0 if record[:count].nil?
27
- record[:status] = :clean if record[:status].nil?
28
- if File.exist?(record[:log]) then
29
- record[:count] = File.readlines(record[:log]).grep(/#{record[:pattern]}/).size
30
- record[:status] = :matched if record[:count] > 0
31
- record[:lines] = `wc -l "#{record[:log]}"`.strip.split(/\s+/)[0].to_i unless record[:status] == :missing
32
- else
33
- record[:status] = :missing
34
- end
15
+ # LogScanner Constructor : initialize prometheus metrics
16
+ # return [Splash::Logs::LogScanner]
17
+ def initialize
18
+ @logs_target = Marshal.load(Marshal.dump(get_config.logs))
19
+ @config = get_config
20
+ @registry = Prometheus::Client::Registry::new
21
+ @metric_count = Prometheus::Client::Gauge.new(:logerrors, docstring: 'SPLASH metric log error', labels: [:log ])
22
+ @metric_missing = Prometheus::Client::Gauge.new(:logmissing, docstring: 'SPLASH metric log missing', labels: [:log ])
23
+ @metric_lines = Prometheus::Client::Gauge.new(:loglines, docstring: 'SPLASH metric log lines numbers', labels: [:log ])
24
+ @registry.register(@metric_count)
25
+ @registry.register(@metric_missing)
26
+ @registry.register(@metric_lines)
35
27
  end
36
- return {:case => :quiet_exit }
37
- end
38
28
 
39
- # pseudo-accessor on @logs_target
40
- def output
41
- return @logs_target
42
- end
43
29
 
44
- # start notification on prometheus for metric logerrors, logmissing; loglines
45
- def notify(options = {})
46
- log = get_logger
47
- unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
48
- return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
30
+ # start log analyse for log target in config
31
+ # @return [Hash] Exiter case :quiet_exit
32
+ def analyse
33
+ @logs_target.each do |record|
34
+ record[:count]=0 if record[:count].nil?
35
+ record[:status] = :clean if record[:status].nil?
36
+ if File.exist?(record[:log]) then
37
+ record[:count] = File.readlines(record[:log]).grep(/#{record[:pattern]}/).size
38
+ record[:status] = :matched if record[:count] > 0
39
+ record[:lines] = `wc -l "#{record[:log]}"`.strip.split(/\s+/)[0].to_i unless record[:status] == :missing
40
+ else
41
+ record[:status] = :missing
42
+ end
43
+ end
44
+ return {:case => :quiet_exit }
49
45
  end
50
- session = (options[:session]) ? options[:session] : log.get_session
51
- log.info "Sending metrics to Prometheus Pushgateway", session
52
- @logs_target.each do |item|
53
- missing = (item[:status] == :missing)? 1 : 0
54
- log.item "Sending metrics for #{item[:log]}", session
55
- @metric_count.set(item[:count], labels: { log: item[:log] })
56
- @metric_missing.set(missing, labels: { log: item[:log] })
57
- lines = (item[:lines])? item[:lines] : 0
58
- @metric_lines.set(lines, labels: { log: item[:log] })
46
+
47
+ # pseudo-accessor on @logs_target
48
+ # @return [Hash] the logs structure
49
+ def output
50
+ return @logs_target
51
+ end
52
+
53
+ # start notification on prometheus for metric logerrors, logmissing; loglines
54
+ # @param [Hash] options
55
+ # @option options [String] :session a session number for log daemon
56
+ # @return [Hash] Exiter case :quiet_exit
57
+ def notify(options = {})
58
+ log = get_logger
59
+ unless verify_service url: @config.prometheus_pushgateway_url then
60
+ return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
61
+ end
62
+ session = (options[:session]) ? options[:session] : log.get_session
63
+ log.info "Sending metrics to Prometheus Pushgateway", session
64
+ @logs_target.each do |item|
65
+ missing = (item[:status] == :missing)? 1 : 0
66
+ log.item "Sending metrics for #{item[:log]}", session
67
+ @metric_count.set(item[:count], labels: { log: item[:log] })
68
+ @metric_missing.set(missing, labels: { log: item[:log] })
69
+ lines = (item[:lines])? item[:lines] : 0
70
+ @metric_lines.set(lines, labels: { log: item[:log] })
71
+ end
72
+ hostname = Socket.gethostname
73
+ url = @config.prometheus_pushgateway_url
74
+ Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
75
+ log.ok "Sending to Prometheus PushGateway done.", session
76
+ return {:case => :quiet_exit }
59
77
  end
60
- hostname = Socket.gethostname
61
- url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}"
62
- Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
63
- log.ok "Sending to Prometheus PushGateway done.", session
64
- return {:case => :quiet_exit }
65
- end
66
78
 
79
+ end
67
80
  end
68
81
  end
@@ -0,0 +1,83 @@
1
+ # coding: utf-8
2
+
3
+ # base Splash Module
4
+ module Splash
5
+
6
+ # Processes namespace
7
+ module Processes
8
+
9
+ # Processes scanner and notifier
10
+ class ProcessScanner
11
+ include Splash::Constants
12
+ include Splash::Config
13
+
14
+
15
+ # ProcessScanner Constructor : initialize prometheus metrics
16
+ # @return [Splash::Processes::ProcessScanner]
17
+ def initialize
18
+ @processes_target = Marshal.load(Marshal.dump(get_config.processes))
19
+ @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
+ end
29
+
30
+
31
+ # start process analyse for process target in config
32
+ # @return [Hash] Exiter case :quiet_exit
33
+ def analyse
34
+ @processes_target.each do |record|
35
+ list = get_processes patterns: record[:patterns], full: true
36
+ if list.empty?
37
+ record[:status] = :inexistant
38
+ record[:cpu] = 0
39
+ record[:mem] = 0
40
+ else
41
+ record[:status] = :running
42
+ record[:cpu] = list[0]['%CPU']
43
+ record[:mem] = list[0]['%MEM']
44
+ end
45
+ end
46
+ return {:case => :quiet_exit }
47
+ end
48
+
49
+ # pseudo-accessor on @processes_target
50
+ # @return [Hash] the processes structure
51
+ def output
52
+ return @processes_target
53
+ end
54
+
55
+ # start notification on prometheus for metrics
56
+ # @param [Hash] options
57
+ # @option options [String] :session a session number for log daemon
58
+ # @return [Hash] Exiter case :quiet_exit
59
+ def notify(options = {})
60
+ log = get_logger
61
+ unless verify_service url: @config.prometheus_pushgateway_url then
62
+ return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
63
+ end
64
+ session = (options[:session]) ? options[:session] : log.get_session
65
+ log.info "Sending metrics to Prometheus Pushgateway", session
66
+ @processes_target.each do |item|
67
+ missing = (item[:status] == :missing)? 1 : 0
68
+ log.item "Sending metrics for #{item[:process]}", session
69
+ val = (item[:status] == :running )? 1 : 0
70
+ @metric_status.set(val, labels: { process: item[:process] })
71
+ @metric_cpu_percent.set(item[:cpu], labels: { process: item[:process] })
72
+ @metric_mem_percent.set(item[:mem], labels: { process: item[:process] })
73
+ 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
+ return {:case => :quiet_exit }
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,105 @@
1
+ # coding: utf-8
2
+
3
+ # base Splash module
4
+ module Splash
5
+
6
+ # Splash Commands module/namespace
7
+ module Sequences
8
+
9
+ include Splash::Commands
10
+ include Splash::Config
11
+ include Splash::Loggers
12
+ include Splash::Exiter
13
+ include Splash::Transports
14
+
15
+ def run_seq(params = {})
16
+ list = get_config.sequences
17
+ name = params[:name].to_sym
18
+ acase = {}
19
+ seq_res = []
20
+ log = get_logger
21
+ log.info "beginnning Sequence execution : #{name}"
22
+ session = (params[:session])? params[:session] : get_session
23
+ if list.include? name then
24
+ seq_options = (list[name][:options].nil?)? {} : list[name][:options]
25
+ list[name][:definition].each do |step|
26
+ log.info "STEP : #{step[:step]}",session
27
+ if step[:on_host].nil? then
28
+ command = CommandWrapper::new(step[:command].to_s)
29
+ step[:callback] = true if step[:callback].nil?
30
+ step[:trace] = true if step[:trace].nil?
31
+ step[:notify] = true if step[:notify].nil?
32
+ step[:session] = session
33
+ acase = command.call_and_notify step
34
+ else
35
+ log.info "Remote execution of #{step[:command]} on #{step[:on_host]}", session
36
+ begin
37
+ transport = get_default_client
38
+ if transport.class == Hash and transport.include? :case then
39
+ return transport
40
+ else
41
+ acase = transport.execute({ :verb => :execute_command,
42
+ payload: {:name => step[:command].to_s},
43
+ :return_to => "splash.#{Socket.gethostname}.return",
44
+ :queue => "splash.#{step[:on_host]}.input" })
45
+ log.receive "return with exitcode #{acase[:exit_code]}", session
46
+ end
47
+ rescue Interrupt
48
+ acase = { case: :interrupt, more: "Remote command exection", exit_code: 33}
49
+ end
50
+
51
+ end
52
+ seq_res.push acase[:exit_code]
53
+ continue = (seq_options[:continue].nil?)? true : seq_options[:continue]
54
+ if acase[:exit_code] > 0 and continue == false then
55
+ acase[:more] = "Break execution on error, continue = false"
56
+ break
57
+ end
58
+ end
59
+ else
60
+ return { :case => :not_found, :more => "Sequence #{name} not configured" }
61
+ end
62
+
63
+ if seq_res.select {|res| res > 0}.count == seq_res.count then
64
+ acase = { case: :status_ko, more: "all execution failed" }
65
+ elsif seq_res.select {|res| res > 0}.count > 0 then
66
+ acase = { case: :status_ko, more: "some execution failed" }
67
+ else
68
+ acase = { case: :status_ok, more: "all execution successed" }
69
+ end
70
+ acase[:more] << " with remote call interrupt" if seq_res.include?(33)
71
+ return acase
72
+ end
73
+
74
+
75
+ def list_seq(options = {})
76
+ list = get_config.sequences
77
+ unless list.empty?
78
+ acase = { :case => :quiet_exit , :more => "List configured sequences"}
79
+ acase[:data] = list
80
+ return acase
81
+ else
82
+ return { :case => :not_found, :more => 'No sequences configured' }
83
+ end
84
+ end
85
+
86
+ def show_seq(options = {})
87
+ list = get_config.sequences
88
+ name = options[:name].to_sym
89
+ if list.include? name then
90
+ acase = { :case => :quiet_exit, :more => "Show specific sequence : #{name}"}
91
+ acase[:data] = list[name]
92
+ else
93
+ return { :case => :not_found, :more => "Sequence #{name} not configured" }
94
+ end
95
+ return acase
96
+ end
97
+
98
+ def schedule_seq(options = {})
99
+ acase = { :case => :quiet_exit, :more => "schedule" }
100
+ return acase
101
+
102
+ end
103
+
104
+ end
105
+ end