prometheus-splash 0.4.5 → 0.6.1

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.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +64 -2
  3. data/README.md +58 -60
  4. data/bin/splash +13 -5
  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 +31 -3
  10. data/lib/splash/cli/commands.rb +82 -33
  11. data/lib/splash/cli/config.rb +25 -4
  12. data/lib/splash/cli/daemon.rb +11 -14
  13. data/lib/splash/cli/documentation.rb +5 -2
  14. data/lib/splash/cli/logs.rb +27 -17
  15. data/lib/splash/cli/process.rb +103 -0
  16. data/lib/splash/cli/sequences.rb +112 -0
  17. data/lib/splash/cli/webadmin.rb +46 -0
  18. data/lib/splash/commands.rb +146 -120
  19. data/lib/splash/config.rb +170 -15
  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 +33 -0
  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/daemon/controller.rb +136 -0
  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 +17 -2
  32. data/lib/splash/exiter.rb +15 -0
  33. data/lib/splash/helpers.rb +91 -50
  34. data/lib/splash/loggers.rb +48 -17
  35. data/lib/splash/loggers/cli.rb +18 -3
  36. data/lib/splash/loggers/daemon.rb +23 -4
  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 -53
  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/main.rb +26 -0
  52. data/lib/splash/webadmin/portal/controllers/commands.rb +7 -0
  53. data/lib/splash/webadmin/portal/controllers/documentation.rb +6 -0
  54. data/lib/splash/webadmin/portal/controllers/home.rb +12 -0
  55. data/lib/splash/webadmin/portal/controllers/logs.rb +14 -0
  56. data/lib/splash/webadmin/portal/controllers/notfound.rb +5 -0
  57. data/lib/splash/webadmin/portal/controllers/processes.rb +14 -0
  58. data/lib/splash/webadmin/portal/controllers/proxy.rb +28 -0
  59. data/lib/splash/webadmin/portal/controllers/restclient.rb +19 -0
  60. data/lib/splash/webadmin/portal/init.rb +11 -0
  61. data/lib/splash/webadmin/portal/public/css/ultragreen.css +8544 -0
  62. data/lib/splash/webadmin/portal/public/fonts/FontAwesome.otf +0 -0
  63. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.ttf +0 -0
  64. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff +0 -0
  65. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff2 +0 -0
  66. data/lib/splash/webadmin/portal/public/images/logo_splash.png +0 -0
  67. data/lib/splash/webadmin/portal/public/images/logo_splash_reduce.png +0 -0
  68. data/lib/splash/webadmin/portal/public/images/logo_splash_tiny.png +0 -0
  69. data/lib/splash/webadmin/portal/views/commands.slim +49 -0
  70. data/lib/splash/webadmin/portal/views/documentation.slim +3 -0
  71. data/lib/splash/webadmin/portal/views/home.slim +78 -0
  72. data/lib/splash/webadmin/portal/views/layout.slim +43 -0
  73. data/lib/splash/webadmin/portal/views/logs.slim +32 -0
  74. data/lib/splash/webadmin/portal/views/nav.slim +17 -0
  75. data/lib/splash/webadmin/portal/views/not_found.slim +3 -0
  76. data/lib/splash/webadmin/portal/views/processes.slim +29 -0
  77. data/lib/splash/webadmin/portal/views/proxy.slim +13 -0
  78. data/lib/splash/webadmin/portal/views/restclient.slim +41 -0
  79. data/lib/splash/webadmin/portal/views/restclient_result.slim +29 -0
  80. data/prometheus-splash.gemspec +8 -1
  81. data/spec/helpers_spec.rb +119 -0
  82. data/templates/ansible-splash/Vagrantfile +1 -1
  83. data/templates/ansible-splash/deploy.yml +28 -1
  84. data/templates/ansible-splash/group_vars/DEV.yml +2 -0
  85. data/templates/ansible-splash/roles/mq/handlers/main.yml +1 -1
  86. data/templates/ansible-splash/roles/mq/tasks/main.yml +17 -1
  87. data/templates/ansible-splash/roles/mq/templates/rabbitmq-env.conf.j2 +13 -0
  88. data/templates/ansible-splash/roles/splash/handlers/main.yml +4 -0
  89. data/templates/ansible-splash/roles/splash/tasks/main.yml +25 -1
  90. data/templates/ansible-splash/roles/splash/templates/logrotate.splash.j2 +11 -0
  91. data/templates/ansible-splash/roles/splash/templates/splash.yml.j2 +1 -1
  92. data/templates/splashd.service +1 -1
  93. data/test.sh +42 -0
  94. metadata +159 -11
  95. data/lib/splash/controller.rb +0 -90
  96. data/lib/splash/orchestrator.rb +0 -100
  97. data/lib/splash/orchestrator/grammar.rb +0 -53
  98. data/lib/splash/orchestrator/hooks.rb +0 -16
  99. data/templates/ansible-splash/inventory.prod +0 -26
@@ -1,14 +1,18 @@
1
1
  # coding: utf-8
2
+
3
+ # module for all Thor subcommands
2
4
  module CLISplash
3
5
 
6
+ # Thor inherited class for splashd daemon management
4
7
  class CLIController < Thor
5
- include Splash::LogsMonitor::DaemonController
8
+ include Splash::Daemon::Controller
6
9
  include Splash::Transports
7
10
  include Splash::Exiter
8
11
  include Splash::Loggers
9
12
 
10
13
 
11
- option :foreground, :type => :boolean
14
+ # Thor method : starting Splashd
15
+ option :foreground, :type => :boolean, :aliases => "-F"
12
16
  option :purge, :type => :boolean, default: true
13
17
  option :scheduling, :type => :boolean, default: true
14
18
  long_desc <<-LONGDESC
@@ -19,25 +23,15 @@ module CLISplash
19
23
  LONGDESC
20
24
  desc "start", "Starting Splash Daemon"
21
25
  def start
22
- log = get_logger
23
- if options[:purge] then
24
- transport = get_default_client
25
- if transport.class == Hash and transport.include? :case then
26
- splash_exit transport
27
- else
28
- queue = "splash.#{Socket.gethostname}.input"
29
- transport.purge queue: queue
30
- log.info "Queue : #{queue} purged"
31
- end
32
- end
33
26
  acase = run_as_root :startdaemon, options
34
27
  splash_exit acase
35
28
  end
36
29
 
37
-
30
+ # Thor method : purge transport input queue of Splashd daemon
38
31
  desc "purge", "Purge Transport Input queue of Daemon"
39
32
  def purge
40
33
  log = get_logger
34
+ log.level = :fatal if options[:quiet]
41
35
  transport = get_default_client
42
36
  if transport.class == Hash and transport.include? :case then
43
37
  splash_exit transport
@@ -49,18 +43,21 @@ module CLISplash
49
43
  end
50
44
  end
51
45
 
46
+ # Thor method : stopping Splashd
52
47
  desc "stop", "Stopping Splash Daemon"
53
48
  def stop
54
49
  acase = run_as_root :stopdaemon
55
50
  splash_exit acase
56
51
  end
57
52
 
53
+ # Thor method : getting execution status of Splashd
58
54
  desc "status", "Splash Daemon status"
59
55
  def status
60
56
  acase = run_as_root :statusdaemon
61
57
  splash_exit acase
62
58
  end
63
59
 
60
+ # Thor method : sending ping verb over transport in the input queue of Splashd
64
61
  desc "ping HOSTNAME", "send a ping to HOSTNAME daemon over transport (need an active tranport), Typicallly RabbitMQ"
65
62
  def ping(hostname=Socket.gethostname)
66
63
  log = get_logger
@@ -1,11 +1,14 @@
1
1
  # coding: utf-8
2
+
3
+ # module for all Thor subcommands
2
4
  module CLISplash
3
5
 
6
+ # Thor inherited class for documentation management
4
7
  class Documentation < Thor
5
8
  include Splash::Config
6
9
  include Splash::Exiter
7
10
 
8
-
11
+ # Thor method : display the readme file Typicallly formatted in Markdown
9
12
  desc "readme", "Display README file"
10
13
  option :formatted, :type => :boolean, :default => true
11
14
  def readme
@@ -14,7 +17,7 @@ module CLISplash
14
17
  if options[:formatted] then
15
18
  content = TTY::Markdown.parse_file(filename)
16
19
  else
17
- conten = File::readlines(filename).join
20
+ content = File::readlines(filename).join
18
21
  end
19
22
  pager = TTY::Pager.new
20
23
  pager.page(content)
@@ -1,35 +1,39 @@
1
1
  # coding: utf-8
2
+
3
+ # module for all Thor subcommands
2
4
  module CLISplash
3
5
 
6
+ # Thor inherited class for documentation management
4
7
  class Logs < Thor
5
8
  include Splash::Config
6
9
  include Splash::Exiter
10
+ include Splash::Logs
7
11
 
8
-
9
- desc "analyse", "analyze logs in config"
12
+ # Thor method : running Splash configured logs monitors analyse
13
+ desc "analyse", "analyze logs defined in Splash config"
10
14
  def analyse
11
15
  log = get_logger
12
- results = Splash::LogScanner::new
16
+ results = LogScanner::new
13
17
  res = results.analyse
14
- log.info "SPlash Configured logs status :"
18
+ log.info "SPlash Configured log monitors :"
15
19
  full_status = true
16
20
  results.output.each do |result|
17
21
  if result[:status] == :clean then
18
- log.ok "Log : #{result[:log]} : no errors"
22
+ log.ok "Log : #{result[:log]} with label : #{result[:label]} : no errors"
19
23
  log.item "Detected pattern : #{result[:pattern]}"
20
24
  log.item "Nb lines = #{result[:lines]}"
21
25
  elsif result[:status] == :missing then
22
- log.ko "Log : #{result[:log]} : missing !"
26
+ log.ko "Log : #{result[:log]} with label : #{result[:label]} : missing !"
23
27
  log.item "Detected pattern : #{result[:pattern]}"
24
28
  else
25
- log.ko "Log : #{result[:log]} : #{result[:count]} errors"
29
+ log.ko "Log : #{result[:log]} with label : #{result[:label]} : #{result[:count]} errors"
26
30
  log.item "Detected pattern : #{result[:pattern]}"
27
31
  log.item "Nb lines = #{result[:lines]}"
28
32
  end
29
33
 
30
34
  full_status = false unless result[:status] == :clean
31
35
  end
32
- display_status = (full_status)? "OK": "KO"
36
+
33
37
  if full_status then
34
38
  log.ok "Global status : no error found"
35
39
  else
@@ -38,44 +42,50 @@ module CLISplash
38
42
  splash_exit case: :quiet_exit
39
43
  end
40
44
 
41
- desc "monitor", "monitor logs in config"
45
+
46
+ # Thor method : running Splash configured logs monitors analyse and sending to Prometheus Pushgateway
47
+ desc "monitor", "monitor logs defined in Splash config"
42
48
  def monitor
43
- result = Splash::LogScanner::new
49
+ log = get_logger
50
+ log.level = :fatal if options[:quiet]
51
+ result = LogScanner::new
44
52
  result.analyse
45
- result.notify
46
53
  splash_exit result.notify
47
54
 
48
55
  end
49
56
 
50
- desc "show LOG", "show configured log monitoring for LOG"
57
+ # Thor method : display a specific Splash configured log monitor
58
+ desc "show LOG", "show Splash configured log monitoring for LOG"
51
59
  def show(logrecord)
52
60
  log = get_logger
53
- log_record_set = get_config.logs.select{|item| item[:log] == logrecord }
61
+ log_record_set = get_config.logs.select{|item| item[:log] == logrecord or item[:label] == logrecord.to_sym}
54
62
  unless log_record_set.empty? then
55
63
  record = log_record_set.first
56
64
  log.info "Splash log monitor : #{record[:log]}"
57
65
  log.item "pattern : /#{record[:pattern]}/"
66
+ log.item "label : #{record[:label]}"
58
67
  splash_exit case: :quiet_exit
59
68
  else
60
69
  splash_exit case: :not_found, :more => "log not configured"
61
70
  end
62
71
  end
63
72
 
64
- desc "list", "Show configured logs monitoring"
73
+ # Thor method : display the full list of Splash configured log monitors
74
+ desc "list", "List all Splash configured logs monitoring"
65
75
  long_desc <<-LONGDESC
66
76
  Show configured logs monitoring\n
67
77
  with --detail, show logs monitor details
68
78
  LONGDESC
69
- option :detail, :type => :boolean
79
+ option :detail, :type => :boolean, :aliases => "-D"
70
80
  def list
71
81
  log = get_logger
72
82
  log.info "Splash configured log monitoring :"
73
83
  log_record_set = get_config.logs
74
84
  log.ko 'No configured commands found' if log_record_set.empty?
75
85
  log_record_set.each do |record|
76
- log.item "log monitor : #{record[:log]}"
86
+ log.item "log monitor : #{record[:log]} label : #{record[:label]}"
77
87
  if options[:detail] then
78
- log.flat " -> pattern : /#{record[:pattern]}/"
88
+ log.arrow "pattern : /#{record[:pattern]}/"
79
89
  end
80
90
  end
81
91
  splash_exit case: :quiet_exit
@@ -0,0 +1,103 @@
1
+ # coding: utf-8
2
+
3
+ # module for all Thor subcommands
4
+ module CLISplash
5
+
6
+ # Thor inherited class for Processes management
7
+ class Processes < Thor
8
+ include Splash::Config
9
+ include Splash::Exiter
10
+ include Splash::Processes
11
+
12
+ # Thor method : unning Splash configured processes monitors analyse
13
+ desc "analyse", "analyze processes defined in Splash config"
14
+ def analyse
15
+ log = get_logger
16
+ results = ProcessScanner::new
17
+ res = results.analyse
18
+ log.info "Splash Configured process records :"
19
+ full_status = true
20
+ results.output.each do |result|
21
+ if result[:status] == :running then
22
+ log.ok "Process : #{result[:process]} : running"
23
+ log.item "Detected patterns : "
24
+ result[:patterns].each do |pattern|
25
+ log.arrow "/#{pattern}/"
26
+ end
27
+ log.item "CPU usage in % : #{result[:cpu]} "
28
+ log.item "Memory usage in % : #{result[:mem]} "
29
+ else
30
+ log.ko "Process : #{result[:process]} : inexistant"
31
+ log.item "Detected patterns : "
32
+ result[:patterns].each do |pattern|
33
+ log.arrow "/#{pattern}/"
34
+ end
35
+ end
36
+
37
+ full_status = false unless result[:status] == :running
38
+ end
39
+
40
+ if full_status then
41
+ log.ok "Global status : no error found"
42
+ else
43
+ log.error "Global status : some error found"
44
+ end
45
+ splash_exit case: :quiet_exit
46
+ end
47
+
48
+
49
+ # Thor method : running Splash configured processes monitors analyse and sending to Prometheus Pushgateway
50
+ desc "monitor", "monitor processes defined in Splash config"
51
+ def monitor
52
+ log = get_logger
53
+ log.level = :fatal if options[:quiet]
54
+ result = ProcessScanner::new
55
+ result.analyse
56
+ splash_exit result.notify
57
+ end
58
+
59
+ # Thor method : display a specific Splash configured process monitor
60
+ desc "show PROCESS", "show Splash configured process record for PROCESS"
61
+ def show(record)
62
+ log = get_logger
63
+ process_recordset = get_config.processes.select{|item| item[:process] == record }
64
+ unless process_recordset.empty? then
65
+ record = process_recordset.first
66
+ log.item "Process monitor : #{record[:process]}"
67
+ log.arrow "patterns :"
68
+ record[:patterns].each do |pattern|
69
+ log.flat " - /#{pattern}/"
70
+ end
71
+ splash_exit case: :quiet_exit
72
+ else
73
+ splash_exit case: :not_found, :more => "Process not configured"
74
+ end
75
+ end
76
+
77
+ # Thor method : display the full list of Splash configured processes monitors
78
+ desc "list", "List all Splash configured process records"
79
+ long_desc <<-LONGDESC
80
+ List all Splash configured processes record\n
81
+ with --detail, show process records details
82
+ LONGDESC
83
+ option :detail, :type => :boolean, :aliases => "-D"
84
+ def list
85
+ log = get_logger
86
+ log.info "Splash configured process records :"
87
+ process_recordset = get_config.processes
88
+ log.ko 'No configured process found' if process_recordset.empty?
89
+ process_recordset.each do |record|
90
+ log.item "Process monitor : #{record[:process]}"
91
+ if options[:detail] then
92
+ log.arrow "patterns :"
93
+ record[:patterns].each do |pattern|
94
+ log.flat " - /#{pattern}/"
95
+ end
96
+ end
97
+ end
98
+ splash_exit case: :quiet_exit
99
+ end
100
+
101
+ end
102
+
103
+ end
@@ -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
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+
3
+ # module for all Thor subcommands
4
+ module CLISplash
5
+
6
+ # Thor inherited class for Processes management
7
+ class WebAdmin < Thor
8
+ include Splash::WebAdmin::Controller
9
+ include Splash::Config
10
+ include Splash::Exiter
11
+ include Splash::Helpers
12
+
13
+
14
+ # Thor method : stopping Splash Webadmin
15
+ desc "stop", "Stopping Splash Webadmin Daemon"
16
+ def stop
17
+ acase = run_as_root :stopdaemon, options
18
+ splash_exit acase
19
+ end
20
+
21
+ # Thor method : getting execution status of Splashd
22
+ desc "status", "Splash WebAdmin Daemon status"
23
+ def status
24
+ acase = run_as_root :statusdaemon, options
25
+ splash_exit acase
26
+ end
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+ # Thor method : getting execution status of Splash WebAdmin
35
+ long_desc <<-LONGDESC
36
+ Starting Splash Daemon\n
37
+ LONGDESC
38
+ desc "start", "Splash WebAdmin Daemon status"
39
+ def start
40
+ acase = run_as_root :startdaemon
41
+ splash_exit acase
42
+ end
43
+
44
+ end
45
+
46
+ end