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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +44 -0
- data/README.md +58 -60
- data/bin/splash +3 -0
- data/config/splash.yml +77 -7
- data/lib/splash/backends.rb +6 -0
- data/lib/splash/backends/file.rb +40 -0
- data/lib/splash/backends/redis.rb +47 -4
- data/lib/splash/cli.rb +18 -5
- data/lib/splash/cli/commands.rb +26 -18
- data/lib/splash/cli/config.rb +16 -2
- data/lib/splash/cli/daemon.rb +10 -3
- data/lib/splash/cli/documentation.rb +5 -2
- data/lib/splash/cli/logs.rb +25 -16
- data/lib/splash/cli/process.rb +103 -0
- data/lib/splash/cli/sequences.rb +114 -0
- data/lib/splash/cli/webadmin.rb +46 -0
- data/lib/splash/commands.rb +146 -122
- data/lib/splash/config.rb +166 -14
- data/lib/splash/config/flush.rb +30 -0
- data/lib/splash/config/sanitycheck.rb +7 -2
- data/lib/splash/config/service.rb +8 -1
- data/lib/splash/config/setup.rb +8 -3
- data/lib/splash/constants.rb +37 -8
- data/lib/splash/daemon.rb +6 -0
- data/lib/splash/{controller.rb → daemon/controller.rb} +34 -14
- data/lib/splash/daemon/metrics.rb +103 -0
- data/lib/splash/daemon/orchestrator.rb +182 -0
- data/lib/splash/daemon/orchestrator/grammar.rb +76 -0
- data/lib/splash/daemon/orchestrator/hooks.rb +28 -0
- data/lib/splash/dependencies.rb +16 -2
- data/lib/splash/exiter.rb +14 -0
- data/lib/splash/helpers.rb +84 -48
- data/lib/splash/loggers.rb +40 -13
- data/lib/splash/loggers/cli.rb +18 -3
- data/lib/splash/loggers/daemon.rb +14 -3
- data/lib/splash/loggers/dual.rb +35 -2
- data/lib/splash/loggers/web.rb +51 -0
- data/lib/splash/logs.rb +67 -54
- data/lib/splash/processes.rb +83 -0
- data/lib/splash/sequences.rb +105 -0
- data/lib/splash/templates.rb +10 -0
- data/lib/splash/transports.rb +9 -0
- data/lib/splash/transports/rabbitmq.rb +33 -4
- data/lib/splash/webadmin.rb +122 -0
- data/lib/splash/webadmin/api/routes/commands.rb +28 -0
- data/lib/splash/webadmin/api/routes/config.rb +10 -0
- data/lib/splash/webadmin/api/routes/init.rb +2 -0
- data/lib/splash/webadmin/api/routes/logs.rb +59 -0
- data/lib/splash/webadmin/api/routes/process.rb +60 -0
- data/lib/splash/webadmin/api/routes/sequences.rb +28 -0
- data/lib/splash/webadmin/main.rb +26 -0
- data/lib/splash/webadmin/portal/controllers/commands.rb +7 -0
- data/lib/splash/webadmin/portal/controllers/documentation.rb +6 -0
- data/lib/splash/webadmin/portal/controllers/home.rb +12 -0
- data/lib/splash/webadmin/portal/controllers/logs.rb +14 -0
- data/lib/splash/webadmin/portal/controllers/notfound.rb +5 -0
- data/lib/splash/webadmin/portal/controllers/processes.rb +14 -0
- data/lib/splash/webadmin/portal/controllers/proxy.rb +28 -0
- data/lib/splash/webadmin/portal/controllers/restclient.rb +19 -0
- data/lib/splash/webadmin/portal/controllers/sequences.rb +7 -0
- data/lib/splash/webadmin/portal/init.rb +11 -0
- data/lib/splash/webadmin/portal/public/css/ultragreen.css +8544 -0
- data/lib/splash/webadmin/portal/public/fonts/FontAwesome.otf +0 -0
- data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff +0 -0
- data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff2 +0 -0
- data/lib/splash/webadmin/portal/public/images/logo_splash.png +0 -0
- data/lib/splash/webadmin/portal/public/images/logo_splash_reduce.png +0 -0
- data/lib/splash/webadmin/portal/public/images/logo_splash_tiny.png +0 -0
- data/lib/splash/webadmin/portal/views/commands.slim +49 -0
- data/lib/splash/webadmin/portal/views/documentation.slim +3 -0
- data/lib/splash/webadmin/portal/views/home.slim +78 -0
- data/lib/splash/webadmin/portal/views/layout.slim +43 -0
- data/lib/splash/webadmin/portal/views/logs.slim +32 -0
- data/lib/splash/webadmin/portal/views/nav.slim +17 -0
- data/lib/splash/webadmin/portal/views/not_found.slim +3 -0
- data/lib/splash/webadmin/portal/views/processes.slim +29 -0
- data/lib/splash/webadmin/portal/views/proxy.slim +13 -0
- data/lib/splash/webadmin/portal/views/restclient.slim +41 -0
- data/lib/splash/webadmin/portal/views/restclient_result.slim +29 -0
- data/lib/splash/webadmin/portal/views/sequences.slim +50 -0
- data/prometheus-splash.gemspec +7 -1
- data/spec/helpers_spec.rb +119 -0
- data/templates/ansible-splash/roles/splash/handlers/main.yml +4 -0
- data/templates/ansible-splash/roles/splash/tasks/main.yml +24 -1
- data/templates/ansible-splash/roles/splash/templates/logrotate.splash.j2 +11 -0
- data/templates/ansible-splash/roles/splash/templates/splash.yml.j2 +1 -1
- metadata +145 -10
- data/lib/splash/orchestrator.rb +0 -100
- data/lib/splash/orchestrator/grammar.rb +0 -54
- data/lib/splash/orchestrator/hooks.rb +0 -16
@@ -0,0 +1,6 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/daemon/orchestrator.rb'
|
3
|
+
require File.dirname(__FILE__) + '/daemon/metrics.rb'
|
4
|
+
require File.dirname(__FILE__) + '/daemon/controller.rb'
|
5
|
+
|
6
|
+
# Dir[File.dirname(__FILE__) + '/daemon/*.rb'].each {|file| require file }
|
@@ -1,19 +1,32 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
require 'splash/daemon/orchestrator'
|
3
|
+
|
4
|
+
# base Splash module
|
2
5
|
module Splash
|
3
|
-
|
4
|
-
|
6
|
+
|
7
|
+
# global daemon module
|
8
|
+
module Daemon
|
9
|
+
|
10
|
+
# Daemon Controller Module
|
11
|
+
module Controller
|
5
12
|
include Splash::Constants
|
6
13
|
include Splash::Helpers
|
7
14
|
include Splash::Config
|
8
|
-
include Splash::Orchestrator
|
9
15
|
include Splash::Exiter
|
10
16
|
include Splash::Loggers
|
17
|
+
include Splash::Daemon::Orchestrator
|
11
18
|
|
19
|
+
# Start the Splash Daemon
|
20
|
+
# @param [Hash] options
|
21
|
+
# @option options [Symbol] :quiet activate quiet mode for log (limit to :fatal)
|
22
|
+
# @option options [Symbol] :foreground run daemon in foreground
|
23
|
+
# @option options [Symbol] :purge clean input queue for daemon on configured transport
|
24
|
+
# @return [Hash] Exiter Case (:quiet_exit, :already_exist, :unknown_error or other)
|
12
25
|
def startdaemon(options = {})
|
13
26
|
config = get_config
|
14
27
|
log = get_logger
|
15
28
|
log.level = :fatal if options[:quiet]
|
16
|
-
unless verify_service
|
29
|
+
unless verify_service url: config.prometheus_pushgateway_url then
|
17
30
|
return {:case => :service_dependence_missing, :more => 'Prometheus Gateway'}
|
18
31
|
end
|
19
32
|
realpid = get_processes pattern: get_config.daemon_process_name
|
@@ -22,7 +35,7 @@ module Splash
|
|
22
35
|
return {:case => :already_exist, :more => "Splash Process already launched on foreground "}
|
23
36
|
end
|
24
37
|
|
25
|
-
unless File::exist? config.
|
38
|
+
unless File::exist? config.daemon_full_pid_path then
|
26
39
|
unless realpid.empty? then
|
27
40
|
return {:case => :already_exist, :more => "Splash Process already launched "}
|
28
41
|
end
|
@@ -37,19 +50,19 @@ module Splash
|
|
37
50
|
end
|
38
51
|
end
|
39
52
|
daemon_config = {:description => config.daemon_process_name,
|
40
|
-
:pid_file => config.
|
41
|
-
:stdout_trace => config.
|
42
|
-
:stderr_trace => config.
|
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,
|
43
56
|
:foreground => options[:foreground]
|
44
57
|
}
|
45
58
|
|
46
|
-
["int","term","hup"].each do |type| daemon_config["sig#{type}_handler".to_sym] = Proc::new { ObjectSpace.each_object(Splash::Orchestrator::Scheduler).first.
|
59
|
+
["int","term","hup"].each do |type| daemon_config["sig#{type}_handler".to_sym] = Proc::new { ObjectSpace.each_object(Splash::Daemon::Orchestrator::Scheduler).first.terminate } end
|
47
60
|
res = daemonize daemon_config do
|
48
61
|
Scheduler::new options
|
49
62
|
end
|
50
63
|
sleep 1
|
51
64
|
if res == 0 then
|
52
|
-
pid = `cat #{config.
|
65
|
+
pid = `cat #{config.daemon_full_pid_path}`.to_i
|
53
66
|
log.ok "Splash Daemon Started, with PID : #{pid}"
|
54
67
|
return {:case => :quiet_exit, :more => "Splash Daemon successfully loaded."}
|
55
68
|
else
|
@@ -61,30 +74,37 @@ module Splash
|
|
61
74
|
end
|
62
75
|
end
|
63
76
|
|
77
|
+
# Stop the Splash Daemon
|
78
|
+
# @param [Hash] options
|
79
|
+
# @option options [Symbol] :quiet activate quiet mode for log (limit to :fatal)
|
80
|
+
# @return [Hash] Exiter Case (:quiet_exit, :not_found, other)
|
64
81
|
def stopdaemon(options = {})
|
65
82
|
config = get_config
|
66
83
|
log = get_logger
|
67
84
|
log.level = :fatal if options[:quiet]
|
68
|
-
if File.exist?(config.
|
85
|
+
if File.exist?(config.daemon_full_pid_path) then
|
69
86
|
begin
|
70
|
-
pid = `cat #{config.
|
87
|
+
pid = `cat #{config.daemon_full_pid_path}`.to_i
|
71
88
|
Process.kill("TERM", pid)
|
72
89
|
acase = {:case => :quiet_exit, :more => 'Splash stopped succesfully'}
|
73
90
|
rescue Errno::ESRCH
|
74
91
|
acase = {:case => :not_found, :more => "Process of PID : #{pid} not found"}
|
75
92
|
end
|
76
|
-
FileUtils::rm config.
|
93
|
+
FileUtils::rm config.daemon_full_pid_path if File::exist? config.daemon_full_pid_path
|
77
94
|
else
|
78
95
|
acase = {:case => :not_found, :more => "Splash is not running"}
|
79
96
|
end
|
80
97
|
return acase
|
81
98
|
end
|
82
99
|
|
100
|
+
# Status of the Splash Daemon, display status
|
101
|
+
# @param [Hash] options ignored
|
102
|
+
# @return [Hash] Exiter Case (:status_ko, :status_ok)
|
83
103
|
def statusdaemon(options = {})
|
84
104
|
log = get_logger
|
85
105
|
config = get_config
|
86
106
|
pid = realpid = ''
|
87
|
-
pid = `cat #{config.
|
107
|
+
pid = `cat #{config.daemon_full_pid_path}`.to_s if File.exist?(config.daemon_full_pid_path)
|
88
108
|
listpid = get_processes({ :pattern => get_config.daemon_process_name})
|
89
109
|
pid.chomp!
|
90
110
|
if listpid.empty? then
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash module
|
4
|
+
module Splash
|
5
|
+
|
6
|
+
# global daemon module
|
7
|
+
module Daemon
|
8
|
+
|
9
|
+
# Metrics management modulefor Splash daemon
|
10
|
+
module Metrics
|
11
|
+
include Splash::Constants
|
12
|
+
include Splash::Helpers
|
13
|
+
include Splash::Config
|
14
|
+
include Splash::Loggers
|
15
|
+
|
16
|
+
@@manager=nil
|
17
|
+
|
18
|
+
# metrics manager factory
|
19
|
+
# @return [Splash::Daemon::Metrics::Manager]
|
20
|
+
def get_metrics_manager
|
21
|
+
return @@manager ||= Manager::new
|
22
|
+
end
|
23
|
+
|
24
|
+
# Metrics Manager (collect and sending to Prometheus)
|
25
|
+
class Manager
|
26
|
+
|
27
|
+
# metric : commands executions count during Splash daemon uptime
|
28
|
+
attr_reader :execution_count
|
29
|
+
# metric : logs monitoring count during Splash daemon uptime
|
30
|
+
attr_reader :monitoring_logs_count
|
31
|
+
# metric : processes monitoring count during Splash daemon uptime
|
32
|
+
attr_reader :monitoring_processes_count
|
33
|
+
|
34
|
+
# Constructor prepare prometheus-client, defined metrics and init attributes
|
35
|
+
def initialize
|
36
|
+
@config = get_config
|
37
|
+
@starttime = Time.now
|
38
|
+
@execution_count = 0
|
39
|
+
@monitoring_logs_count = 0
|
40
|
+
@monitoring_processes_count = 0
|
41
|
+
|
42
|
+
|
43
|
+
@registry = Prometheus::Client::Registry::new
|
44
|
+
@metric_uptime = Prometheus::Client::Gauge.new(:splash_uptime, docstring: 'SPLASH self metric uptime')
|
45
|
+
@metric_execution = Prometheus::Client::Gauge.new(:splash_execution, docstring: 'SPLASH self metric total commands execution count')
|
46
|
+
@metric_logs_monitoring = Prometheus::Client::Gauge.new(:splash_logs_monitoring, docstring: 'SPLASH self metric total logs monitoring count')
|
47
|
+
@metric_processes_monitoring = Prometheus::Client::Gauge.new(:splash_processes_monitoring, docstring: 'SPLASH self metric total processes monitoring count')
|
48
|
+
@registry.register(@metric_uptime)
|
49
|
+
@registry.register(@metric_execution)
|
50
|
+
@registry.register(@metric_logs_monitoring)
|
51
|
+
@registry.register(@metric_processes_monitoring)
|
52
|
+
end
|
53
|
+
|
54
|
+
# virtual accessor uptime
|
55
|
+
def uptime
|
56
|
+
return Time.now - @starttime
|
57
|
+
end
|
58
|
+
|
59
|
+
# increment metric : execution_count
|
60
|
+
def inc_execution
|
61
|
+
@execution_count += 1
|
62
|
+
end
|
63
|
+
|
64
|
+
# increment metric : monitoring_logs_count
|
65
|
+
def inc_logs_monitoring
|
66
|
+
@monitoring_logs_count += 1
|
67
|
+
end
|
68
|
+
|
69
|
+
# increment metric : monitoring_processes_count
|
70
|
+
def inc_processes_monitoring
|
71
|
+
@monitoring_processes_count += 1
|
72
|
+
end
|
73
|
+
|
74
|
+
# Send metrics to Prometheus PushGateway
|
75
|
+
# @return [Hash] Exiter case ( :service_dependence_missing , :quiet_exit)
|
76
|
+
def notify
|
77
|
+
log = get_logger
|
78
|
+
session = get_session
|
79
|
+
unless verify_service url: @config.prometheus_pushgateway_url then
|
80
|
+
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
|
81
|
+
end
|
82
|
+
|
83
|
+
log.debug "Sending Splash self metrics to PushGateway." , session
|
84
|
+
@metric_uptime.set uptime
|
85
|
+
@metric_execution.set execution_count
|
86
|
+
@metric_logs_monitoring.set monitoring_logs_count
|
87
|
+
@metric_processes_monitoring.set monitoring_processes_count
|
88
|
+
|
89
|
+
hostname = Socket.gethostname
|
90
|
+
url = @config.prometheus_pushgateway_url
|
91
|
+
Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
|
92
|
+
log.debug "Sending to Prometheus PushGateway done.", session
|
93
|
+
return {:case => :quiet_exit }
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
Dir[File.dirname(__FILE__) + '/orchestrator/*.rb'].each {|file| require file }
|
3
|
+
|
4
|
+
# base Splash module
|
5
|
+
module Splash
|
6
|
+
|
7
|
+
# global daemon module
|
8
|
+
module Daemon
|
9
|
+
|
10
|
+
# orchestrator specific module
|
11
|
+
module Orchestrator
|
12
|
+
|
13
|
+
# Splash Scheduler object
|
14
|
+
class Scheduler
|
15
|
+
include Splash::Constants
|
16
|
+
include Splash::Helpers
|
17
|
+
include Splash::Config
|
18
|
+
include Splash::Transports
|
19
|
+
include Splash::Daemon::Orchestrator::Grammar
|
20
|
+
include Splash::Loggers
|
21
|
+
include Splash::Logs
|
22
|
+
include Splash::Processes
|
23
|
+
include Splash::Commands
|
24
|
+
include Splash::Sequences
|
25
|
+
|
26
|
+
# Constructor prepare the Scheduler
|
27
|
+
# commands Schedules
|
28
|
+
# logs monitorings
|
29
|
+
# process monitorings
|
30
|
+
# @param [Hash] options
|
31
|
+
# @option options [Symbol] :scheduling activate commands scheduling
|
32
|
+
def initialize(options = {})
|
33
|
+
@log = get_logger
|
34
|
+
self.extend Splash::Daemon::Metrics
|
35
|
+
@metric_manager = get_metrics_manager
|
36
|
+
$stdout.sync = true
|
37
|
+
$stderr.sync = true
|
38
|
+
@server = Rufus::Scheduler::new
|
39
|
+
@server.extend SchedulerHooks
|
40
|
+
@config = get_config
|
41
|
+
|
42
|
+
@log.info "Splash Orchestrator starting :"
|
43
|
+
if options[:scheduling] then
|
44
|
+
@log.item "Initializing commands Scheduling."
|
45
|
+
init_commands_scheduling
|
46
|
+
init_sequences_scheduling
|
47
|
+
end
|
48
|
+
|
49
|
+
if @config.logs.empty? then
|
50
|
+
@log.item "No logs to monitor"
|
51
|
+
else
|
52
|
+
sched,value = @config.daemon_procmon_scheduling.flatten
|
53
|
+
@log.item "Initializing logs monitorings & notifications."
|
54
|
+
@log_result = LogScanner::new
|
55
|
+
@server.send sched,value do
|
56
|
+
begin
|
57
|
+
session = get_session
|
58
|
+
@metric_manager.inc_logs_monitoring
|
59
|
+
@log.trigger "Logs monitoring for Scheduling : #{sched.to_s} #{value.to_s}", session
|
60
|
+
@log_result.analyse
|
61
|
+
@log_result.notify :session => session
|
62
|
+
rescue Errno::ECONNREFUSED
|
63
|
+
@log.error "PushGateway seems to be done, please start it.", session
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
if @config.processes.empty? then
|
69
|
+
@log.item "No processes to monitor"
|
70
|
+
else
|
71
|
+
sched,value = @config.daemon_logmon_scheduling.flatten
|
72
|
+
@log.item "Initializing processes monitorings & notifications."
|
73
|
+
@process_result = ProcessScanner::new
|
74
|
+
@server.send sched,value do
|
75
|
+
begin
|
76
|
+
session = get_session
|
77
|
+
@metric_manager.inc_processes_monitoring
|
78
|
+
@log.trigger "Processes monitoring for Scheduling : #{sched.to_s} #{value.to_s}", session
|
79
|
+
@process_result.analyse
|
80
|
+
@process_result.notify :session => session
|
81
|
+
rescue Errno::ECONNREFUSED
|
82
|
+
@log.error "PushGateway seems to be done, please start it.", session
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
sched,value = @config.daemon_metrics_scheduling.flatten
|
89
|
+
@log.item "Initializing Splash metrics notifications."
|
90
|
+
@server.send sched,value do
|
91
|
+
begin
|
92
|
+
@metric_manager.notify
|
93
|
+
rescue Errno::ECONNREFUSED
|
94
|
+
@log.error "PushGateway seems to be done, please start it."
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
hostname = Socket.gethostname
|
99
|
+
transport = get_default_subscriber queue: "splash.#{hostname}.input"
|
100
|
+
if transport.class == Hash and transport.include? :case then
|
101
|
+
splash_exit transport
|
102
|
+
end
|
103
|
+
transport.subscribe(:block => true) do |delivery_info, properties, body|
|
104
|
+
content = YAML::load(body)
|
105
|
+
session = get_session
|
106
|
+
content[:session] = session
|
107
|
+
if VERBS.include? content[:verb]
|
108
|
+
@log.receive "Valid remote order, verb : #{content[:verb].to_s}", session
|
109
|
+
res = self.send content[:verb], content
|
110
|
+
get_default_client.publish queue: content[:return_to], message: res.to_yaml
|
111
|
+
@log.send "Result to #{content[:return_to]}.", session
|
112
|
+
else
|
113
|
+
@log.receive "INVALID remote order, verb : #{content[:verb].to_s}", session
|
114
|
+
get_default_client.publish queue: content[:return_to], message: "Unkown verb #{content[:verb]}".to_yaml
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Stop the Splash daemon gracefully
|
120
|
+
# @return [hash] Exiter Case :quiet_exit
|
121
|
+
def terminate
|
122
|
+
@log.info "Splash daemon shutdown"
|
123
|
+
@server.shutdown
|
124
|
+
change_logger logger: :cli
|
125
|
+
splash_exit case: :quiet_exit
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
# prepare commands Scheduling
|
130
|
+
def init_commands_scheduling
|
131
|
+
config = get_config.commands
|
132
|
+
commands = config.select{|key,value| value.include? :schedule}.keys
|
133
|
+
commands.each do |command|
|
134
|
+
sched,value = config[command][:schedule].flatten
|
135
|
+
@log.arrow "Scheduling command #{command.to_s}"
|
136
|
+
@server.send sched,value do
|
137
|
+
session = get_session
|
138
|
+
@log.trigger "Executing Scheduled command #{command.to_s} for Scheduling : #{sched.to_s} #{value.to_s}", session
|
139
|
+
execute command: command.to_s, session: session
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
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
|
+
|
164
|
+
# execute_command verb : execute command specified in payload
|
165
|
+
# @param [Hash] options
|
166
|
+
# @option options [Symbol] :command the name of the command
|
167
|
+
# @option options [Symbol] :ack ack flag to inhibit execution and send ack to Prometheus (0)
|
168
|
+
# @return [Hash] Exiter case
|
169
|
+
def execute(options)
|
170
|
+
command = CommandWrapper::new(options[:command])
|
171
|
+
if options[:ack] then
|
172
|
+
else
|
173
|
+
@metric_manager.inc_execution
|
174
|
+
return command.call_and_notify trace: true, notify: true, callback: true, session: options[:session]
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash module
|
4
|
+
module Splash
|
5
|
+
|
6
|
+
# global daemon module
|
7
|
+
module Daemon
|
8
|
+
|
9
|
+
# orchestrator specific module
|
10
|
+
module Orchestrator
|
11
|
+
|
12
|
+
# Orchestrator grammar method defiition module
|
13
|
+
module Grammar
|
14
|
+
|
15
|
+
include Splash::Config
|
16
|
+
include Splash::Loggers
|
17
|
+
|
18
|
+
# list of known verbs for Splash orchestrator
|
19
|
+
VERBS=[:ping,:list_commands,:execute_command,:ack_command, :shutdown]
|
20
|
+
|
21
|
+
# shutdown verb : stop the Splash daemon gracefully
|
22
|
+
# @param [Hash] content message content Hash Structure, ignored
|
23
|
+
# @return [Hash] Exiter Case :quiet_exit
|
24
|
+
def shutdown(content)
|
25
|
+
terminate
|
26
|
+
end
|
27
|
+
|
28
|
+
# ping verb : return pong to hostname precise in payload
|
29
|
+
# @param [Hash] content message content Hash Structure, include mandatory payload[:hostname]
|
30
|
+
# @return [String] the pong
|
31
|
+
def ping(content)
|
32
|
+
return "Pong : #{content[:payload][:hostname]} !"
|
33
|
+
end
|
34
|
+
|
35
|
+
# list_commands verb : return the list of specified commands in local Splash
|
36
|
+
# @param [Hash] content message content Hash Structure, ignored
|
37
|
+
# @return [Hash] structure of commands
|
38
|
+
def list_commands(content)
|
39
|
+
return get_config.commands
|
40
|
+
end
|
41
|
+
|
42
|
+
# ack_command verb : send ack to Prometheus, for command specified in payload
|
43
|
+
# @param [Hash] content message content Hash Structure, include mandatory payload[:name]
|
44
|
+
# @return [Hash] Exiter case
|
45
|
+
def ack_command(content)
|
46
|
+
return execute command: content[:payload][:name], ack: true
|
47
|
+
end
|
48
|
+
|
49
|
+
# execute_command verb : execute command specified in payload
|
50
|
+
# @param [Hash] content message content Hash Structure, include mandatory payload[:name]
|
51
|
+
# @return [Hash] Exiter case
|
52
|
+
def execute_command(content)
|
53
|
+
payload = content[:payload]
|
54
|
+
unless get_config.commands.include? payload[:name].to_sym
|
55
|
+
@log.item "Command not found", content[:session]
|
56
|
+
return { :case => :not_found }
|
57
|
+
end
|
58
|
+
if payload.include? :schedule then
|
59
|
+
sched,value = payload[:schedule].flatten
|
60
|
+
@log.schedule "remote call command #{payload[:name]}, scheduling : #{sched.to_s} #{value}", content[:session]
|
61
|
+
@server.send sched,value do
|
62
|
+
@log.trigger "Executing Scheduled command #{payload[:name]} for Scheduling : #{sched.to_s} #{value}", content[:session]
|
63
|
+
execute command: payload[:name], session: content[:session]
|
64
|
+
end
|
65
|
+
return { :case => :quiet_exit }
|
66
|
+
else
|
67
|
+
@log.info "Execute direct command", content[:session]
|
68
|
+
res = execute command: payload[:name], session: content[:session]
|
69
|
+
return res
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|