prometheus-splash 0.4.4 → 0.6.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 +72 -3
- data/README.md +58 -60
- data/bin/splash +13 -5
- data/config/splash.yml +26 -2
- 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 +29 -3
- data/lib/splash/cli/commands.rb +82 -33
- data/lib/splash/cli/config.rb +25 -4
- data/lib/splash/cli/daemon.rb +11 -14
- data/lib/splash/cli/documentation.rb +5 -2
- data/lib/splash/cli/logs.rb +27 -17
- data/lib/splash/cli/process.rb +103 -0
- data/lib/splash/cli/webadmin.rb +46 -0
- data/lib/splash/commands.rb +144 -119
- data/lib/splash/config.rb +160 -2
- data/lib/splash/config/flush.rb +30 -0
- data/lib/splash/config/sanitycheck.rb +6 -1
- data/lib/splash/config/service.rb +33 -0
- data/lib/splash/config/setup.rb +8 -3
- data/lib/splash/constants.rb +35 -2
- data/lib/splash/daemon.rb +6 -0
- data/lib/splash/{controller.rb → daemon/controller.rb} +52 -6
- data/lib/splash/daemon/metrics.rb +103 -0
- data/lib/splash/daemon/orchestrator.rb +161 -0
- data/lib/splash/daemon/orchestrator/grammar.rb +76 -0
- data/lib/splash/daemon/orchestrator/hooks.rb +28 -0
- data/lib/splash/dependencies.rb +14 -2
- data/lib/splash/exiter.rb +15 -0
- data/lib/splash/helpers.rb +81 -49
- data/lib/splash/loggers.rb +48 -17
- data/lib/splash/loggers/cli.rb +18 -3
- data/lib/splash/loggers/daemon.rb +23 -4
- data/lib/splash/loggers/dual.rb +35 -2
- data/lib/splash/loggers/web.rb +51 -0
- data/lib/splash/logs.rb +67 -53
- data/lib/splash/processes.rb +83 -0
- data/lib/splash/templates.rb +10 -0
- data/lib/splash/transports.rb +9 -0
- data/lib/splash/transports/rabbitmq.rb +46 -19
- 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/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 +30 -0
- data/lib/splash/webadmin/portal/controllers/restclient.rb +19 -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/prometheus-splash.gemspec +8 -1
- data/spec/helpers_spec.rb +119 -0
- data/templates/ansible-splash/Vagrantfile +1 -1
- data/templates/ansible-splash/deploy.yml +28 -1
- data/templates/ansible-splash/group_vars/DEV.yml +2 -0
- data/templates/ansible-splash/roles/mq/handlers/main.yml +1 -1
- data/templates/ansible-splash/roles/mq/tasks/main.yml +17 -1
- data/templates/ansible-splash/roles/mq/templates/rabbitmq-env.conf.j2 +13 -0
- data/templates/ansible-splash/roles/splash/handlers/main.yml +4 -0
- data/templates/ansible-splash/roles/splash/tasks/main.yml +25 -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
- data/templates/splashd.service +1 -1
- data/test.sh +42 -0
- metadata +157 -11
- data/lib/splash/orchestrator.rb +0 -100
- data/lib/splash/orchestrator/grammar.rb +0 -53
- data/lib/splash/orchestrator/hooks.rb +0 -16
- data/templates/ansible-splash/inventory.prod +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54e538fd7e22b4dc38c1253db96c6e842bf81d1378db0434295c0a827e23bfb7
|
4
|
+
data.tar.gz: c951aaf9aacd398d0944594185fc8d4986de4268162a62cedd69ff0c96d26f9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 110950f5ac22753830d8b6f1fd74eaf86d77c78eb18728613215fc671279aa8c6da577ba3d54250640c747c76f35c66cd35ffd2ccb38cfc47d65a7c47e408b2b
|
7
|
+
data.tar.gz: 18aecf0d1f4f080ec1863ec79e17cc6d0582b5cd7f9efac442162c0095d92658372fa2bad1b3c502dd0e44a731a4fd9fe9710bae3e6a4d00be5759610ad08c1c
|
data/CHANGELOG.md
CHANGED
@@ -12,14 +12,14 @@
|
|
12
12
|
* adding \n for LONGDESC Thor #14
|
13
13
|
* Doc for command name format in YAML #2
|
14
14
|
|
15
|
-
###
|
15
|
+
### CHANGES :
|
16
16
|
|
17
17
|
* RabbitMQ Credentials and vhosts support #16
|
18
18
|
* backend hardening #18
|
19
19
|
* remote show with --hostname #12
|
20
20
|
|
21
21
|
|
22
|
-
###
|
22
|
+
### FEATURES :
|
23
23
|
|
24
24
|
* CLI colors and logger CLI /dual #8
|
25
25
|
* Log for splash daemon #6
|
@@ -55,4 +55,73 @@
|
|
55
55
|
|
56
56
|
### DOC :
|
57
57
|
|
58
|
-
* prepare Vagrantfile and Ansible playbook
|
58
|
+
* prepare Vagrantfile and Ansible playbook
|
59
|
+
|
60
|
+
|
61
|
+
## V 0.4.5 2020/04/17
|
62
|
+
|
63
|
+
### FIX :
|
64
|
+
|
65
|
+
* RabbitMQ Exception catching + refacto connection #31
|
66
|
+
|
67
|
+
|
68
|
+
## V 0.5.0 2020/04/17
|
69
|
+
|
70
|
+
### FIX
|
71
|
+
|
72
|
+
* auto setup root check without /etc/splash.yml #34
|
73
|
+
* empty hostname with --hostname #27
|
74
|
+
* foreground execution control #24
|
75
|
+
* root required for file backend with command last and get #36
|
76
|
+
|
77
|
+
### FEATURES
|
78
|
+
|
79
|
+
* command treeview with --hostname #28
|
80
|
+
* log horodating with PID #35
|
81
|
+
* quiet mode + no-colors and no-emoji #5
|
82
|
+
* correlation id in log for daemon #15
|
83
|
+
* systemd Splashd service installation #32
|
84
|
+
|
85
|
+
|
86
|
+
## V 0.5.1 2020/04/17
|
87
|
+
|
88
|
+
### CHANGES
|
89
|
+
|
90
|
+
* short Alias for commands without --no-[xxxx] #38
|
91
|
+
* REFACTO : namespaces
|
92
|
+
* Splash::Commands
|
93
|
+
* Splash::Log
|
94
|
+
* Splash::Daemon
|
95
|
+
* Splash::Daemon::Orchestrator
|
96
|
+
|
97
|
+
|
98
|
+
### FEATURES
|
99
|
+
|
100
|
+
* flush backend arg in config #41
|
101
|
+
* adding global --debug flag
|
102
|
+
* adding splash Daemon metrics #25
|
103
|
+
|
104
|
+
### DOC
|
105
|
+
|
106
|
+
* default value of mon scheduling 20s => 1m in ansible splash.yml
|
107
|
+
|
108
|
+
|
109
|
+
### FIX
|
110
|
+
|
111
|
+
* Ansible Splash role handler error
|
112
|
+
* Ansible Splash role logrotate copytruncate for splash logs
|
113
|
+
* Prometheus Registry mismatch=> cumulative metrics on each groups #42
|
114
|
+
* logger Dual level conservation #43
|
115
|
+
|
116
|
+
## V 0.5.2 2020/04/18
|
117
|
+
|
118
|
+
### FIX
|
119
|
+
|
120
|
+
* dual logger daemon shutdown foreground error
|
121
|
+
|
122
|
+
## V 0.5.3 2020/04/18
|
123
|
+
|
124
|
+
### FEATURE
|
125
|
+
|
126
|
+
* processes monitoring #23
|
127
|
+
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ SPLASH is **Supervision with Prometheus of Logs and Asynchronous tasks orchestra
|
|
9
9
|
* Web : http://www.ultragreen.net
|
10
10
|
* Github : https://github.com/Ultragreen/prometheus-splash
|
11
11
|
* Rubygems : https://rubygems.org/gems/prometheus-splash
|
12
|
-
* DOC yardoc : https://www.rubydoc.info/gems/prometheus-splash/0.
|
12
|
+
* DOC yardoc : https://www.rubydoc.info/gems/prometheus-splash/0.6.0
|
13
13
|
|
14
14
|
Prometheus Logs and Batchs supervision over PushGateway
|
15
15
|
|
@@ -65,10 +65,12 @@ As root or with rvmsudo, if you use RVM.
|
|
65
65
|
# splash config setup
|
66
66
|
Splash -> setup :
|
67
67
|
* Installing Configuration file : /etc/splash.yml : [OK]
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
👍 Splash Initialisation
|
69
|
+
👍 Installing template file : /etc/splash_execution_report.tpl
|
70
|
+
👍 Creating/Checking pid file path : /var/run/splash
|
71
|
+
👍 Creating/Checking trace file path : /var/run/spla
|
72
|
+
|
73
|
+
*NOTE : you can just type 'splash' withou any arguments, for the first setup because, Splash come with an automatic recovery mode, when configuration file is missing, run at the very beginnning of his the execution*
|
72
74
|
|
73
75
|
*WARNING : if you have already configured Splash, running this command without --preserve flag, RESET the Splash Configuration.*
|
74
76
|
|
@@ -121,7 +123,7 @@ For file/folders if problems is detected, it could be such as :
|
|
121
123
|
run :
|
122
124
|
|
123
125
|
$ splash config version
|
124
|
-
Splash version : 0.0
|
126
|
+
Splash version : 0.6.0, Author : Romain GEORGES <gems@ultragreen.net>
|
125
127
|
Ultragreen (c) 2020 BSD-2-Clause
|
126
128
|
|
127
129
|
|
@@ -652,74 +654,70 @@ TODO
|
|
652
654
|
|
653
655
|
defined in the lib/splash/constants.rb
|
654
656
|
|
655
|
-
```ruby
|
656
657
|
|
657
|
-
|
658
|
-
|
658
|
+
|
659
|
+
# the only one non-overridable by the configuration
|
660
|
+
CONFIG_FILE = "/etc/splash.yml"
|
659
661
|
|
660
662
|
|
661
|
-
TRACE_PATH="/var/run/splash"
|
663
|
+
TRACE_PATH="/var/run/splash"
|
662
664
|
|
663
|
-
DAEMON_LOGMON_SCHEDULING={ :every => '20s'}
|
664
|
-
DAEMON_PROCESS_NAME="Splash : daemon."
|
665
|
-
DAEMON_PID_PATH="/var/run"
|
666
|
-
DAEMON_PID_FILE="splash.pid"
|
667
|
-
DAEMON_STDOUT_TRACE="stdout.txt"
|
668
|
-
DAEMON_STDERR_TRACE="stderr.txt"
|
665
|
+
DAEMON_LOGMON_SCHEDULING={ :every => '20s'}
|
666
|
+
DAEMON_PROCESS_NAME="Splash : daemon."
|
667
|
+
DAEMON_PID_PATH="/var/run"
|
668
|
+
DAEMON_PID_FILE="splash.pid"
|
669
|
+
DAEMON_STDOUT_TRACE="stdout.txt"
|
670
|
+
DAEMON_STDERR_TRACE="stderr.txt"
|
669
671
|
|
670
|
-
AUTHOR="Romain GEORGES"
|
671
|
-
EMAIL = "gems@ultragreen.net"
|
672
|
-
COPYRIGHT="Ultragreen (c) 2020"
|
673
|
-
LICENSE="BSD-2-Clause"
|
672
|
+
AUTHOR="Romain GEORGES"
|
673
|
+
EMAIL = "gems@ultragreen.net"
|
674
|
+
COPYRIGHT="Ultragreen (c) 2020"
|
675
|
+
LICENSE="BSD-2-Clause"
|
674
676
|
|
675
|
-
PROMETHEUS_PUSHGATEWAY_HOST = "localhost"
|
676
|
-
PROMETHEUS_PUSHGATEWAY_PORT = "9091"
|
677
|
+
PROMETHEUS_PUSHGATEWAY_HOST = "localhost"
|
678
|
+
PROMETHEUS_PUSHGATEWAY_PORT = "9091"
|
677
679
|
|
678
|
-
EXECUTION_TEMPLATE="/etc/splash_execution_report.tpl"
|
679
|
-
EXECUTION_TEMPLATE_TOKENS_LIST = [:end_date,:start_date,:cmd_name,:cmd_line,:stdout,:stderr,:desc,:status,:exec_time]
|
680
|
+
EXECUTION_TEMPLATE="/etc/splash_execution_report.tpl"
|
681
|
+
EXECUTION_TEMPLATE_TOKENS_LIST = [:end_date,:start_date,:cmd_name,:cmd_line,:stdout,:stderr,:desc,:status,:exec_time]
|
680
682
|
|
681
|
-
BACKENDS_STRUCT = { :list => [:file,:redis],
|
683
|
+
BACKENDS_STRUCT = { :list => [:file,:redis],
|
682
684
|
:stores => { :execution_trace => { :type => :file, :path => "/var/run/splash" }}}
|
683
|
-
TRANSPORTS_STRUCT = { :list => [:rabbitmq],
|
685
|
+
TRANSPORTS_STRUCT = { :list => [:rabbitmq],
|
684
686
|
:active => :rabbitmq,
|
685
687
|
:rabbitmq => { :url => 'amqp://localhost/'} }
|
686
688
|
|
687
|
-
```
|
688
|
-
|
689
689
|
|
690
690
|
#### Splash CLI return code significations
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
```
|
722
|
-
}
|
691
|
+
|
692
|
+
|
693
|
+
# context execution
|
694
|
+
:not_root => {:message => "This operation need to be run as root (use sudo or rvmsudo)", :code => 10},
|
695
|
+
:options_incompatibility => {:message => "Options incompatibility", :code => 40},
|
696
|
+
:service_dependence_missing => {:message => "Splash Service dependence missing", :code => 60},
|
697
|
+
|
698
|
+
# config
|
699
|
+
:specific_config_required => {:message => "Specific configuration required", :code => 30},
|
700
|
+
:splash_setup_error => {:message => "Splash Setup terminated unsuccessfully", :code => 25},
|
701
|
+
:splash_setup_success => {:message => "Splash Setup terminated successfully", :code => 0},
|
702
|
+
:splash_sanitycheck_error => {:message => "Splash Sanitycheck terminated unsuccessfully", :code => 20},
|
703
|
+
:splash_sanitycheck_success => {:message => "Splash Sanitycheck terminated successfully", :code => 0},
|
704
|
+
:configuration_error => {:message => "Splash Configuration Error", :code => 50},
|
705
|
+
|
706
|
+
|
707
|
+
# global
|
708
|
+
:quiet_exit => {:code => 0},
|
709
|
+
|
710
|
+
# events
|
711
|
+
:interrupt => {:message => "Splash user operation interrupted", :code => 33},
|
712
|
+
|
713
|
+
# request
|
714
|
+
:not_found => {:message => "Object not found", :code => 44},
|
715
|
+
:already_exist => {:message => "Object already exist", :code => 48},
|
716
|
+
|
717
|
+
# daemon
|
718
|
+
:status_ok => {:message => "Status OK", :code => 0},
|
719
|
+
:status_ko => {:message => "Status KO", :code => 31}
|
720
|
+
|
723
721
|
|
724
722
|
### In the Futur ?
|
725
723
|
|
data/bin/splash
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
# coding: utf-8
|
3
3
|
|
4
|
+
# major include
|
4
5
|
require 'splash/dependencies'
|
5
6
|
require 'splash/cli'
|
6
7
|
|
@@ -13,12 +14,19 @@ include Splash::Exiter
|
|
13
14
|
include Splash::Loggers
|
14
15
|
include Splash::Config
|
15
16
|
|
17
|
+
# auto setup
|
16
18
|
unless verify_file(name: CONFIG_FILE, mode: "644", owner: user_root, group: group_root).empty? then
|
17
|
-
puts '
|
18
|
-
puts ' => Restart after rebuild (recheck for homemade templates) :'
|
19
|
+
puts 'Splash need reconfiguration : Auto setup launch'
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
if is_root? then
|
22
|
+
acase = setupsplash
|
23
|
+
splash_exit acase
|
24
|
+
else
|
25
|
+
puts 'ERROR : auto setup not start, because your not root, please run as root :'
|
26
|
+
puts '(sudo or rvmsudo) splash [conf setup]'
|
27
|
+
exit 50
|
28
|
+
end
|
22
29
|
end
|
23
30
|
|
31
|
+
# running Thor
|
24
32
|
CLI.start(ARGV)
|
data/config/splash.yml
CHANGED
@@ -34,6 +34,10 @@
|
|
34
34
|
:daemon:
|
35
35
|
:logmon_scheduling:
|
36
36
|
:every: 20s
|
37
|
+
:metrics_scheduling:
|
38
|
+
:every: 15s
|
39
|
+
:procmon_scheduling:
|
40
|
+
:every: 20s
|
37
41
|
:process_name: "Splash : daemon."
|
38
42
|
:paths:
|
39
43
|
:pid_path: /var/run/splash
|
@@ -46,6 +50,17 @@
|
|
46
50
|
:pushgateway:
|
47
51
|
:host: "localhost"
|
48
52
|
:port: 9091
|
53
|
+
:path: ''
|
54
|
+
:url: "http://localhost:9090/"
|
55
|
+
:webadmin:
|
56
|
+
:port: 9234
|
57
|
+
:ip: 127.0.0.1
|
58
|
+
:proxy: false
|
59
|
+
:process_name: "Splash : WebAdmin."
|
60
|
+
:files:
|
61
|
+
:stdout_trace: stdout_webadmin.txt
|
62
|
+
:stderr_trace: stderr_webadmin.txt
|
63
|
+
:pid_file: splash_webadmin.pid
|
49
64
|
|
50
65
|
|
51
66
|
### configuration of commands and scheduling
|
@@ -102,7 +117,16 @@
|
|
102
117
|
|
103
118
|
### configuration of monitored logs
|
104
119
|
:logs:
|
105
|
-
- :
|
120
|
+
- :label: :log_app_1
|
121
|
+
:log: /tmp/test
|
106
122
|
:pattern: ERROR
|
107
|
-
- :
|
123
|
+
- :label: :log_app_2
|
124
|
+
:log: /tmp/test2
|
108
125
|
:pattern: ERROR
|
126
|
+
|
127
|
+
|
128
|
+
### configuration of monitored processes
|
129
|
+
:processes:
|
130
|
+
- :process: cron
|
131
|
+
:patterns:
|
132
|
+
- cron
|
data/lib/splash/backends.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Dir[File.dirname(__FILE__) + '/backends/*.rb'].each {|file| require file }
|
3
3
|
|
4
|
+
# base Splash Module
|
4
5
|
module Splash
|
6
|
+
|
7
|
+
# generic backends module
|
5
8
|
module Backends
|
6
9
|
include Splash::Config
|
7
10
|
include Splash::Constants
|
8
11
|
|
12
|
+
# factory for backend
|
13
|
+
# @param [Symbol] store the name of the store actually in [:execution_trace]
|
14
|
+
# @return [Splash::Backends::<Type>|Hash] with type in [:redis,:file] or Exiter case :configuration_error
|
9
15
|
def get_backend(store)
|
10
16
|
backend = get_config[:backends][:stores][store][:type].to_s
|
11
17
|
aclass = "Splash::Backends::#{backend.capitalize}"
|
data/lib/splash/backends/file.rb
CHANGED
@@ -1,46 +1,86 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash Module
|
2
4
|
module Splash
|
5
|
+
# generic backends module
|
3
6
|
module Backends
|
7
|
+
|
8
|
+
# File backend definition
|
4
9
|
class File
|
5
10
|
include Splash::Config
|
6
11
|
include Splash::Exiter
|
7
12
|
include Splash::Helpers
|
8
13
|
include Splash::Loggers
|
9
14
|
|
15
|
+
# Constructor
|
16
|
+
# @param [Symbol] store name in [:execution_trace] actually (see config and constants )
|
17
|
+
# @return [Splash::Backends::File] a File backend
|
10
18
|
def initialize(store)
|
11
19
|
@config = get_config[:backends][:stores][store]
|
12
20
|
@path = @config[:path]
|
13
21
|
ensure_backend
|
14
22
|
end
|
15
23
|
|
24
|
+
# return the list of find records in backend for a specific pattern
|
25
|
+
# @param [String] pattern shell regexp
|
26
|
+
# @return [Array] list of record
|
16
27
|
def list(pattern='*')
|
17
28
|
pattern = suffix_trace(pattern)
|
18
29
|
return Dir.glob("#{@path}/#{pattern}").map{|item| ::File.basename(item,".trace") }
|
19
30
|
end
|
20
31
|
|
32
|
+
|
33
|
+
# return value of queried record
|
34
|
+
# @param [Hash] options
|
35
|
+
# @option options [Symbol] :key the name of the record
|
36
|
+
# @return [String] content value of record
|
21
37
|
def get(options)
|
22
38
|
return ::File.readlines("#{@path}/#{suffix_trace(options[:key])}").join
|
23
39
|
end
|
24
40
|
|
41
|
+
# defined and store value for specified key
|
42
|
+
# @param [Hash] options
|
43
|
+
# @option options [Symbol] :key the name of the record
|
44
|
+
# @option options [Symbol] :value the content value of the record
|
45
|
+
# @return [String] content value of record
|
25
46
|
def put(options)
|
26
47
|
::File.open("#{@path}/#{suffix_trace(options[:key])}", 'w') { |file|
|
27
48
|
file.write options[:value]
|
28
49
|
}
|
29
50
|
end
|
30
51
|
|
52
|
+
# delete a specific record
|
53
|
+
# @param [Hash] options
|
54
|
+
# @option options [Symbol] :key the name of the record
|
55
|
+
# @return [Boolean] status of the operation
|
31
56
|
def del(options)
|
32
57
|
::File.unlink("#{@path}/#{suffix_trace(options[:key])}") if File.exist?("#{@path}/#{suffix_trace(options[:key])}")
|
33
58
|
end
|
34
59
|
|
60
|
+
# verifiy a specific record existance
|
61
|
+
# @param [Hash] options
|
62
|
+
# @option options [Symbol] :key the name of the record
|
63
|
+
# @return [Boolean] presence of the record
|
35
64
|
def exist?(options)
|
36
65
|
return ::File.exist?("#{@path}/#{suffix_trace(options[:key])}")
|
37
66
|
end
|
38
67
|
|
68
|
+
# flush all records in backend
|
69
|
+
def flush
|
70
|
+
Dir.glob("#{@path}/*.trace").each { |file| ::File.delete(file)}
|
71
|
+
end
|
72
|
+
|
39
73
|
private
|
74
|
+
|
75
|
+
# File backend specific method for suffixing record name with .trace for filename
|
76
|
+
# @param [String] astring
|
77
|
+
# @return [String] suffixed string
|
40
78
|
def suffix_trace(astring)
|
41
79
|
return "#{astring}.trace"
|
42
80
|
end
|
43
81
|
|
82
|
+
# File backend specific method to test backend, correcting if requiered, spool path checking
|
83
|
+
# @return [True|Hash] Exiter case :configuration_error if failing to correct backend
|
44
84
|
def ensure_backend
|
45
85
|
unless verify_folder(name: @config[:path], mode: "644", owner: get_config.user_root, group: get_config.group_root).empty? then
|
46
86
|
get_logger.warn "File Backend folder : #{@config[:path]} is missing"
|
@@ -1,57 +1,100 @@
|
|
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]
|
9
19
|
conf = { :host => @config[:host], :port => @config[:port], :db => @config[:base].to_i}
|
10
20
|
conf[:password] = @config[:auth] if @config[:auth]
|
11
21
|
@store = ::Redis.new conf
|
12
|
-
|
22
|
+
#@redis_cli_cmd = `which redis-cli`
|
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
|
-
|
41
|
-
|
72
|
+
#`#{@redis_cli_cmd} -n #{@config[:base]} flushdb`
|
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
|