ntq_tools 0.5.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/app/controllers/ntq_tools/impersonation_controller.rb +4 -1
- data/app/controllers/ntq_tools/monitors_controller.rb +27 -0
- data/app/controllers/ntq_tools/translations_controller.rb +2 -2
- data/config/routes.rb +7 -3
- data/lib/ntq_tools/monitor.rb +37 -0
- data/lib/ntq_tools/monitors/base.rb +20 -0
- data/lib/ntq_tools/monitors/database.rb +21 -0
- data/lib/ntq_tools/monitors/redis.rb +23 -0
- data/lib/ntq_tools/monitors/sidekiq.rb +22 -0
- data/lib/ntq_tools/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a594621c88b14946e288aa2368c4163b6dcdbffcc6cd13fd5731034497777559
|
4
|
+
data.tar.gz: ec37118491ddd0477344ac0a1f17b5deeecbcf1e14a5da12d43c6f3335ec8b45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d46da61dd5cc76c37fb6f9886ddef63fadda3965c24bc9a2f9e7659bf3844540172e8716423097d69840511cdd107b63f86c41fa24162e1b9f07fdaacc2dc766
|
7
|
+
data.tar.gz: d91a1e25634c89ebabbf52f148f686f2fcd2fc7d9ce7fdaec245d2eccf76d3ea2c4056f94a75246a4deba9deece97f49dbeee082f64a92303bbf352a394fea57
|
data/README.md
CHANGED
@@ -4,6 +4,14 @@ Short description and motivation.
|
|
4
4
|
## Usage
|
5
5
|
How to use my plugin.
|
6
6
|
|
7
|
+
## Monitoring
|
8
|
+
Pour activer le monitoring, veillez à ajouter ces variables d'environnement
|
9
|
+
|
10
|
+
```
|
11
|
+
MONITORING_PASSWORD
|
12
|
+
MONITORING_USERNAME
|
13
|
+
```
|
14
|
+
|
7
15
|
## Installation
|
8
16
|
Add this line to your application's Gemfile:
|
9
17
|
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module NtqTools
|
2
2
|
class ImpersonationController < ::ApplicationController
|
3
|
-
|
3
|
+
skip_before_action :authenticate_user!, raise: false, if: -> { Rails.env.development? }
|
4
|
+
skip_before_action :authenticate_back_user!, raise: false, if: -> { Rails.env.development? }
|
5
|
+
skip_before_action :authenticate_customer!, raise: false, if: -> { Rails.env.development? }
|
6
|
+
|
4
7
|
before_action :check_impersonation_enabled, except: [:config]
|
5
8
|
before_action :model_name_is_valid?, only: [:sign_in]
|
6
9
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'ntq_tools/monitor'
|
2
|
+
module NtqTools
|
3
|
+
class MonitorsController < ActionController::Base
|
4
|
+
|
5
|
+
before_action :check_basic_auth
|
6
|
+
|
7
|
+
def check
|
8
|
+
@status, @services_status = NtqTools::Monitor.check
|
9
|
+
|
10
|
+
respond_to do |format|
|
11
|
+
format.json do
|
12
|
+
render json: { status: @status, services_status: @services_status }, status: @status == 'OK' ? :ok : :service_unavailable
|
13
|
+
end
|
14
|
+
format.html do
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def check_basic_auth
|
22
|
+
authenticate_or_request_with_http_basic do |username, password|
|
23
|
+
username == ENV['MONITORING_USERNAME'] && password == ENV['MONITORING_PASSWORD']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -5,8 +5,8 @@ module NtqTools
|
|
5
5
|
before_action :check_presence_of_key, except: [:refresh]
|
6
6
|
|
7
7
|
def show
|
8
|
-
return
|
9
|
-
|
8
|
+
return render json: { data: nil }, status: 404 unless I18n.exists?(params[:key].to_s)
|
9
|
+
|
10
10
|
render json: {
|
11
11
|
data: I18n.t(params[:key])
|
12
12
|
}, status: 200
|
data/config/routes.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
NtqTools::Engine.routes.draw do
|
2
|
-
|
3
|
-
get '/translation/refresh' => "translations#refresh"
|
2
|
+
get '/check' => "monitors#check"
|
4
3
|
|
5
|
-
if
|
4
|
+
if Rails.env.development?
|
5
|
+
resource :translation, only: [:update, :show]
|
6
|
+
get '/translation/refresh' => "translations#refresh"
|
7
|
+
end
|
8
|
+
|
9
|
+
if NtqTools.impersonation_enabled && NtqTools.impersonation_user_models.any? && defined?(Devise) && Rails.env.development?
|
6
10
|
get '/impersonation/users' => "impersonation#index"
|
7
11
|
get "/impersonation/:model_name/:id/sign_in" => "impersonation#signin"
|
8
12
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'ntq_tools/monitors/redis'
|
2
|
+
require 'ntq_tools/monitors/database'
|
3
|
+
require 'ntq_tools/monitors/sidekiq'
|
4
|
+
|
5
|
+
module NtqTools
|
6
|
+
class Monitor
|
7
|
+
|
8
|
+
# Check if installed services are running, it return a tuple with the status and the services status
|
9
|
+
#
|
10
|
+
# eg: [:ok, [{name: 'redis', status: 'OK'}, {name: 'database', status: 'OK'}]]
|
11
|
+
# eg: [:error, [{name: 'redis', status: 'OK'}, {name: 'database', status: 'ERROR'}]]
|
12
|
+
#
|
13
|
+
# @return [Symbol, Array<Hash>]
|
14
|
+
def self.check
|
15
|
+
services_status = []
|
16
|
+
list.each do |monitor|
|
17
|
+
next unless monitor.is_installed?
|
18
|
+
|
19
|
+
services_status << {
|
20
|
+
name: monitor.name,
|
21
|
+
status: monitor.check ? 'OK' : 'ERROR'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
status = services_status.all? { |service| service[:status] == 'OK' } ? :ok : :error
|
25
|
+
[status, services_status]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.list
|
29
|
+
[
|
30
|
+
::NtqTools::Monitors::Redis,
|
31
|
+
::NtqTools::Monitors::Database,
|
32
|
+
::NtqTools::Monitors::Sidekiq
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module NtqTools
|
2
|
+
module Monitors
|
3
|
+
class Base
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def name
|
7
|
+
"You must define the name method in your monitor class"
|
8
|
+
end
|
9
|
+
|
10
|
+
def is_installed?
|
11
|
+
"You must define the is_installed? method in your monitor class"
|
12
|
+
end
|
13
|
+
|
14
|
+
def check
|
15
|
+
"You must define the check method in your monitor class"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'ntq_tools/monitors/base'
|
2
|
+
module NtqTools
|
3
|
+
module Monitors
|
4
|
+
class Database < Base
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def name
|
8
|
+
"database"
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_installed?
|
12
|
+
defined?(::ActiveRecord).present?
|
13
|
+
end
|
14
|
+
|
15
|
+
def check
|
16
|
+
::ActiveRecord::Base.connection_pool.with_connection { |con| con.active? } rescue false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'ntq_tools/monitors/base'
|
2
|
+
module NtqTools
|
3
|
+
module Monitors
|
4
|
+
class Redis < Base
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def name
|
8
|
+
'redis'
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_installed?
|
12
|
+
::Gem.loaded_specs.has_key?("redis")
|
13
|
+
end
|
14
|
+
|
15
|
+
def check
|
16
|
+
::Sidekiq.redis { |con| con.ping }.present?
|
17
|
+
rescue ::Redis::CannotConnectError
|
18
|
+
false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'ntq_tools/monitors/base'
|
2
|
+
module NtqTools
|
3
|
+
module Monitors
|
4
|
+
class Sidekiq < Base
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def name
|
8
|
+
"sidekiq"
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_installed?
|
12
|
+
::Gem.loaded_specs.has_key?("sidekiq")
|
13
|
+
end
|
14
|
+
|
15
|
+
def check
|
16
|
+
::Sidekiq::ProcessSet.new.any? { |process| process['busy'] }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/ntq_tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ntq_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- app/assets/stylesheets/ntq_tools/application.css
|
59
59
|
- app/controllers/ntq_tools/application_controller.rb
|
60
60
|
- app/controllers/ntq_tools/impersonation_controller.rb
|
61
|
+
- app/controllers/ntq_tools/monitors_controller.rb
|
61
62
|
- app/controllers/ntq_tools/translations_controller.rb
|
62
63
|
- app/helpers/ntq_tools/application_helper.rb
|
63
64
|
- app/jobs/ntq_tools/application_job.rb
|
@@ -70,6 +71,11 @@ files:
|
|
70
71
|
- lib/generators/templates/ntq_tools.rb
|
71
72
|
- lib/ntq_tools.rb
|
72
73
|
- lib/ntq_tools/engine.rb
|
74
|
+
- lib/ntq_tools/monitor.rb
|
75
|
+
- lib/ntq_tools/monitors/base.rb
|
76
|
+
- lib/ntq_tools/monitors/database.rb
|
77
|
+
- lib/ntq_tools/monitors/redis.rb
|
78
|
+
- lib/ntq_tools/monitors/sidekiq.rb
|
73
79
|
- lib/ntq_tools/translations/hash_utils.rb
|
74
80
|
- lib/ntq_tools/translations/translation_tool.rb
|
75
81
|
- lib/ntq_tools/translations/yaml_tool.rb
|