prometheus-splash 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54e538fd7e22b4dc38c1253db96c6e842bf81d1378db0434295c0a827e23bfb7
4
- data.tar.gz: c951aaf9aacd398d0944594185fc8d4986de4268162a62cedd69ff0c96d26f9d
3
+ metadata.gz: 3048edcf69c8bac285eab790a497fddbb9a4420a5cee8738ee1397c0a7c39587
4
+ data.tar.gz: adb8f52b4e3b2d808728e092960e648768a45d8fbb66876ca7c585f492516c86
5
5
  SHA512:
6
- metadata.gz: 110950f5ac22753830d8b6f1fd74eaf86d77c78eb18728613215fc671279aa8c6da577ba3d54250640c747c76f35c66cd35ffd2ccb38cfc47d65a7c47e408b2b
7
- data.tar.gz: 18aecf0d1f4f080ec1863ec79e17cc6d0582b5cd7f9efac442162c0095d92658372fa2bad1b3c502dd0e44a731a4fd9fe9710bae3e6a4d00be5759610ad08c1c
6
+ metadata.gz: fd9ed4dc543ea0a81cd163c73988424a87b76a5e094f548900e30ff71db7e8525798d9c824113ecf8972d2e26b6a616d2393a1afb3a1e3caaa8f62ebb331f3dc
7
+ data.tar.gz: 23635fa7711d83e15f8b859d47bdcea3fa4dadc268cb899b46282555b73a2f998bf38614a48ec54997e9fe9986a78098fc2a9c818183be37e7dbd913bc7cfe8a
@@ -47,11 +47,8 @@
47
47
  :stderr_trace: stderr.txt
48
48
  :pid_file: splash.pid
49
49
  :prometheus:
50
- :pushgateway:
51
- :host: "localhost"
52
- :port: 9091
53
- :path: ''
54
- :url: "http://localhost:9090/"
50
+ :pushgateway: 'http://localhost:9091/'
51
+ :url: 'http://localhost:9090/'
55
52
  :webadmin:
56
53
  :port: 9234
57
54
  :ip: 127.0.0.1
@@ -63,7 +60,7 @@
63
60
  :pid_file: splash_webadmin.pid
64
61
 
65
62
 
66
- ### configuration of commands and scheduling
63
+ ### Sample configuration of commands and scheduling
67
64
  :commands:
68
65
  :id_root:
69
66
  :desc: run id command on root
@@ -115,7 +112,7 @@
115
112
  :on_success: :echo3
116
113
 
117
114
 
118
- ### configuration of monitored logs
115
+ ### Sample configuration of monitored logs
119
116
  :logs:
120
117
  - :label: :log_app_1
121
118
  :log: /tmp/test
@@ -124,9 +121,58 @@
124
121
  :log: /tmp/test2
125
122
  :pattern: ERROR
126
123
 
127
-
128
124
  ### configuration of monitored processes
129
125
  :processes:
130
126
  - :process: cron
131
127
  :patterns:
132
128
  - cron
129
+
130
+
131
+ ###
132
+ ## Sample configuration of executions sequences
133
+ :sequences:
134
+ :sample_remote_sequence:
135
+ :definition:
136
+ - :step: execute echo2 on omicron
137
+ :command: :echo2
138
+ :on_host: omicron
139
+ - :step: run locally echo3
140
+ :command: :echo3
141
+ :trace: false
142
+ :sample_local_sequence:
143
+ :definition:
144
+ - :step: run locally pwd without callback
145
+ :command: :pwd
146
+ :callback: false
147
+ - :step: run locally echo3 without Prometheus notifications
148
+ :command: :echo3
149
+ :notify: false
150
+ :sample_local_failed_sequence:
151
+ :options:
152
+ :continue: false
153
+ :definition:
154
+ - :step: run false_test locally without callback
155
+ :command: :false_test
156
+ :callback: false
157
+ - :step: considere this as inefective
158
+ :command: :echo3
159
+ :sample_local_full_sequence:
160
+ :options:
161
+ :continue: true
162
+ :definition:
163
+ - :step: run false_test locally without callback
164
+ :command: :false_test
165
+ :callback: false
166
+ :trace: false
167
+ - :step: considere this as inefective
168
+ :command: :pwd
169
+ :sample_scheduled_sequence:
170
+ :schedule:
171
+ :every: 1m
172
+ :options:
173
+ :continue: true
174
+ :definition:
175
+ - :step: exec echo3
176
+ :command: :echo3
177
+
178
+ ###
@@ -29,6 +29,8 @@ class CLI < Thor
29
29
  include CLISplash
30
30
  desc "commands SUBCOMMAND ...ARGS", "Managing commands/batchs supervision & orchestration"
31
31
  subcommand "commands", Commands
32
+ desc "sequences SUBCOMMAND ...ARGS", "Managing Sequences of commands"
33
+ subcommand "sequences", Sequences
32
34
  desc "logs SUBCOMMAND ...ARGS", "Managing Files/Logs supervision"
33
35
  subcommand "logs", Logs
34
36
  desc "processes SUBCOMMAND ...ARGS", "Managing processes supervision"
@@ -133,7 +133,7 @@ module CLISplash
133
133
  log = get_logger
134
134
  if options[:hostname] then
135
135
  options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
136
- log.info "Remote Splash scheduling command on #{options[:hostname]}:"
136
+ log.info "Remote Splash treeview command on #{options[:hostname]}:"
137
137
  log.info "ctrl+c for interrupt"
138
138
  begin
139
139
  transport = get_default_client
@@ -169,7 +169,7 @@ module CLISplash
169
169
  end
170
170
 
171
171
 
172
- # Thor method : getting the list of avaible commands in splash config
172
+ # Thor method : getting the list of available commands in splash config
173
173
  desc "list", "Show configured commands"
174
174
  long_desc <<-LONGDESC
175
175
  Show configured commands\n
@@ -0,0 +1,112 @@
1
+ # coding: utf-8
2
+
3
+ # module for all Thor subcommands
4
+ module CLISplash
5
+
6
+ # Thor inherited class for sequences management
7
+ class Sequences < Thor
8
+ include Splash::Sequences
9
+ include Splash::Transports
10
+ include Splash::Exiter
11
+ include Splash::Loggers
12
+
13
+
14
+ # Thor method : execute sequence
15
+ option :continue, :type => :boolean, default: true
16
+ long_desc <<-LONGDESC
17
+ Execute a commands Sequence\n
18
+ With --no-continue, stop execution on failure
19
+ LONGDESC
20
+ desc "execute", "Execute a sequence"
21
+ def execute(sequence)
22
+ options[:name] = sequence
23
+ acase = run_as_root :run_seq, options
24
+ splash_exit acase
25
+ end
26
+
27
+
28
+ # Thor method : show sequence
29
+ long_desc <<-LONGDESC
30
+ Show a commands Sequence\n
31
+ LONGDESC
32
+ desc "show", "Show a sequence"
33
+ def show(sequence)
34
+ options = {}
35
+ log = get_logger
36
+ options[:name] = sequence
37
+ acase = run_as_root :show_seq, options
38
+ unless acase[:data].nil? then
39
+ dseq = acase[:data]
40
+ log.item sequence
41
+ unless dseq[:options].nil? then
42
+ log.arrow "Options : "
43
+ log.flat " * continue on failure : #{dseq[:options][:continue]}" unless dseq[:options][:continue].nil?
44
+ end
45
+ log.arrow "Definition :"
46
+ dseq[:definition].each do |step|
47
+ log.flat " * Step name : #{step[:step]}"
48
+ log.flat " => Splash Command to execute : #{step[:command]}"
49
+ log.flat " => Execute remote on host : #{step[:on_host]}" unless step[:on_host].nil?
50
+ log.flat " => Follow Callback : #{step[:callback]}" unless step[:callback].nil?
51
+ log.flat " => Prometheus notification : #{step[:notification]}" unless step[:notification].nil?
52
+ end
53
+ end
54
+ splash_exit acase
55
+ end
56
+
57
+
58
+ # Thor method : getting the list of available sequences in splash config
59
+ desc "list", "Show configured sequences"
60
+ long_desc <<-LONGDESC
61
+ Show configured sequences\n
62
+ with --detail, show command details\n
63
+ LONGDESC
64
+ option :detail, :type => :boolean, :aliases => "-D"
65
+ def list
66
+ acase = run_as_root :list_seq, options
67
+ log = get_logger
68
+ unless acase[:data].nil?
69
+ log.info "Splash configured sequences"
70
+ acase[:data].keys.each do |seq|
71
+ log.item seq
72
+ if options[:detail] then
73
+ dseq = acase[:data][seq]
74
+ unless dseq[:options].nil? then
75
+ log.arrow "Options : "
76
+ log.flat " * continue on failure : #{dseq[:options][:continue]}" unless dseq[:options][:continue].nil?
77
+ end
78
+ log.arrow "Definition :"
79
+ dseq[:definition].each do |step|
80
+ log.flat " * Step name : #{step[:step]}"
81
+ log.flat " => Splash Command to execute : #{step[:command]}"
82
+ log.flat " => Execute remote on host : #{step[:on_host]}" unless step[:on_host].nil?
83
+ log.flat " => Follow Callback : #{step[:callback]}" unless step[:callback].nil?
84
+ log.flat " => Prometheus notification : #{step[:notification]}" unless step[:notification].nil?
85
+ end
86
+ end
87
+ end
88
+ end
89
+ splash_exit acase
90
+ end
91
+
92
+
93
+ # Thor method : scheduling execution of a commands sequences in splash daemon
94
+ desc "schedule", "Schedule a configured sequences execution"
95
+ long_desc <<-LONGDESC
96
+ Schedule excution of command sequence on Splash daemon\n
97
+ with --at TIME/DATE, Schedule at specified date/time, like 2030/12/12 23:30:00 or 12:00 \n
98
+ with --in TIMING, Schedule in specified timing, like 12s, 1m, 2h, 3m10s, 10d\n
99
+ --in and --at are imcompatibles.\n
100
+ WARNING : scheduling by CLI are not percisted, so use it only for specifics cases.\n
101
+ LONGDESC
102
+ option :at, :type => :string
103
+ option :in, :type => :string
104
+ def schedule(sequence)
105
+ options[:sequence] = sequence
106
+ acase = run_as_root :schedule_seq, options
107
+ splash_exit acase
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -26,7 +26,7 @@ module Splash
26
26
  # @param [String] name the name of the command
27
27
  def initialize(name)
28
28
  @config = get_config
29
- @url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}/#{@config.prometheus_pushgateway_path}"
29
+ @url = @config.prometheus_pushgateway_url
30
30
  @name = name
31
31
  unless @config.commands.keys.include? @name.to_sym then
32
32
  splash_exit case: :not_found, more: "command #{@name} is not defined in configuration"
@@ -44,7 +44,7 @@ module Splash
44
44
  # @param [String] time execution time numeric.to_s
45
45
  # @return [Hash] Exiter case :quiet_exit
46
46
  def notify(value,time)
47
- unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
47
+ unless verify_service url: @config.prometheus_pushgateway_url then
48
48
  return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
49
49
  end
50
50
  @@metric_exitcode.set(value)
@@ -84,6 +84,8 @@ module Splash
84
84
  log.receive "return with exitcode #{exit_code}", session
85
85
 
86
86
  end
87
+ rescue Interrupt
88
+ splash_exit case: :interrupt, more: "Remote command exection"
87
89
  end
88
90
  else
89
91
  log.info "Executing command : '#{@name}' ", session
@@ -136,7 +138,6 @@ module Splash
136
138
  log.item "Without Prometheus notification", session
137
139
  end
138
140
  end
139
-
140
141
  if options[:callback] then
141
142
  on_failure = (@config.commands[@name.to_sym][:on_failure])? @config.commands[@name.to_sym][:on_failure] : false
142
143
  on_success = (@config.commands[@name.to_sym][:on_success])? @config.commands[@name.to_sym][:on_success] : false
@@ -23,10 +23,8 @@ module Splash
23
23
  self[:copyright] = "#{COPYRIGHT} #{LICENSE}"
24
24
 
25
25
  self[:prometheus_url] = (config_from_file[:prometheus][:url])? config_from_file[:prometheus][:url] : PROMETHEUS_URL
26
+ self[:prometheus_pushgateway_url] = (config_from_file[:prometheus][:pushgateway])? config_from_file[:prometheus][:pushgateway] : PROMETHEUS_PUSHGATEWAY_URL
26
27
 
27
- self[:prometheus_pushgateway_path] = (config_from_file[:prometheus][:pushgateway][:path])? config_from_file[:prometheus][:pushgateway][:path] : PROMETHEUS_PUSHGATEWAY_PATH
28
- self[:prometheus_pushgateway_host] = (config_from_file[:prometheus][:pushgateway][:host])? config_from_file[:prometheus][:pushgateway][:host] : PROMETHEUS_PUSHGATEWAY_HOST
29
- self[:prometheus_pushgateway_port] = (config_from_file[:prometheus][:pushgateway][:port])? config_from_file[:prometheus][:pushgateway][:port] : PROMETHEUS_PUSHGATEWAY_PORT
30
28
  self[:daemon_process_name] = (config_from_file[:daemon][:process_name])? config_from_file[:daemon][:process_name] : DAEMON_PROCESS_NAME
31
29
  self[:daemon_logmon_scheduling] = (config_from_file[:daemon][:logmon_scheduling])? config_from_file[:daemon][:logmon_scheduling] : DAEMON_LOGMON_SCHEDULING
32
30
  self[:daemon_metrics_scheduling] = (config_from_file[:daemon][:metrics_scheduling])? config_from_file[:daemon][:metrics_scheduling] : DAEMON_METRICS_SCHEDULING
@@ -42,10 +40,12 @@ module Splash
42
40
  self[:webadmin_stderr_trace] = (config_from_file[:webadmin][:files][:stderr_trace])? config_from_file[:webadmin][:files][:stderr_trace] : WEBADMIN_STDERR_TRACE
43
41
 
44
42
 
43
+ self[:pid_path] = (config_from_file[:daemon][:paths][:pid_path])? config_from_file[:daemon][:paths][:pid_path] : PID_PATH
44
+ self[:trace_path] = (config_from_file[:daemon][:paths][:trace_path])? config_from_file[:daemon][:paths][:trace_path] : TRACE_PATH
45
+
46
+
45
47
  self[:execution_template_tokens] = EXECUTION_TEMPLATE_TOKENS_LIST
46
48
  self[:execution_template_path] = (config_from_file[:templates][:execution][:path])? config_from_file[:templates][:execution][:path] : EXECUTION_TEMPLATE
47
- self[:pid_path] = (config_from_file[:daemon][:paths][:pid_path])? config_from_file[:daemon][:paths][:pid_path] : DAEMON_PID_PATH
48
- self[:trace_path] = (config_from_file[:daemon][:paths][:trace_path])? config_from_file[:daemon][:paths][:trace_path] : TRACE_PATH
49
49
  self[:pid_file] = (config_from_file[:daemon][:files][:pid_file])? config_from_file[:daemon][:files][:pid_file] : DAEMON_PID_FILE
50
50
  self[:stdout_trace] = (config_from_file[:daemon][:files][:stdout_trace])? config_from_file[:daemon][:files][:stdout_trace] : DAEMON_STDOUT_TRACE
51
51
  self[:stderr_trace] = (config_from_file[:daemon][:files][:stderr_trace])? config_from_file[:daemon][:files][:stderr_trace] : DAEMON_STDERR_TRACE
@@ -57,6 +57,7 @@ module Splash
57
57
  self[:processes] = (config_from_file[:processes])? config_from_file[:processes] : {}
58
58
  self[:logs] = (config_from_file[:logs])? config_from_file[:logs] : {}
59
59
  self[:commands] = (config_from_file[:commands])? config_from_file[:commands] : {}
60
+ self[:sequences] = (config_from_file[:sequences])? config_from_file[:sequences] : {}
60
61
 
61
62
  end
62
63
 
@@ -180,6 +181,11 @@ module Splash
180
181
  return self[:processes]
181
182
  end
182
183
 
184
+ # getter for sequences Hash Config sample
185
+ # @return [Hash]
186
+ def sequences
187
+ return self[:sequences]
188
+ end
183
189
 
184
190
  # getter for author Config sample
185
191
  # @return [String]
@@ -202,51 +208,42 @@ module Splash
202
208
 
203
209
 
204
210
 
205
- # getter for daemon_process_name Config sample
206
- # @return [String]
207
- def daemon_process_name
208
- return self[:daemon_process_name]
209
- end
210
211
 
211
- # getter for prometheus_pushgateway_host Config sample
212
+ # getter for prometheus_pushgateway_url Config sample
212
213
  # @return [String]
213
- def prometheus_pushgateway_host
214
- return self[:prometheus_pushgateway_host]
214
+ def prometheus_pushgateway_url
215
+ return self[:prometheus_pushgateway_url]
215
216
  end
216
217
 
217
- # getter for prometheus_pushgateway_port Config sample
218
+ # getter for prometheus_url Config sample
218
219
  # @return [String]
219
- def prometheus_pushgateway_port
220
- return self[:prometheus_pushgateway_port]
220
+ def prometheus_url
221
+ return self[:prometheus_url]
221
222
  end
222
223
 
223
- # getter for prometheus_pushgateway_path Config sample
224
- # @return [String]
225
- def prometheus_pushgateway_path
226
- return self[:prometheus_pushgateway_path]
227
- end
228
224
 
229
- # getter for prometheus_url Config sample
225
+ # getter for daemon_process_name Config sample
230
226
  # @return [String]
231
- def prometheus_url
232
- return self[:prometheus_url]
227
+ def daemon_process_name
228
+ return self[:daemon_process_name]
233
229
  end
234
230
 
235
- # getter for full_pid_path Config sample
231
+
232
+ # getter for daemon_full_pid_path Config sample
236
233
  # @return [String]
237
- def full_pid_path
234
+ def daemon_full_pid_path
238
235
  return "#{self[:pid_path]}/#{self[:pid_file]}"
239
236
  end
240
237
 
241
- # getter for full_stdout_trace_path Config sample
238
+ # getter for daemon_full_stdout_trace_path Config sample
242
239
  # @return [String]
243
- def full_stdout_trace_path
240
+ def daemon_full_stdout_trace_path
244
241
  return "#{self[:trace_path]}/#{self[:stdout_trace]}"
245
242
  end
246
243
 
247
- # getter for full_stderr_trace_path Config sample
244
+ # getter for daemon_full_stderr_trace_path Config sample
248
245
  # @return [String]
249
- def full_stderr_trace_path
246
+ def daemon_full_stderr_trace_path
250
247
  return "#{self[:trace_path]}/#{self[:stderr_trace]}"
251
248
  end
252
249
 
@@ -50,7 +50,7 @@ module Splash
50
50
  end
51
51
 
52
52
  target = "Prometheus PushGateway Service running"
53
- if verify_service host: config.prometheus_pushgateway_host ,port: config.prometheus_pushgateway_port then
53
+ if verify_service url: config.prometheus_pushgateway_url then
54
54
  log.ok target
55
55
  else
56
56
  log.ko target
@@ -7,12 +7,14 @@ module Splash
7
7
  module Constants
8
8
 
9
9
  # Current splash version
10
- VERSION = "0.6.0"
10
+ VERSION = "0.6.1"
11
11
 
12
12
  # the path to th config file, not overridable by config
13
13
  CONFIG_FILE = "/etc/splash.yml"
14
14
  # the default execution trace_path if backend file
15
15
  TRACE_PATH="/var/run/splash"
16
+ # the default pid file path
17
+ PID_PATH="/var/run"
16
18
 
17
19
 
18
20
  # default scheduling criteria for log monitoring
@@ -24,8 +26,6 @@ module Splash
24
26
 
25
27
  # the display name of daemon in proc info (ps/top)
26
28
  DAEMON_PROCESS_NAME="Splash : daemon."
27
- # the default pid file path
28
- DAEMON_PID_PATH="/var/run"
29
29
  # the default pid file name
30
30
  DAEMON_PID_FILE="splash.pid"
31
31
  # the default sdtout trace file
@@ -42,15 +42,11 @@ module Splash
42
42
  # type of licence
43
43
  LICENSE="BSD-2-Clause"
44
44
 
45
- # the default prometheus pushgateway host
46
- PROMETHEUS_PUSHGATEWAY_HOST = "localhost"
47
- # the default prometheus pushgateway port
48
- PROMETHEUS_PUSHGATEWAY_PORT = "9091"
49
- # the default prometheus pushgateway port
50
- PROMETHEUS_PUSHGATEWAY_PATH = ''
45
+ # the default prometheus pushgateway URL
46
+ PROMETHEUS_PUSHGATEWAY_URL = 'http://localhost:9090/'
51
47
 
52
48
  # the default prometheus URL
53
- PROMETHEUS_URL = "http://localhost:9090"
49
+ PROMETHEUS_URL = "http://localhost:9090/"
54
50
 
55
51
  # the default path fo execution report template
56
52
  EXECUTION_TEMPLATE="/etc/splash_execution_report.tpl"
@@ -26,7 +26,7 @@ module Splash
26
26
  config = get_config
27
27
  log = get_logger
28
28
  log.level = :fatal if options[:quiet]
29
- unless verify_service host: config.prometheus_pushgateway_host ,port: config.prometheus_pushgateway_port then
29
+ unless verify_service url: config.prometheus_pushgateway_url then
30
30
  return {:case => :service_dependence_missing, :more => 'Prometheus Gateway'}
31
31
  end
32
32
  realpid = get_processes pattern: get_config.daemon_process_name
@@ -35,7 +35,7 @@ module Splash
35
35
  return {:case => :already_exist, :more => "Splash Process already launched on foreground "}
36
36
  end
37
37
 
38
- unless File::exist? config.full_pid_path then
38
+ unless File::exist? config.daemon_full_pid_path then
39
39
  unless realpid.empty? then
40
40
  return {:case => :already_exist, :more => "Splash Process already launched "}
41
41
  end
@@ -50,9 +50,9 @@ module Splash
50
50
  end
51
51
  end
52
52
  daemon_config = {:description => config.daemon_process_name,
53
- :pid_file => config.full_pid_path,
54
- :stdout_trace => config.full_stdout_trace_path,
55
- :stderr_trace => config.full_stderr_trace_path,
53
+ :pid_file => config.daemon_full_pid_path,
54
+ :stdout_trace => config.daemon_full_stdout_trace_path,
55
+ :stderr_trace => config.daemon_full_stderr_trace_path,
56
56
  :foreground => options[:foreground]
57
57
  }
58
58
 
@@ -62,7 +62,7 @@ module Splash
62
62
  end
63
63
  sleep 1
64
64
  if res == 0 then
65
- pid = `cat #{config.full_pid_path}`.to_i
65
+ pid = `cat #{config.daemon_full_pid_path}`.to_i
66
66
  log.ok "Splash Daemon Started, with PID : #{pid}"
67
67
  return {:case => :quiet_exit, :more => "Splash Daemon successfully loaded."}
68
68
  else
@@ -82,15 +82,15 @@ module Splash
82
82
  config = get_config
83
83
  log = get_logger
84
84
  log.level = :fatal if options[:quiet]
85
- if File.exist?(config.full_pid_path) then
85
+ if File.exist?(config.daemon_full_pid_path) then
86
86
  begin
87
- pid = `cat #{config.full_pid_path}`.to_i
87
+ pid = `cat #{config.daemon_full_pid_path}`.to_i
88
88
  Process.kill("TERM", pid)
89
89
  acase = {:case => :quiet_exit, :more => 'Splash stopped succesfully'}
90
90
  rescue Errno::ESRCH
91
91
  acase = {:case => :not_found, :more => "Process of PID : #{pid} not found"}
92
92
  end
93
- FileUtils::rm config.full_pid_path if File::exist? config.full_pid_path
93
+ FileUtils::rm config.daemon_full_pid_path if File::exist? config.daemon_full_pid_path
94
94
  else
95
95
  acase = {:case => :not_found, :more => "Splash is not running"}
96
96
  end
@@ -104,7 +104,7 @@ module Splash
104
104
  log = get_logger
105
105
  config = get_config
106
106
  pid = realpid = ''
107
- pid = `cat #{config.full_pid_path}`.to_s if File.exist?(config.full_pid_path)
107
+ pid = `cat #{config.daemon_full_pid_path}`.to_s if File.exist?(config.daemon_full_pid_path)
108
108
  listpid = get_processes({ :pattern => get_config.daemon_process_name})
109
109
  pid.chomp!
110
110
  if listpid.empty? then
@@ -76,7 +76,7 @@ module Splash
76
76
  def notify
77
77
  log = get_logger
78
78
  session = get_session
79
- unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
79
+ unless verify_service url: @config.prometheus_pushgateway_url then
80
80
  return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
81
81
  end
82
82
 
@@ -87,7 +87,7 @@ module Splash
87
87
  @metric_processes_monitoring.set monitoring_processes_count
88
88
 
89
89
  hostname = Socket.gethostname
90
- url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}/#{@config.prometheus_pushgateway_path}"
90
+ url = @config.prometheus_pushgateway_url
91
91
  Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
92
92
  log.debug "Sending to Prometheus PushGateway done.", session
93
93
  return {:case => :quiet_exit }
@@ -21,6 +21,7 @@ module Splash
21
21
  include Splash::Logs
22
22
  include Splash::Processes
23
23
  include Splash::Commands
24
+ include Splash::Sequences
24
25
 
25
26
  # Constructor prepare the Scheduler
26
27
  # commands Schedules
@@ -42,6 +43,7 @@ module Splash
42
43
  if options[:scheduling] then
43
44
  @log.item "Initializing commands Scheduling."
44
45
  init_commands_scheduling
46
+ init_sequences_scheduling
45
47
  end
46
48
 
47
49
  if @config.logs.empty? then
@@ -140,6 +142,25 @@ module Splash
140
142
 
141
143
  end
142
144
 
145
+
146
+ # prepare sequences Scheduling
147
+ def init_sequences_scheduling
148
+ config = get_config.sequences
149
+ sequences = config.select{|key,value| value.include? :schedule}.keys
150
+ sequences.each do |sequence|
151
+ sched,value = config[sequence][:schedule].flatten
152
+ @log.arrow "Scheduling sequence #{sequence.to_s}"
153
+ @server.send sched,value do
154
+ session = get_session
155
+ @log.trigger "Executing Scheduled sequence #{sequence.to_s} for Scheduling : #{sched.to_s} #{value.to_s}", session
156
+ run_seq name: sequence.to_s, session: session
157
+ end
158
+ end
159
+
160
+ end
161
+
162
+
163
+
143
164
  # execute_command verb : execute command specified in payload
144
165
  # @param [Hash] options
145
166
  # @option options [Symbol] :command the name of the command
@@ -147,7 +168,7 @@ module Splash
147
168
  # @return [Hash] Exiter case
148
169
  def execute(options)
149
170
  command = CommandWrapper::new(options[:command])
150
- if options[:ack] then
171
+ if options[:ack] then
151
172
  else
152
173
  @metric_manager.inc_execution
153
174
  return command.call_and_notify trace: true, notify: true, callback: true, session: options[:session]
@@ -13,6 +13,7 @@ module Splash
13
13
  require 'etc'
14
14
  require 'forwardable'
15
15
  require 'json'
16
+ require 'uri'
16
17
 
17
18
 
18
19
 
@@ -55,6 +56,8 @@ module Splash
55
56
 
56
57
 
57
58
  require 'splash/commands'
59
+ require 'splash/sequences'
60
+
58
61
  require 'splash/logs'
59
62
  require 'splash/processes'
60
63
 
@@ -310,11 +310,20 @@ module Splash
310
310
  # @param [Hash] options
311
311
  # @option options [String] :host hostname
312
312
  # @option options [String] :port TCP port
313
+ # @option options [String] :url full URL, priority on :host and :port
313
314
  def verify_service(options ={})
314
315
  begin
316
+ if options[:url] then
317
+ uri = URI.parse(options[:url])
318
+ host = uri.host
319
+ port = uri.port
320
+ else
321
+ host = options[:host]
322
+ port = options[:port]
323
+ end
315
324
  Timeout::timeout(1) do
316
325
  begin
317
- s = TCPSocket.new(options[:host], options[:port])
326
+ s = TCPSocket.new(host, port)
318
327
  s.close
319
328
  return true
320
329
  rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
@@ -56,7 +56,7 @@ module Splash
56
56
  # @return [Hash] Exiter case :quiet_exit
57
57
  def notify(options = {})
58
58
  log = get_logger
59
- unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
59
+ unless verify_service url: @config.prometheus_pushgateway_url then
60
60
  return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
61
61
  end
62
62
  session = (options[:session]) ? options[:session] : log.get_session
@@ -70,7 +70,7 @@ module Splash
70
70
  @metric_lines.set(lines, labels: { log: item[:log] })
71
71
  end
72
72
  hostname = Socket.gethostname
73
- url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}/#{@config.prometheus_pushgateway_path}"
73
+ url = @config.prometheus_pushgateway_url
74
74
  Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
75
75
  log.ok "Sending to Prometheus PushGateway done.", session
76
76
  return {:case => :quiet_exit }
@@ -58,7 +58,7 @@ module Splash
58
58
  # @return [Hash] Exiter case :quiet_exit
59
59
  def notify(options = {})
60
60
  log = get_logger
61
- unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
61
+ unless verify_service url: @config.prometheus_pushgateway_url then
62
62
  return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
63
63
  end
64
64
  session = (options[:session]) ? options[:session] : log.get_session
@@ -72,7 +72,7 @@ module Splash
72
72
  @metric_mem_percent.set(item[:mem], labels: { process: item[:process] })
73
73
  end
74
74
  hostname = Socket.gethostname
75
- url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}/#{@config.prometheus_pushgateway_path}"
75
+ url = @config.prometheus_pushgateway_url
76
76
  Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
77
77
  log.ok "Sending to Prometheus PushGateway done.", session
78
78
  return {:case => :quiet_exit }
@@ -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
@@ -100,7 +100,6 @@ module Splash
100
100
  condition = ConditionVariable.new
101
101
  get_default_subscriber(queue: queue).subscribe do |delivery_info, properties, payload|
102
102
  res = YAML::load(payload)
103
-
104
103
  lock.synchronize { condition.signal }
105
104
  end
106
105
  get_logger.send "Verb : #{order[:verb].to_s} to queue : #{order[:queue]}."
@@ -29,7 +29,7 @@ module Splash
29
29
  realpid = get_processes pattern: get_config.webadmin_process_name
30
30
 
31
31
 
32
- unless File::exist? config.full_pid_path then
32
+ unless File::exist? config.webadmin_full_pid_path then
33
33
  unless realpid.empty? then
34
34
  return {:case => :already_exist, :more => "Splash WebAdmin Process already launched "}
35
35
  end
@@ -11,8 +11,8 @@ class WebAdminApp < Sinatra::Base
11
11
  set :port, get_config.webadmin_port
12
12
  set :bind, get_config.webadmin_ip
13
13
  set :static, :enable
14
- set :public_folder, 'lib/splash/webadmin/portal/public'
15
- set :views, "lib/splash/webadmin/portal/views"
14
+ set :public_folder, search_file_in_gem("prometheus-splash", 'lib/splash/webadmin/portal/public')
15
+ set :views, search_file_in_gem("prometheus-splash", "lib/splash/webadmin/portal/views")
16
16
 
17
17
  before do
18
18
  rehash_config
@@ -1,9 +1,7 @@
1
1
 
2
2
 
3
3
  WebAdminApp.use Rack::ReverseProxy do
4
- config = get_config
5
- url = "http://#{config.prometheus_pushgateway_host}:#{config.prometheus_pushgateway_port}/#{config.prometheus_pushgateway_path}"
6
- reverse_proxy /^\/pushgateway\/?(.*)$/, url
4
+ reverse_proxy /^\/pushgateway\/?(.*)$/, get_config.prometheus_pushgateway_url
7
5
  reverse_proxy_options preserve_host: true
8
6
  end
9
7
 
@@ -23,8 +21,8 @@ WebAdminApp.get '/proxy/links' do
23
21
  @prometheus_url = "http://#{config.webadmin_ip}:#{config.webadmin_port}/prometheus"
24
22
  else
25
23
  @proxy = false
26
- @pushgateway_url = "http://#{config.prometheus_pushgateway_host}:#{config.prometheus_pushgateway_port}/#{config.prometheus_pushgateway_path}"
27
- @prometheus_url = "http://#{config.prometheus_url}"
24
+ @pushgateway_url = "#{config.prometheus_pushgateway_url}"
25
+ @prometheus_url = "#{config.prometheus_url}"
28
26
  end
29
27
  slim :proxy, :format => :html
30
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus-splash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain GEORGES
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-07 00:00:00.000000000 Z
11
+ date: 2020-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -350,6 +350,7 @@ files:
350
350
  - lib/splash/cli/documentation.rb
351
351
  - lib/splash/cli/logs.rb
352
352
  - lib/splash/cli/process.rb
353
+ - lib/splash/cli/sequences.rb
353
354
  - lib/splash/cli/webadmin.rb
354
355
  - lib/splash/commands.rb
355
356
  - lib/splash/config.rb
@@ -374,6 +375,7 @@ files:
374
375
  - lib/splash/loggers/web.rb
375
376
  - lib/splash/logs.rb
376
377
  - lib/splash/processes.rb
378
+ - lib/splash/sequences.rb
377
379
  - lib/splash/templates.rb
378
380
  - lib/splash/transports.rb
379
381
  - lib/splash/transports/rabbitmq.rb