doctor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +2 -0
- data/app/analyser/doctor/database_analyser.rb +28 -0
- data/app/analyser/doctor/telnet_analyser.rb +58 -0
- data/app/controllers/doctor/health_check_controller.rb +8 -0
- data/app/use_case/doctor/health_check.rb +33 -0
- data/app/util/doctor/config_manager.rb +14 -0
- data/app/view/doctor/dto/database_result_dto.rb +11 -0
- data/app/view/doctor/dto/telnet_result_dto.rb +16 -0
- data/app/view/doctor/dto/url_result_dto.rb +11 -0
- data/config/routes.rb +3 -0
- data/lib/doctor.rb +6 -0
- data/lib/doctor/engine.rb +5 -0
- data/lib/doctor/version.rb +3 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7dcdd7cfd84b7bb6ba7d04a0254c49464442fd34
|
4
|
+
data.tar.gz: d1a0e88d205b65bc47a4b8649f02c052c2069b84
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 54de54f7f1831ffe063bc62d203add92114cd8b9048c3209e19994a80366252fcc168e45f80e9fb26b2b65bc38907c8b8d6e22b1b5d166b87349ef91ec0b3db7
|
7
|
+
data.tar.gz: 414f78c97a15e2dd4d683a12a6dc2c9c9e685b3a585fde4aa90e312e214e363e004e50a5558ae3fe597dd32d0c3f45a2fbf0f418f9d8a954435b1a8789572930
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Doctor
|
2
|
+
class DatabaseAnalyser
|
3
|
+
def analyse
|
4
|
+
result = []
|
5
|
+
|
6
|
+
Doctor::ConfigManager.active_record_list.each { |active_record|
|
7
|
+
result << validate_database_connection(active_record)
|
8
|
+
}
|
9
|
+
|
10
|
+
result
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def validate_database_connection(active_record)
|
15
|
+
result = {active_record: active_record.model_name}
|
16
|
+
|
17
|
+
begin
|
18
|
+
active_record.first
|
19
|
+
result[:status] = 'ok'
|
20
|
+
rescue Exception => ex
|
21
|
+
result[:error_message] = ex.message
|
22
|
+
result[:status] = 'error'
|
23
|
+
end
|
24
|
+
|
25
|
+
OpenStruct.new(result)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'net/telnet'
|
2
|
+
|
3
|
+
module Doctor
|
4
|
+
DEFAULT_PORT = 80
|
5
|
+
DEFAULT_TIMEOUT = 1
|
6
|
+
DEFAULT_WAIT_TIME = 1
|
7
|
+
|
8
|
+
class TelnetAnalyser
|
9
|
+
def analyse
|
10
|
+
result = []
|
11
|
+
|
12
|
+
Doctor::ConfigManager.url_to_telnet_list.each { |active_record|
|
13
|
+
result << validate_telnet_connection(active_record)
|
14
|
+
}
|
15
|
+
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def validate_telnet_connection(url)
|
21
|
+
result = build_result(url)
|
22
|
+
|
23
|
+
response = nil
|
24
|
+
|
25
|
+
begin
|
26
|
+
response = execute_telnet(url)
|
27
|
+
|
28
|
+
result[:status] = 'ok'
|
29
|
+
rescue Exception => ex
|
30
|
+
result[:error_message] = ex.message
|
31
|
+
result[:status] = 'error'
|
32
|
+
ensure
|
33
|
+
response.close unless response.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
OpenStruct.new(result)
|
37
|
+
end
|
38
|
+
|
39
|
+
def build_result(url)
|
40
|
+
{
|
41
|
+
name: url[:name],
|
42
|
+
host: url[:host],
|
43
|
+
port: url[:port] || DEFAULT_PORT,
|
44
|
+
timeout: url[:timeout] || DEFAULT_TIMEOUT,
|
45
|
+
wait_time: url[:wait_time] || DEFAULT_WAIT_TIME
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def execute_telnet(url)
|
50
|
+
Net::Telnet::new(
|
51
|
+
"Host" => url[:host],
|
52
|
+
"Port" => url[:port] || DEFAULT_PORT,
|
53
|
+
"Timeout" => url[:timeout] || DEFAULT_TIMEOUT,
|
54
|
+
"Waittime" => url[:wait_time] || DEFAULT_WAIT_TIME
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Doctor
|
2
|
+
class HealthCheck
|
3
|
+
def perform
|
4
|
+
result = {}
|
5
|
+
|
6
|
+
result[:telnets] = analyze_telnet
|
7
|
+
result[:databases] = analyze_database
|
8
|
+
|
9
|
+
result
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def analyze_telnet
|
14
|
+
process(TelnetAnalyser, Dto::TelnetResultDto)
|
15
|
+
end
|
16
|
+
|
17
|
+
def analyze_database
|
18
|
+
process(DatabaseAnalyser, Dto::DatabaseResultDto)
|
19
|
+
end
|
20
|
+
|
21
|
+
def process(analyzer_class, dto_class)
|
22
|
+
analyze_result = analyzer_class.new.analyse
|
23
|
+
|
24
|
+
dto_result = []
|
25
|
+
|
26
|
+
analyze_result.each do |result|
|
27
|
+
dto_result << dto_class.new(result)
|
28
|
+
end
|
29
|
+
|
30
|
+
dto_result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Doctor
|
2
|
+
module Dto
|
3
|
+
class TelnetResultDto
|
4
|
+
def initialize(data)
|
5
|
+
@name = data[:name]
|
6
|
+
@host = data[:host]
|
7
|
+
@port = data[:port]
|
8
|
+
@timeout = data[:timeout]
|
9
|
+
@wait_time = data[:wait_time]
|
10
|
+
|
11
|
+
@status = data[:status]
|
12
|
+
@error_message = data[:error_message] unless data[:error_message].nil?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/config/routes.rb
ADDED
data/lib/doctor.rb
ADDED
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: doctor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Write your name
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.5
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.11.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.11.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 10.5.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 10.5.0
|
55
|
+
description: " a longer description or delete this line."
|
56
|
+
email:
|
57
|
+
- Write your email address
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Rakefile
|
63
|
+
- app/analyser/doctor/database_analyser.rb
|
64
|
+
- app/analyser/doctor/telnet_analyser.rb
|
65
|
+
- app/controllers/doctor/health_check_controller.rb
|
66
|
+
- app/use_case/doctor/health_check.rb
|
67
|
+
- app/util/doctor/config_manager.rb
|
68
|
+
- app/view/doctor/dto/database_result_dto.rb
|
69
|
+
- app/view/doctor/dto/telnet_result_dto.rb
|
70
|
+
- app/view/doctor/dto/url_result_dto.rb
|
71
|
+
- config/routes.rb
|
72
|
+
- lib/doctor.rb
|
73
|
+
- lib/doctor/engine.rb
|
74
|
+
- lib/doctor/version.rb
|
75
|
+
homepage:
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata:
|
79
|
+
allowed_push_host: https://rubygems.org
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
- app
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.4.6
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Write a short summary, because Rubygems requires one.
|
101
|
+
test_files: []
|