prometheus-splash 0.1.0 → 0.1.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: 4ae0ce3acc9966d9dc6bcc162a6691b01a97fa0368595dacbc4e12c36d830371
4
- data.tar.gz: b236034c20105a79dd770ce10334aea80c67dc4f624d059b82f425e862b601e1
3
+ metadata.gz: 62507dbefc8ccad97a7388a4527a79991b7224e5d6181d8edc06fcd6299c6791
4
+ data.tar.gz: 62fa6ab6b86cd2442a9f3d6e2a4bf3e073f3a2d0a51154dba4fa64590c4b5f54
5
5
  SHA512:
6
- metadata.gz: 21daf35dfb3e696ef172cd678d7d2a644c2ef46aceef16cd32c889356f60a0403cd8cbfd1246944b0b7a84acbf8ea627ecd718ae830d48d839abdbd0d3ac5db9
7
- data.tar.gz: 8e6cea17fcdf8fbd7facf65e34ca79e166cf3f26b517f454024fd46ef0b9d18aec7e103ff4ff4efdbf94531beeb6a1f490817e23e9b18bda395955d63cc34d0a
6
+ metadata.gz: f651a3c3a6c758ce7939403d16c48d4b8f3666e30ad378c9de2db38a3e5ff7bfaf5565a0ffedf971781305a3098b15e9d5111efa1b4be6db16db8642b43ddbfc
7
+ data.tar.gz: fe6b45de95e4ecde64eb7361d4edc6da5268bfebabd312617b44983612155f02a7bc20c6297adf85797abe069350f81bf9cc46ec43ebb3fc493fcdd115306280
data/README.md CHANGED
@@ -647,8 +647,38 @@ TRANSPORTS_STRUCT = { :list => [:rabbitmq],
647
647
 
648
648
 
649
649
  #### Splash CLI return code significations
650
+ ```ruby
651
+ EXIT_MAP= {
650
652
 
651
- TODO
653
+ # context execution
654
+ :not_root => {:message => "This operation need to be run as root (use sudo or rvmsudo)", :code => 10},
655
+ :options_incompatibility => {:message => "Options incompatibility", :code => 40},
656
+ :service_dependence_missing => {:message => "Splash Service dependence missing", :code => 60},
657
+
658
+ # config
659
+ :specific_config_required => {:message => "Specific configuration required", :code => 30},
660
+ :splash_setup_error => {:message => "Splash Setup terminated unsuccessfully", :code => 25},
661
+ :splash_setup_success => {:message => "Splash Setup terminated successfully", :code => 0},
662
+ :splash_sanitycheck_error => {:message => "Splash Sanitycheck terminated unsuccessfully", :code => 20},
663
+ :splash_sanitycheck_success => {:message => "Splash Sanitycheck terminated successfully", :code => 0},
664
+ :configuration_error => {:message => "Splash Configuration Error", :code => 50},
665
+
666
+
667
+ # global
668
+ :quiet_exit => {:code => 0},
669
+
670
+ # events
671
+ :interrupt => {:message => "Splash user operation interrupted", :code => 33},
672
+
673
+ # request
674
+ :not_found => {:message => "Object not found", :code => 44},
675
+ :already_exist => {:message => "Object already exist", :code => 48},
676
+
677
+ # daemon
678
+ :status_ok => {:message => "Status OK", :code => 0},
679
+ :status_ko => {:message => "Status KO", :code => 31}
680
+ ```
681
+ }
652
682
 
653
683
  ### In the Futur ?
654
684
 
data/bin/splash CHANGED
@@ -1,374 +1,16 @@
1
1
  #!/usr/bin/env ruby -W:no-deprecated
2
- require 'socket'
3
- require 'yaml'
4
- require 'thread'
2
+ # coding: utf-8
5
3
 
6
- begin
7
- require 'prometheus/client'
8
- require 'prometheus/client/push'
9
- require 'thor'
10
- require 'rufus-scheduler'
11
-
12
- rescue Gem::GemNotFoundException
13
- $stderr.puts "Loadind error, it's like you try to run Splash, with a lake of dependencies."
14
- $stderr.puts "If you run on RVM, please run with rvmsudo and not with sudo."
15
- $stderr.puts "If problem is percistant, please, proceed to new install and Setup."
16
- end
17
-
18
- require 'yaml'
19
-
20
- require 'splash/constants'
21
- require 'splash/helpers'
22
- require 'splash/config'
23
- require 'splash/templates'
24
- require 'splash/backends'
25
- require 'splash/transports'
26
-
27
- require 'splash/commands'
28
- require 'splash/logs'
29
- require 'splash/orchestrator'
30
- require 'splash/controller'
4
+ require 'splash/dependencies'
5
+ require 'splash/cli'
31
6
 
32
7
  #inhibit warning : due to prometheus-client call to URI.encode warning
33
8
  $-w = nil
34
9
 
10
+ include Splash::Dependencies
35
11
  include Splash::Helpers
36
-
37
- module CLISplash
38
-
39
-
40
- class Commands < Thor
41
- include Splash::Config
42
- include Splash::Backends
43
-
44
- desc "execute NAME", "run for command/sequence or ack result"
45
- long_desc <<-LONGDESC
46
- execute command or sequence or ack result
47
- with --no-trace prevent storing execution trace in configured backend (see config file)
48
- with --ack, notify errorcode=0 to Prometheus PushGateway
49
- with --no-notify, bypass Prometheus notification
50
- with --no-callback, never execute callback (:on_failure, :on_success)
51
- never follow sequences
52
- LONGDESC
53
- option :trace, :type => :boolean, :default => true
54
- option :ack, :type => :boolean, negate: false
55
- option :notify, :type => :boolean, :default => true
56
- option :callback, :type => :boolean, :default => true
57
- def execute(name)
58
- if is_root? then
59
- command = Splash::CommandWrapper::new(name)
60
- command.ack if options[:ack]
61
- command.call_and_notify trace: options[:trace], notify: options[:notify], callback: options[:callback]
62
- else
63
- $stderr.puts "Command wrapping need to be run as root"
64
- exit 60
65
- end
66
- end
67
-
68
-
69
-
70
- desc "treeview", "Show commands sequence tree"
71
- def treeview(command, depht = 0)
72
- puts "Command : #{command.to_s}" if depht == 0
73
- cmd = get_config.commands[command.to_sym]
74
- if cmd[:on_failure] then
75
- print " " * depht + " "
76
- puts "* on failure => #{cmd[:on_failure]}"
77
- treeview(cmd[:on_failure], depht+2)
78
- end
79
- if cmd[:on_success] then
80
- print " " * depht + " "
81
- puts "* on success => #{cmd[:on_success]}"
82
- treeview(cmd[:on_success],depht+2)
83
- end
84
- end
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
- desc "list", "Show configured commands"
95
- long_desc <<-LONGDESC
96
- Show configured commands
97
- with --detail, show command details
98
- LONGDESC
99
- option :detail, :type => :boolean
100
- def list
101
- puts "Splash configured commands :"
102
- list = get_config.commands
103
- puts 'No configured commands found' if list.keys.empty?
104
- list.keys.each do |command|
105
- puts " * #{command.to_s}"
106
- if options[:detail] then
107
- puts " - command line : '#{list[command][:command]}'"
108
- puts " - command description : '#{list[command][:desc]}'"
109
- puts " - command failure callback : '#{list[command.to_sym][:on_failure]}'" if list[command.to_sym][:on_failure]
110
- puts " - command success callback : '#{list[command.to_sym][:on_success]}'" if list[command.to_sym][:on_success]
111
- end
112
- end
113
- end
114
-
115
-
116
- desc "show COMMAND", "Show specific configured command COMMAND"
117
- def show(command)
118
- list = get_config.commands
119
- if list.keys.include? command.to_sym then
120
- puts "Splash command : #{command}"
121
- puts " - command line : '#{list[command.to_sym][:command]}'"
122
- puts " - command description : '#{list[command.to_sym][:desc]}'"
123
- puts " - command failure callback : '#{list[command.to_sym][:on_failure]}'" if list[command.to_sym][:on_failure]
124
- puts " - command success callback : '#{list[command.to_sym][:on_success]}'" if list[command.to_sym][:on_success]
125
- else
126
- $stderr.puts "Command not configured"
127
- exit 50
128
- end
129
- end
130
-
131
-
132
- desc "lastrun COMMAND", "Show last running result for specific configured command COMMAND"
133
- long_desc <<-LONGDESC
134
- Show last running result for specific configured command COMMAND
135
- with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)
136
- LONGDESC
137
- option :hostname, :type => :string
138
- def lastrun(command)
139
- backend = get_backend :execution_trace
140
- redis = (backend.class == Splash::Backends::Redis)? true : false
141
- if not redis and options[:hostname] then
142
- $stderr.puts "Remote execution report request only possible with Redis backend"
143
- end
144
- list = get_config.commands
145
- if list.keys.include? command.to_sym then
146
- print "Splash command #{command} previous execution report:\n\n"
147
- req = { :key => command}
148
- req[:hostname] = options[:hostname] if options[:hostname]
149
- if backend.exist? req then
150
- print backend.get req
151
- else
152
- puts "Command not already runned."
153
- end
154
- else
155
- $stderr.puts "Command not configured"
156
- exit 50
157
- end
158
- end
159
-
160
- desc "getreportlist COMMAND", "list all executions report results "
161
- long_desc <<-LONGDESC
162
- Show configured commands
163
- with --pattern <SEARCH>, search type string, wilcard * (group) ? (char)
164
- with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)
165
- with --all, get all execution report for all servers (only with Redis backend configured)
166
- --all and --hostname are exclusives
167
- LONGDESC
168
- option :pattern, :type => :string
169
- option :hostname, :type => :string
170
- option :all, :type => :boolean, :negate => false
171
- def getreportlist
172
- if options[:hostname] and options[:all] then
173
- $stderr.puts "--all option imcompatible with --hostname"
174
- exit 40
175
- end
176
- backend = get_backend :execution_trace
177
- redis = (backend.class == Splash::Backends::Redis)? true : false
178
- if not redis and (options[:hostname] or options[:all]) then
179
- $stderr.puts "Remote execution report request only possible with Redis backend"
180
- exit 40
181
- end
182
- pattern = (options[:pattern])? options[:pattern] : '*'
183
- if options[:all] then
184
- res = backend.listall pattern
185
- elsif options[:hostname]
186
- res = backend.list pattern, options[:hostname]
187
- else
188
- res = backend.list pattern
189
- end
190
- print "List of Executions reports :\n\n"
191
- puts "Not reports found" if res.empty?
192
- res.each do |item|
193
- if options[:all]
194
- host,command = item.split('#')
195
- puts " * Command : #{command} @ host : #{host}"
196
- else
197
- puts " * Command : #{item}"
198
- end
199
- end
200
- end
201
-
202
-
203
-
204
- end
205
-
206
-
207
-
208
-
209
- class CLIController < Thor
210
- include Splash::LogsMonitor::DaemonController
211
- include Splash::Transports
212
-
213
- option :foreground, :type => :boolean
214
- desc "start", "Starting Logs Monitor Daemon"
215
- def start
216
- errorcode = run_as_root :startdaemon
217
- exit errorcode
218
- end
219
-
220
- desc "stop", "Stopping Logs Monitor Daemon"
221
- def stop
222
- errorcode = run_as_root :stopdaemon
223
- exit errorcode
224
- end
225
-
226
- desc "status", "Logs Monitor Daemon status"
227
- def status
228
- errorcode = run_as_root :statusdaemon
229
- exit errorcode
230
- end
231
-
232
- desc "ping HOSTNAME", "send a ping to HOSTNAME daemon over transport (need an active tranport), Typicallly RabbitMQ"
233
- def ping(hostname=Socket.gethostname)
234
- puts "ctrl+c for interrupt"
235
- queue = "splash.#{Socket.gethostname}.returncli"
236
- order = {:verb => :ping, :payload => {:hostname => Socket.gethostname}, :return_to => queue}
237
-
238
- lock = Mutex.new
239
- condition = ConditionVariable.new
240
- begin
241
- get_default_subscriber(queue: queue).subscribe(timeout: 10) do |delivery_info, properties, payload|
242
- puts YAML::load(payload)
243
- lock.synchronize { condition.signal }
244
- end
245
- get_default_client.publish queue: "splash.#{hostname}.input", message: order.to_yaml
246
- lock.synchronize { condition.wait(lock) }
247
- rescue Interrupt
248
- puts "Splash : ping : Interrupted by user. "
249
- exit 33
250
- end
251
- end
252
-
253
- end
254
-
255
-
256
-
257
-
258
- class Config < Thor
259
- include Splash::Config
260
- include Splash::Helpers
261
-
262
- desc "setup", "Setup installation fo Splash"
263
- long_desc <<-LONGDESC
264
- Setup installation fo Splash
265
- with --preserve, preserve from reinstallation of the config
266
- LONGDESC
267
- option :preserve, :type => :boolean
268
- def setup
269
- errorcode = run_as_root :setupsplash
270
- exit errorcode
271
- end
272
-
273
- desc "sanitycheck", "Verify installation fo Splash"
274
- def sanitycheck
275
- errorcode = run_as_root :checkconfig
276
- exit errorcode
277
- end
278
-
279
- desc "version", "display current Splash version"
280
- def version
281
- config = get_config
282
- puts "Splash version : #{config.version}, Author : #{config.author}"
283
- puts config.copyright
284
- end
285
-
286
-
287
- end
288
-
289
-
290
- class Logs < Thor
291
- include Splash::Config
292
-
293
- desc "analyse", "analyze logs in config"
294
- def analyse
295
- results = Splash::LogScanner::new
296
- results.analyse
297
- puts "SPlash Configured logs status :"
298
- full_status = true
299
- results.output.each do |result|
300
- status = (result[:status] == :clean)? "OK": "KO"
301
- puts " * Log : #{result[:log]} : [#{status}]"
302
- puts " - Detected pattern : #{result[:pattern]}"
303
- puts " - detailled Status : #{result[:status].to_s}"
304
- puts " count = #{result[:count]}" if result[:status] == :matched
305
- puts " nb lines = #{result[:lines]}" if result[:status] != :missing
306
- full_status = false unless result[:status] == :clean
307
- end
308
- display_status = (full_status)? "OK": "KO"
309
- puts "Global Status : [#{display_status}]"
310
- end
311
-
312
- desc "monitor", "monitor logs in config"
313
- def monitor
314
- result = Splash::LogScanner::new
315
- result.analyse
316
- result.notify
317
- end
318
-
319
- desc "show LOG", "show configured log monitoring for LOG"
320
- def show(log)
321
- log_record_set = get_config.logs.select{|item| item[:log] == log }
322
- unless log_record_set.empty? then
323
- record = log_record_set.first
324
- puts "Splash log monitor : #{record[:log]}"
325
- puts " -> pattern : /#{record[:pattern]}/"
326
- else
327
- $stderr.puts "log not configured"
328
- exit 50
329
- end
330
- end
331
-
332
- desc "list", "Show configured logs monitoring"
333
- long_desc <<-LONGDESC
334
- Show configured logs monitoring
335
- with --detail, show logs monitor details
336
- LONGDESC
337
- option :detail, :type => :boolean
338
- def list
339
- puts "Splash configured log monitoring :"
340
- log_record_set = get_config.logs
341
- puts 'No configured commands found' if log_record_set.empty?
342
- log_record_set.each do |record|
343
- puts " * log monitor : #{record[:log]}"
344
- if options[:detail] then
345
- puts " -> pattern : /#{record[:pattern]}/"
346
- end
347
- end
348
- end
349
-
350
- end
351
- end
352
-
353
- class CLI < Thor
354
- def self.exit_on_failure?
355
- true
356
- end
357
-
358
- include CLISplash
359
- desc "commands SUBCOMMAND ...ARGS", "Managing commands/batchs supervision"
360
- subcommand "commands", Commands
361
- desc "logs SUBCOMMAND ...ARGS", "Managing Files/Logs supervision"
362
- subcommand "logs", Logs
363
- desc "daemon SUBCOMMAND ...ARGS", "Logs monitor daemon contoller"
364
- subcommand "daemon", CLIController
365
- desc "config SUBCOMMAND ...ARGS", "config tools for Splash"
366
- subcommand "config", Config
367
- end
368
-
369
-
370
-
12
+ include Splash::Exiter
371
13
 
372
14
 
373
15
 
374
- CLI.start(ARGV)
16
+ CLI.start(ARGV)
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  Dir[File.dirname(__FILE__) + '/backends/*.rb'].each {|file| require file }
2
3
 
3
4
  module Splash
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  module Splash
2
3
  module Backends
3
4
  class File
@@ -1,6 +1,4 @@
1
- require "redis"
2
- require "socket"
3
-
1
+ # coding: utf-8
4
2
  module Splash
5
3
  module Backends
6
4
  class Redis