prometheus-splash 0.5.2 → 0.8.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 +38 -0
- data/README.md +58 -60
- data/bin/splash +3 -0
- data/config/splash.yml +106 -10
- data/lib/splash/backends.rb +7 -0
- data/lib/splash/backends/file.rb +36 -0
- data/lib/splash/backends/redis.rb +44 -1
- data/lib/splash/cli.rb +16 -4
- data/lib/splash/cli/commands.rb +12 -5
- data/lib/splash/cli/config.rb +9 -1
- data/lib/splash/cli/daemon.rb +49 -2
- data/lib/splash/cli/documentation.rb +5 -2
- data/lib/splash/cli/logs.rb +21 -13
- data/lib/splash/cli/process.rb +103 -0
- data/lib/splash/cli/sequences.rb +114 -0
- data/lib/splash/cli/transfers.rb +206 -0
- data/lib/splash/cli/webadmin.rb +46 -0
- data/lib/splash/commands.rb +26 -4
- data/lib/splash/config.rb +184 -23
- data/lib/splash/config/flush.rb +9 -1
- 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 +41 -10
- data/lib/splash/daemon.rb +5 -1
- data/lib/splash/daemon/controller.rb +31 -11
- data/lib/splash/daemon/metrics.rb +47 -22
- data/lib/splash/daemon/orchestrator.rb +141 -36
- data/lib/splash/daemon/orchestrator/grammar.rb +40 -5
- data/lib/splash/daemon/orchestrator/hooks.rb +10 -0
- data/lib/splash/dependencies.rb +19 -0
- data/lib/splash/exiter.rb +14 -0
- data/lib/splash/helpers.rb +93 -46
- data/lib/splash/loggers.rb +30 -4
- data/lib/splash/loggers/cli.rb +18 -11
- data/lib/splash/loggers/daemon.rb +14 -3
- data/lib/splash/loggers/dual.rb +14 -1
- data/lib/splash/loggers/web.rb +51 -0
- data/lib/splash/logs.rb +16 -5
- data/lib/splash/processes.rb +83 -0
- data/lib/splash/sequences.rb +105 -0
- data/lib/splash/templates.rb +10 -0
- data/lib/splash/transfers.rb +224 -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 +27 -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 +31 -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 +36 -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 +123 -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 +16 -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 +12 -3
- data/spec/helpers_spec.rb +119 -0
- metadata +196 -8
@@ -1,8 +1,18 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash Module
|
2
4
|
module Splash
|
5
|
+
|
6
|
+
# generic backends module
|
3
7
|
module Backends
|
8
|
+
|
9
|
+
# Redis backend definition
|
4
10
|
class Redis
|
5
11
|
include Splash::Config
|
12
|
+
|
13
|
+
# Constructor
|
14
|
+
# @param [Symbol] store name in [:execution_trace] actually (see config and constants )
|
15
|
+
# @return [Splash::Backends::Redis] a Redis backend
|
6
16
|
def initialize(store)
|
7
17
|
@hostname = Socket.gethostname
|
8
18
|
@config = get_config[:backends][:stores][store]
|
@@ -13,45 +23,78 @@ module Splash
|
|
13
23
|
@store.auth(@config[:auth]) if @config[:auth]
|
14
24
|
end
|
15
25
|
|
26
|
+
# return the list of find records in backend for a specific pattern
|
27
|
+
# @param [String] hostname optionnal (default : local hostname)
|
28
|
+
# @param [String] pattern shell regexp
|
29
|
+
# @return [Array] list of record (for all hostname if hostname is specified)
|
16
30
|
def list(pattern='*', hostname = @hostname)
|
17
31
|
return @store.keys("#{hostname}##{pattern}").map{|item| item = remove_hostname(item)}
|
18
32
|
end
|
19
33
|
|
34
|
+
# return the list of find records in backend for a specific pattern, without hostname Checking
|
35
|
+
# Redis Backend specific method
|
36
|
+
# @param [String] pattern shell regexp
|
37
|
+
# @return [Array] list of record (for all hostname if hostname is specified)
|
20
38
|
def listall(pattern='*')
|
21
39
|
return @store.keys(pattern)
|
22
40
|
end
|
23
41
|
|
42
|
+
# return value of queried record
|
43
|
+
# @param [Hash] options
|
44
|
+
# @option options [Symbol] :key the name of the record
|
45
|
+
# @return [String] content value of record
|
24
46
|
def get(options)
|
25
47
|
hostname = (options[:hostname])? options[:hostname] : @hostname
|
26
48
|
return @store.get(prefix_hostname(options[:key],hostname))
|
27
49
|
end
|
28
50
|
|
51
|
+
# defined and store value for specified key
|
52
|
+
# @param [Hash] options
|
53
|
+
# @option options [Symbol] :key the name of the record
|
54
|
+
# @option options [Symbol] :value the content value of the record
|
55
|
+
# @return [String] content value of record
|
29
56
|
def put(options)
|
30
57
|
hostname = (options[:hostname])? options[:hostname] : @hostname
|
31
58
|
@store.set prefix_hostname(options[:key],hostname), options[:value]
|
32
59
|
end
|
33
60
|
|
61
|
+
# delete a specific record
|
62
|
+
# @param [Hash] options
|
63
|
+
# @option options [Symbol] :key the name of the record
|
64
|
+
# @return [Boolean] status of the operation
|
34
65
|
def del(options)
|
35
66
|
hostname = (options[:hostname])? options[:hostname] : @hostname
|
36
67
|
@store.del prefix_hostname(options[:key],hostname)
|
37
68
|
end
|
38
69
|
|
70
|
+
# flush all records in backend
|
39
71
|
def flush
|
40
72
|
#`#{@redis_cli_cmd} -n #{@config[:base]} flushdb`
|
41
73
|
@store.flushdb
|
42
74
|
end
|
43
75
|
|
76
|
+
# verifiy a specific record existance
|
77
|
+
# @param [Hash] options
|
78
|
+
# @option options [Symbol] :key the name of the record
|
79
|
+
# @return [Boolean] presence of the record
|
44
80
|
def exist?(options)
|
45
81
|
hostname = (options[:hostname])? options[:hostname] : @hostname
|
46
82
|
return ( not @store.get(prefix_hostname(options[:key],hostname)).nil?)
|
47
83
|
end
|
48
84
|
|
49
85
|
private
|
86
|
+
|
87
|
+
# Redis backend specific method for prefix record name with hostname
|
88
|
+
# @param [String] key
|
89
|
+
# @param [String] hostname
|
90
|
+
# @return [String] prefixed string
|
50
91
|
def prefix_hostname(key,hostname)
|
51
92
|
return "#{hostname}##{key}"
|
52
93
|
end
|
53
94
|
|
54
|
-
|
95
|
+
# Redis backend specific method for removing hostname of record
|
96
|
+
# @param [String] astring
|
97
|
+
# @return [String] cleaned string
|
55
98
|
def remove_hostname(astring)
|
56
99
|
result = astring.split("#")
|
57
100
|
result.shift
|
data/lib/splash/cli.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Dir[File.dirname(__FILE__) + '/cli/*.rb'].each {|file| require file }
|
3
3
|
|
4
|
+
# The CLI Command structure for Thor
|
4
5
|
class CLI < Thor
|
6
|
+
|
7
|
+
# callback for managing ARGV errors
|
5
8
|
def self.exit_on_failure?
|
6
9
|
true
|
7
10
|
end
|
8
11
|
|
9
|
-
|
12
|
+
# Constructor override to manage debug, colors and emoji options for logger
|
10
13
|
def initialize(*args)
|
11
14
|
super
|
12
15
|
log = get_logger
|
@@ -24,14 +27,23 @@ class CLI < Thor
|
|
24
27
|
|
25
28
|
|
26
29
|
include CLISplash
|
27
|
-
desc "commands SUBCOMMAND ...ARGS", "Managing commands/batchs supervision"
|
30
|
+
desc "commands SUBCOMMAND ...ARGS", "Managing commands/batchs supervision & orchestration"
|
28
31
|
subcommand "commands", Commands
|
32
|
+
desc "sequences SUBCOMMAND ...ARGS", "Managing Sequences of commands"
|
33
|
+
subcommand "sequences", Sequences
|
29
34
|
desc "logs SUBCOMMAND ...ARGS", "Managing Files/Logs supervision"
|
30
35
|
subcommand "logs", Logs
|
31
|
-
desc "
|
36
|
+
desc "processes SUBCOMMAND ...ARGS", "Managing processes supervision"
|
37
|
+
subcommand "processes", Processes
|
38
|
+
desc "daemon SUBCOMMAND ...ARGS", "Splash daemon controller"
|
32
39
|
subcommand "daemon", CLIController
|
33
|
-
desc "config SUBCOMMAND ...ARGS", "
|
40
|
+
desc "config SUBCOMMAND ...ARGS", "Config tools for Splash"
|
34
41
|
subcommand "config", Config
|
35
42
|
desc "documentation SUBCOMMAND ...ARGS", "Documentation for Splash"
|
36
43
|
subcommand "documentation", Documentation
|
44
|
+
desc "webadmin SUBCOMMAND ...ARGS", "Splash Webadmin daemon controller"
|
45
|
+
subcommand "webadmin", WebAdmin
|
46
|
+
desc "transfers SUBCOMMAND ...ARGS", "Managing transfers"
|
47
|
+
subcommand "transfers", Transfers
|
48
|
+
|
37
49
|
end
|
data/lib/splash/cli/commands.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
module CLISplash
|
3
2
|
|
3
|
+
# module for all Thor subcommands
|
4
|
+
module CLISplash
|
4
5
|
|
6
|
+
# Thor inherited class for commands management
|
5
7
|
class Commands < Thor
|
6
8
|
include Splash::Config
|
7
9
|
include Splash::Backends
|
@@ -11,6 +13,8 @@ module CLISplash
|
|
11
13
|
include Splash::Loggers
|
12
14
|
include Splash::Commands
|
13
15
|
|
16
|
+
|
17
|
+
# Thor method : execution of command
|
14
18
|
desc "execute NAME", "run for command/sequence or ack result"
|
15
19
|
long_desc <<-LONGDESC
|
16
20
|
execute command or sequence or ack result\n
|
@@ -74,6 +78,7 @@ module CLISplash
|
|
74
78
|
end
|
75
79
|
|
76
80
|
|
81
|
+
# Thor method : scheduling commands
|
77
82
|
desc "schedule NAME", "Schedule excution of command on Splash daemon"
|
78
83
|
long_desc <<-LONGDESC
|
79
84
|
Schedule excution of command on Splash daemon\n
|
@@ -116,7 +121,7 @@ module CLISplash
|
|
116
121
|
|
117
122
|
end
|
118
123
|
|
119
|
-
|
124
|
+
# Thor method : getting a treeview of sequence of commands
|
120
125
|
desc "treeview", "Show commands sequence tree"
|
121
126
|
long_desc <<-LONGDESC
|
122
127
|
Show commands sequence tree\n
|
@@ -128,7 +133,7 @@ module CLISplash
|
|
128
133
|
log = get_logger
|
129
134
|
if options[:hostname] then
|
130
135
|
options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
|
131
|
-
log.info "Remote Splash
|
136
|
+
log.info "Remote Splash treeview command on #{options[:hostname]}:"
|
132
137
|
log.info "ctrl+c for interrupt"
|
133
138
|
begin
|
134
139
|
transport = get_default_client
|
@@ -164,6 +169,7 @@ module CLISplash
|
|
164
169
|
end
|
165
170
|
|
166
171
|
|
172
|
+
# Thor method : getting the list of available commands in splash config
|
167
173
|
desc "list", "Show configured commands"
|
168
174
|
long_desc <<-LONGDESC
|
169
175
|
Show configured commands\n
|
@@ -213,7 +219,7 @@ module CLISplash
|
|
213
219
|
splash_exit case: :quiet_exit
|
214
220
|
end
|
215
221
|
|
216
|
-
|
222
|
+
# Thor method: getting informations about a specific splash configuration defined command
|
217
223
|
desc "show COMMAND", "Show specific configured command COMMAND"
|
218
224
|
long_desc <<-LONGDESC
|
219
225
|
Show specific configured command COMMAND\n
|
@@ -259,7 +265,7 @@ module CLISplash
|
|
259
265
|
end
|
260
266
|
end
|
261
267
|
|
262
|
-
|
268
|
+
# Thor method : getting information on the last execution of a command
|
263
269
|
desc "lastrun COMMAND", "Show last running result for specific configured command COMMAND"
|
264
270
|
long_desc <<-LONGDESC
|
265
271
|
Show last running result for specific configured command COMMAND\n
|
@@ -299,6 +305,7 @@ module CLISplash
|
|
299
305
|
end
|
300
306
|
end
|
301
307
|
|
308
|
+
# Thor method : getting the list of avaibles executions reports
|
302
309
|
desc "getreportlist", "list all executions report results "
|
303
310
|
long_desc <<-LONGDESC
|
304
311
|
list all executions report results\n
|
data/lib/splash/cli/config.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
3
|
+
# module for all Thor subcommands
|
2
4
|
module CLISplash
|
3
5
|
|
6
|
+
# Thor inherited class for configuration management
|
4
7
|
class Config < Thor
|
5
8
|
include Splash::ConfigUtilities
|
6
9
|
include Splash::Helpers
|
7
10
|
include Splash::Exiter
|
8
11
|
include Splash::Loggers
|
9
12
|
|
10
|
-
|
13
|
+
# Thor method : running of Splash setup
|
11
14
|
desc "setup", "Setup installation fo Splash"
|
12
15
|
long_desc <<-LONGDESC
|
13
16
|
Setup installation fo Splash\n
|
@@ -19,12 +22,14 @@ module CLISplash
|
|
19
22
|
splash_exit acase
|
20
23
|
end
|
21
24
|
|
25
|
+
# Thor method : running of Splash sanitycheck
|
22
26
|
desc "sanitycheck", "Verify installation fo Splash"
|
23
27
|
def sanitycheck
|
24
28
|
acase = run_as_root :checkconfig
|
25
29
|
splash_exit acase
|
26
30
|
end
|
27
31
|
|
32
|
+
# Thor method : Getting the current Splash version
|
28
33
|
desc "version", "Display current Splash version"
|
29
34
|
def version
|
30
35
|
log = get_logger
|
@@ -34,12 +39,15 @@ module CLISplash
|
|
34
39
|
splash_exit case: :quiet_exit
|
35
40
|
end
|
36
41
|
|
42
|
+
# Thor method : Installing Splashd Systemd service file
|
37
43
|
desc "service", "Install Splashd Systemd service"
|
38
44
|
def service
|
39
45
|
acase = run_as_root :addservice
|
40
46
|
splash_exit acase
|
41
47
|
end
|
42
48
|
|
49
|
+
|
50
|
+
# Thor method : flushing configured backend
|
43
51
|
desc "flushbackend", "Flush configured backend"
|
44
52
|
def flushbackend
|
45
53
|
acase = run_as_root :flush_backend
|
data/lib/splash/cli/daemon.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
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
8
|
include Splash::Daemon::Controller
|
6
9
|
include Splash::Transports
|
@@ -8,6 +11,7 @@ module CLISplash
|
|
8
11
|
include Splash::Loggers
|
9
12
|
|
10
13
|
|
14
|
+
# Thor method : starting Splashd
|
11
15
|
option :foreground, :type => :boolean, :aliases => "-F"
|
12
16
|
option :purge, :type => :boolean, default: true
|
13
17
|
option :scheduling, :type => :boolean, default: true
|
@@ -23,7 +27,7 @@ module CLISplash
|
|
23
27
|
splash_exit acase
|
24
28
|
end
|
25
29
|
|
26
|
-
|
30
|
+
# Thor method : purge transport input queue of Splashd daemon
|
27
31
|
desc "purge", "Purge Transport Input queue of Daemon"
|
28
32
|
def purge
|
29
33
|
log = get_logger
|
@@ -39,18 +43,21 @@ module CLISplash
|
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
46
|
+
# Thor method : stopping Splashd
|
42
47
|
desc "stop", "Stopping Splash Daemon"
|
43
48
|
def stop
|
44
49
|
acase = run_as_root :stopdaemon
|
45
50
|
splash_exit acase
|
46
51
|
end
|
47
52
|
|
53
|
+
# Thor method : getting execution status of Splashd
|
48
54
|
desc "status", "Splash Daemon status"
|
49
55
|
def status
|
50
56
|
acase = run_as_root :statusdaemon
|
51
57
|
splash_exit acase
|
52
58
|
end
|
53
59
|
|
60
|
+
# Thor method : sending ping verb over transport in the input queue of Splashd
|
54
61
|
desc "ping HOSTNAME", "send a ping to HOSTNAME daemon over transport (need an active tranport), Typicallly RabbitMQ"
|
55
62
|
def ping(hostname=Socket.gethostname)
|
56
63
|
log = get_logger
|
@@ -67,7 +74,47 @@ module CLISplash
|
|
67
74
|
splash_exit case: :quiet_exit
|
68
75
|
end
|
69
76
|
rescue Interrupt
|
70
|
-
splash_exit status: :error, case: :interrupt, more: "
|
77
|
+
splash_exit status: :error, case: :interrupt, more: "ping Command"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Thor method : sending get_jobs verb over transport in the input queue of Splashd
|
82
|
+
desc "getjobs", "send a get_jobs verb to HOSTNAME daemon over transport (need an active tranport), Typicallly RabbitMQ"
|
83
|
+
def getjobs(hostname=Socket.gethostname)
|
84
|
+
log = get_logger
|
85
|
+
log.info "ctrl+c for interrupt"
|
86
|
+
begin
|
87
|
+
transport = get_default_client
|
88
|
+
if transport.class == Hash and transport.include? :case then
|
89
|
+
splash_exit transport
|
90
|
+
else
|
91
|
+
log.receive transport.execute({ :verb => :get_jobs,
|
92
|
+
:return_to => "splash.#{Socket.gethostname}.returncli",
|
93
|
+
:queue => "splash.#{hostname}.input" })
|
94
|
+
splash_exit case: :quiet_exit
|
95
|
+
end
|
96
|
+
rescue Interrupt
|
97
|
+
splash_exit status: :error, case: :interrupt, more: "getjobs Command"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Thor method : sending reset verb over transport in the input queue of Splashd
|
102
|
+
desc "getjobs", "send a reset verb to HOSTNAME daemon over transport (need an active tranport), Typicallly RabbitMQ"
|
103
|
+
def reset(hostname=Socket.gethostname)
|
104
|
+
log = get_logger
|
105
|
+
log.info "ctrl+c for interrupt"
|
106
|
+
begin
|
107
|
+
transport = get_default_client
|
108
|
+
if transport.class == Hash and transport.include? :case then
|
109
|
+
splash_exit transport
|
110
|
+
else
|
111
|
+
log.receive transport.execute({ :verb => :reset,
|
112
|
+
:return_to => "splash.#{Socket.gethostname}.returncli",
|
113
|
+
:queue => "splash.#{hostname}.input" })
|
114
|
+
splash_exit case: :quiet_exit
|
115
|
+
end
|
116
|
+
rescue Interrupt
|
117
|
+
splash_exit status: :error, case: :interrupt, more: "reset Command"
|
71
118
|
end
|
72
119
|
end
|
73
120
|
|
@@ -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
|
-
|
20
|
+
content = File::readlines(filename).join
|
18
21
|
end
|
19
22
|
pager = TTY::Pager.new
|
20
23
|
pager.page(content)
|
data/lib/splash/cli/logs.rb
CHANGED
@@ -1,36 +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
|
7
10
|
include Splash::Logs
|
8
11
|
|
9
|
-
|
10
|
-
desc "analyse", "analyze logs in config"
|
12
|
+
# Thor method : running Splash configured logs monitors analyse
|
13
|
+
desc "analyse", "analyze logs defined in Splash config"
|
11
14
|
def analyse
|
12
15
|
log = get_logger
|
13
16
|
results = LogScanner::new
|
14
17
|
res = results.analyse
|
15
|
-
log.info "SPlash Configured
|
18
|
+
log.info "SPlash Configured log monitors :"
|
16
19
|
full_status = true
|
17
20
|
results.output.each do |result|
|
18
21
|
if result[:status] == :clean then
|
19
|
-
log.ok "Log : #{result[:log]} : no errors"
|
22
|
+
log.ok "Log : #{result[:log]} with label : #{result[:label]} : no errors"
|
20
23
|
log.item "Detected pattern : #{result[:pattern]}"
|
21
24
|
log.item "Nb lines = #{result[:lines]}"
|
22
25
|
elsif result[:status] == :missing then
|
23
|
-
log.ko "Log : #{result[:log]} : missing !"
|
26
|
+
log.ko "Log : #{result[:log]} with label : #{result[:label]} : missing !"
|
24
27
|
log.item "Detected pattern : #{result[:pattern]}"
|
25
28
|
else
|
26
|
-
log.ko "Log : #{result[:log]} : #{result[:count]} errors"
|
29
|
+
log.ko "Log : #{result[:log]} with label : #{result[:label]} : #{result[:count]} errors"
|
27
30
|
log.item "Detected pattern : #{result[:pattern]}"
|
28
31
|
log.item "Nb lines = #{result[:lines]}"
|
29
32
|
end
|
30
33
|
|
31
34
|
full_status = false unless result[:status] == :clean
|
32
35
|
end
|
33
|
-
|
36
|
+
|
34
37
|
if full_status then
|
35
38
|
log.ok "Global status : no error found"
|
36
39
|
else
|
@@ -39,7 +42,9 @@ module CLISplash
|
|
39
42
|
splash_exit case: :quiet_exit
|
40
43
|
end
|
41
44
|
|
42
|
-
|
45
|
+
|
46
|
+
# Thor method : running Splash configured logs monitors analyse and sending to Prometheus Pushgateway
|
47
|
+
desc "monitor", "monitor logs defined in Splash config"
|
43
48
|
def monitor
|
44
49
|
log = get_logger
|
45
50
|
log.level = :fatal if options[:quiet]
|
@@ -49,21 +54,24 @@ module CLISplash
|
|
49
54
|
|
50
55
|
end
|
51
56
|
|
52
|
-
|
57
|
+
# Thor method : display a specific Splash configured log monitor
|
58
|
+
desc "show LOG", "show Splash configured log monitoring for LOG"
|
53
59
|
def show(logrecord)
|
54
60
|
log = get_logger
|
55
|
-
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}
|
56
62
|
unless log_record_set.empty? then
|
57
63
|
record = log_record_set.first
|
58
64
|
log.info "Splash log monitor : #{record[:log]}"
|
59
65
|
log.item "pattern : /#{record[:pattern]}/"
|
66
|
+
log.item "label : #{record[:label]}"
|
60
67
|
splash_exit case: :quiet_exit
|
61
68
|
else
|
62
69
|
splash_exit case: :not_found, :more => "log not configured"
|
63
70
|
end
|
64
71
|
end
|
65
72
|
|
66
|
-
|
73
|
+
# Thor method : display the full list of Splash configured log monitors
|
74
|
+
desc "list", "List all Splash configured logs monitoring"
|
67
75
|
long_desc <<-LONGDESC
|
68
76
|
Show configured logs monitoring\n
|
69
77
|
with --detail, show logs monitor details
|
@@ -75,9 +83,9 @@ module CLISplash
|
|
75
83
|
log_record_set = get_config.logs
|
76
84
|
log.ko 'No configured commands found' if log_record_set.empty?
|
77
85
|
log_record_set.each do |record|
|
78
|
-
log.item "log monitor : #{record[:log]}"
|
86
|
+
log.item "log monitor : #{record[:log]} label : #{record[:label]}"
|
79
87
|
if options[:detail] then
|
80
|
-
log.
|
88
|
+
log.arrow "pattern : /#{record[:pattern]}/"
|
81
89
|
end
|
82
90
|
end
|
83
91
|
splash_exit case: :quiet_exit
|