prometheus-splash 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/config/splash.yml +10 -0
- data/lib/splash/cli/commands.rb +5 -0
- data/lib/splash/cli/daemon.rb +2 -3
- data/lib/splash/commands.rb +63 -41
- data/lib/splash/config/setup.rb +1 -1
- data/lib/splash/constants.rb +1 -1
- data/lib/splash/orchestrator.rb +3 -1
- data/lib/splash/orchestrator/grammar.rb +11 -8
- data/lib/splash/transports/rabbitmq.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6036da9aa1ce8abf1bc28d87c034152654cd75518d46b95bd683f9642b01186c
|
4
|
+
data.tar.gz: ac742574fd569bed467ac95fc33029339335beef8e596717444f6fe74c3bc446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af38c990376f81466c893c140946b22ad492cdda47cd0c9fb874ce90dcf543151cee2d8a7f8b285b537d1dd909551839efce6e988256fa5131fe52feac6e77db
|
7
|
+
data.tar.gz: 07742cabe62fa85017c35a1d29e1804060f43113313a071777db977b423ea7668f9bdbe5cd1b78b7af68fd9cd8401540f80a010e5f25803858bca18ef5c5992a
|
data/config/splash.yml
CHANGED
@@ -78,6 +78,16 @@
|
|
78
78
|
:echo3:
|
79
79
|
:desc: echo 'been'
|
80
80
|
:command: echo been
|
81
|
+
:rand_sleep_5:
|
82
|
+
:desc: sleep on a rand 5
|
83
|
+
:command: ruby -e 'sleep rand(5)'
|
84
|
+
:schedule:
|
85
|
+
:every: "10s"
|
86
|
+
:test_remote_call:
|
87
|
+
:desc: remote call test
|
88
|
+
:delegate_to:
|
89
|
+
:host: omicron
|
90
|
+
:remote_command: :echo2
|
81
91
|
|
82
92
|
|
83
93
|
### configuration of monitored logs
|
data/lib/splash/cli/commands.rb
CHANGED
@@ -27,6 +27,7 @@ module CLISplash
|
|
27
27
|
def execute(name)
|
28
28
|
if is_root? then
|
29
29
|
if options[:hostname] then
|
30
|
+
splash_exit({ :case => :options_incompatibility, :more => '--hostname forbidden with delagate commands'}) if get_config.commands[name.to_sym][:delegate_to]
|
30
31
|
puts "Remote Splash configured commands on #{options[:hostname]}:"
|
31
32
|
puts "ctrl+c for interrupt"
|
32
33
|
begin
|
@@ -122,6 +123,10 @@ module CLISplash
|
|
122
123
|
puts " - command description : '#{list[command][:desc]}'"
|
123
124
|
puts " - command failure callback : '#{list[command.to_sym][:on_failure]}'" if list[command.to_sym][:on_failure]
|
124
125
|
puts " - command success callback : '#{list[command.to_sym][:on_success]}'" if list[command.to_sym][:on_success]
|
126
|
+
if list[command.to_sym][:schedule]
|
127
|
+
sched,val = list[command.to_sym][:schedule].flatten
|
128
|
+
puts " - command scheduled : #{sched} #{val}."
|
129
|
+
end
|
125
130
|
end
|
126
131
|
end
|
127
132
|
splash_exit case: :quiet_exit
|
data/lib/splash/cli/daemon.rb
CHANGED
@@ -8,13 +8,13 @@ module CLISplash
|
|
8
8
|
|
9
9
|
|
10
10
|
option :foreground, :type => :boolean
|
11
|
-
option :purge, :type => :boolean
|
11
|
+
option :purge, :type => :boolean, default: true
|
12
12
|
option :scheduling, :type => :boolean, default: true
|
13
13
|
long_desc <<-LONGDESC
|
14
14
|
Starting Splash Daemon\n
|
15
15
|
With --foreground, run Splash in foreground\n
|
16
16
|
With --no-scheduling, inhibit commands scheduling\n
|
17
|
-
With --purge,
|
17
|
+
With --no-purge, inhibit purge Input Queue for Splash Daemon
|
18
18
|
LONGDESC
|
19
19
|
desc "start", "Starting Splash Daemon"
|
20
20
|
def start
|
@@ -26,7 +26,6 @@ module CLISplash
|
|
26
26
|
queue = "splash.#{Socket.gethostname}.input"
|
27
27
|
transport.purge queue: queue
|
28
28
|
puts " * Queue : #{queue} purged"
|
29
|
-
splash_exit case: :quiet_exit
|
30
29
|
end
|
31
30
|
end
|
32
31
|
acase = run_as_root :startdaemon, options
|
data/lib/splash/commands.rb
CHANGED
@@ -6,6 +6,7 @@ module Splash
|
|
6
6
|
include Splash::Helpers
|
7
7
|
include Splash::Backends
|
8
8
|
include Splash::Exiter
|
9
|
+
include Splash::Transports
|
9
10
|
|
10
11
|
|
11
12
|
@@registry = Prometheus::Client.registry
|
@@ -42,58 +43,78 @@ module Splash
|
|
42
43
|
|
43
44
|
|
44
45
|
def call_and_notify(options)
|
45
|
-
puts "Executing command : '#{@name}' "
|
46
46
|
acase = { :case => :quiet_exit }
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
puts "
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
exit_code = 0
|
48
|
+
if @config.commands[@name.to_sym][:delegate_to] then
|
49
|
+
return { :case => :options_incompatibility, :more => '--hostname forbidden with delagate commands'} if options[:hostname]
|
50
|
+
puts "Remote command : #{@name} execution delegate to : #{@config.commands[@name.to_sym][:delegate_to][:host]} as : #{@config.commands[@name.to_sym][:delegate_to][:remote_command]}"
|
51
|
+
begin
|
52
|
+
transport = get_default_client
|
53
|
+
if transport.class == Hash and transport.include? :case then
|
54
|
+
return transport
|
55
|
+
else
|
56
|
+
res = transport.execute({ :verb => :execute_command,
|
57
|
+
payload: {:name => @config.commands[@name.to_sym][:delegate_to][:remote_command].to_s},
|
58
|
+
:return_to => "splash.#{Socket.gethostname}.return",
|
59
|
+
:queue => "splash.#{@config.commands[@name.to_sym][:delegate_to][:host]}.input" })
|
60
|
+
exit_code = res[:exit_code]
|
61
|
+
puts " => exitcode #{exit_code}"
|
62
|
+
|
63
|
+
end
|
56
64
|
end
|
57
|
-
time = Time.now - start
|
58
|
-
exit_code = $?.exitstatus
|
59
65
|
else
|
60
|
-
puts "
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
puts "Executing command : '#{@name}' "
|
67
|
+
start = Time.now
|
68
|
+
start_date = DateTime.now.to_s
|
69
|
+
unless options[:trace] then
|
70
|
+
puts " * Traceless execution"
|
71
|
+
if @config.commands[@name.to_sym][:user] then
|
72
|
+
puts " * Execute with user : #{@config.commands[@name.to_sym][:user]}."
|
73
|
+
system("sudo -u #{@config.commands[@name.to_sym][:user]} #{@config.commands[@name.to_sym][:command]} > /dev/null 2>&1")
|
74
|
+
else
|
75
|
+
system("#{@config.commands[@name.to_sym][:command]} > /dev/null 2>&1")
|
76
|
+
end
|
77
|
+
time = Time.now - start
|
78
|
+
exit_code = $?.exitstatus
|
64
79
|
else
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
80
|
+
puts " * Tracefull execution"
|
81
|
+
if @config.commands[@name.to_sym][:user] then
|
82
|
+
puts " * Execute with user : #{@config.commands[@name.to_sym][:user]}."
|
83
|
+
stdout, stderr, status = Open3.capture3("sudo -u #{@config.commands[@name.to_sym][:user]} #{@config.commands[@name.to_sym][:command]}")
|
84
|
+
else
|
85
|
+
stdout, stderr, status = Open3.capture3(@config.commands[@name.to_sym][:command])
|
86
|
+
end
|
87
|
+
time = Time.now - start
|
88
|
+
tp = Template::new(
|
69
89
|
list_token: @config.execution_template_tokens,
|
70
90
|
template_file: @config.execution_template_path)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
91
|
+
data = Hash::new
|
92
|
+
data[:start_date] = start_date
|
93
|
+
data[:end_date] = DateTime.now.to_s
|
94
|
+
data[:cmd_name] = @name
|
95
|
+
data[:cmd_line] = @config.commands[@name.to_sym][:command]
|
96
|
+
data[:desc] = @config.commands[@name.to_sym][:desc]
|
97
|
+
data[:status] = status.to_s
|
98
|
+
data[:stdout] = stdout
|
99
|
+
data[:stderr] = stderr
|
100
|
+
data[:exec_time] = time.to_s
|
101
|
+
backend = get_backend :execution_trace
|
102
|
+
key = @name
|
103
|
+
backend.put key: key, value: data.to_yaml
|
104
|
+
exit_code = status.exitstatus
|
105
|
+
end
|
86
106
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
107
|
+
puts " => exitcode #{exit_code}"
|
108
|
+
if options[:notify] then
|
109
|
+
acase = notify(exit_code,time.to_i)
|
110
|
+
else
|
111
|
+
puts " * Without Prometheus notification"
|
112
|
+
end
|
92
113
|
end
|
114
|
+
|
93
115
|
if options[:callback] then
|
94
116
|
on_failure = (@config.commands[@name.to_sym][:on_failure])? @config.commands[@name.to_sym][:on_failure] : false
|
95
117
|
on_success = (@config.commands[@name.to_sym][:on_success])? @config.commands[@name.to_sym][:on_success] : false
|
96
|
-
|
97
118
|
if on_failure and exit_code > 0 then
|
98
119
|
puts " * On failure callback : #{on_failure}"
|
99
120
|
if @config.commands.keys.include? on_failure then
|
@@ -115,6 +136,7 @@ module Splash
|
|
115
136
|
else
|
116
137
|
puts " * Without callbacks sequences"
|
117
138
|
end
|
139
|
+
acase[:exit_code] = exit_code
|
118
140
|
return acase
|
119
141
|
end
|
120
142
|
end
|
data/lib/splash/config/setup.rb
CHANGED
@@ -8,7 +8,7 @@ module Splash
|
|
8
8
|
include Splash::Helpers
|
9
9
|
# Setup action method for installing Splash
|
10
10
|
# @return [Integer] an errorcode value
|
11
|
-
def setupsplash
|
11
|
+
def setupsplash(options = {})
|
12
12
|
conf_in_path = search_file_in_gem "prometheus-splash", "config/splash.yml"
|
13
13
|
full_res = 0
|
14
14
|
puts "Splash -> setup : "
|
data/lib/splash/constants.rb
CHANGED
data/lib/splash/orchestrator.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Dir[File.dirname(__FILE__) + '/orchestrator/*.rb'].each {|file| require file }
|
3
3
|
|
4
|
+
|
5
|
+
|
4
6
|
module Splash
|
5
7
|
module Orchestrator
|
6
8
|
|
@@ -77,7 +79,7 @@ module Splash
|
|
77
79
|
if options[:ack] then
|
78
80
|
command.ack
|
79
81
|
else
|
80
|
-
command.call_and_notify trace: true, notify: true, callback: true
|
82
|
+
return command.call_and_notify trace: true, notify: true, callback: true
|
81
83
|
end
|
82
84
|
end
|
83
85
|
|
@@ -15,7 +15,7 @@ module Splash
|
|
15
15
|
return get_config.commands
|
16
16
|
end
|
17
17
|
|
18
|
-
def ack_command
|
18
|
+
def ack_command(payload)
|
19
19
|
return self.execute command: payload[:name], ack: true
|
20
20
|
end
|
21
21
|
|
@@ -27,15 +27,18 @@ module Splash
|
|
27
27
|
end
|
28
28
|
if payload.include? :schedule then
|
29
29
|
sched,value = payload[:schedule].flatten
|
30
|
+
puts " * Schedule remote call command #{payload[:name]}, scheduling : #{sched.to_s} #{value}"
|
31
|
+
@server.send sched,value do
|
32
|
+
self.execute command: payload[:name]
|
33
|
+
end
|
34
|
+
return { :case => :quiet_exit }
|
30
35
|
else
|
31
|
-
|
32
|
-
|
36
|
+
puts " * Execute direct command"
|
37
|
+
puts payload[:name]
|
38
|
+
res = self.execute command: payload[:name]
|
39
|
+
puts res.inspect
|
40
|
+
return res
|
33
41
|
end
|
34
|
-
puts " * Schedule remote call command #{payload[:name]}, scheduling : #{sched.to_s} #{value}"
|
35
|
-
@server.send sched,value do
|
36
|
-
self.execute command: payload[:name]
|
37
|
-
end
|
38
|
-
return { :case => :quiet_exit }
|
39
42
|
end
|
40
43
|
|
41
44
|
end
|
@@ -64,8 +64,9 @@ module Splash
|
|
64
64
|
lock = Mutex.new
|
65
65
|
res = nil
|
66
66
|
condition = ConditionVariable.new
|
67
|
-
get_default_subscriber(queue: queue).subscribe
|
67
|
+
get_default_subscriber(queue: queue).subscribe do |delivery_info, properties, payload|
|
68
68
|
res = YAML::load(payload)
|
69
|
+
|
69
70
|
lock.synchronize { condition.signal }
|
70
71
|
end
|
71
72
|
get_default_client.publish queue: order[:queue], message: order.to_yaml
|