ntq_tools 0.6.0 → 0.7.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: '019d7dc36a586c41c90f0344dc403b659636885801160c02ce727bce64a67c02'
4
- data.tar.gz: c428933a52c6da37c406d6b7d67506c653144c8db7b0256c7a0ac5979f784a5f
3
+ metadata.gz: 94c540289f3f6ae2a2c2956b0ee7ee132c57eb7091f36e54350f88cbb86762d2
4
+ data.tar.gz: ba67366fe693e767e9a7219b7d9600e03a533d2f1094fa02d3f6b94e532c6393
5
5
  SHA512:
6
- metadata.gz: 16a33bdd9c21bb5c83f4f3b82bc983f8072ce75bf31a144c1056fc364e6a10e03392055e1d4c44c85e6690c5993c6f00e7bd52e7fb028577c1d99fefe22388ef
7
- data.tar.gz: d52ae223a99923e7c85c47d240d81b65f222c2be988aa044b7c0336c12345206382b1ae961a22fa3b9dd4a8010105fe66cf632232816150bdf2a63bf36716c31
6
+ metadata.gz: 223b5fda86121d12cdd0c109aaedfb53551dd4d1c5ea584ee13d5b968f62184e50271c43cd5f4acb47aa1872c545e5d640253db1062b1dfe338b412b8d6f4d1f
7
+ data.tar.gz: 54addce36763c562fd8a8281edebacb3f5262b0b06bfc4eaaa68321e29e4dd79391f915277a9b42deb72c0a703de0bcbcf29ac5a363119577ffaa465457999a8
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
 
@@ -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
data/config/routes.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  NtqTools::Engine.routes.draw do
2
- resource :translation, only: [:update, :show]
3
- get '/translation/refresh' => "translations#refresh"
2
+ get '/check' => "monitors#check"
3
+
4
+ if Rails.env.development?
5
+ resource :translation, only: [:update, :show]
6
+ get '/translation/refresh' => "translations#refresh"
7
+ end
4
8
 
5
9
  if NtqTools.impersonation_enabled && NtqTools.impersonation_user_models.any? && defined?(Devise) && Rails.env.development?
6
10
  get '/impersonation/users' => "impersonation#index"
@@ -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
@@ -1,3 +1,3 @@
1
1
  module NtqTools
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.1"
3
3
  end
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.6.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-22 00:00:00.000000000 Z
11
+ date: 2024-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '8'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: '6'
22
+ version: '5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '8'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '6'
32
+ version: '5'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: missing_translation
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -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