Class: Marty::Diagnostic::Base
- Inherits:
-
Request
- Object
- Request
- Marty::Diagnostic::Base
show all
- Extended by:
- Packer
- Includes:
- ActionView::Helpers::TextHelper
- Defined in:
- lib/marty/diagnostic/base.rb
Constant Summary
collapse
- @@read_only =
Marty::Util.db_in_recovery?
- @@template =
ActionController::Base.new.lookup_context.
find_template('marty/diagnostic/diag').identifier
Class Method Summary
collapse
Methods included from Packer
create_info, error, is_valid_info?, pack, process, process_hash
Methods inherited from Request
op, params, request, request=, scope, ssl?
Class Method Details
.apply_consistency(data) ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/marty/diagnostic/base.rb', line 49
def self.apply_consistency data
diff = get_difference(data)
data.each_with_object({}) do |(node, diagnostic), new_data|
new_data[node] = diagnostic.each_with_object({}) do |(test, info), new_diagnostic|
new_diagnostic[test] = info + { 'consistent' => !diff.include?(test) }
end
end
end
|
.consistent?(data) ⇒ Boolean
58
59
60
|
# File 'lib/marty/diagnostic/base.rb', line 58
def self.consistent? data
process_status_only(data.values).uniq.count == 1
end
|
.diagnostic_fn(opts = {}) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/marty/diagnostic/base.rb', line 15
def self.diagnostic_fn opts = {}
opts.each do |k, v|
send("#{k}=", v)
end
class << self
define_method :generate do
pack do
yield
end
end
end
end
|
.display(data) ⇒ Object
62
63
64
65
66
|
# File 'lib/marty/diagnostic/base.rb', line 62
def self.display data
consistent = consistent?(data)
success = consistent && !fatal?
ERB.new(File.open(@@template).read).result(binding)
end
|
.display_info_css(info) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/marty/diagnostic/base.rb', line 68
def self.display_info_css info
return 'inconsistent' if info.nil? || (info['status'] &&
info['consistent'] == false)
return 'error' unless info['status']
'passed'
end
|
.display_info_description(info) ⇒ Object
76
77
78
|
# File 'lib/marty/diagnostic/base.rb', line 76
def self.display_info_description info
new.simple_format(info ? info['description'] : 'N/A')
end
|
.fatal? ⇒ Boolean
32
33
34
|
# File 'lib/marty/diagnostic/base.rb', line 32
def self.fatal?
name.include?('Fatal')
end
|
.get_difference(data) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/marty/diagnostic/base.rb', line 42
def self.get_difference data
values = process_status_only(data.values)
Marty::DataExporter.hash_array_merge(values, true).map do |test, values|
test if values.uniq.count > 1
end.compact
end
|
.process_status_only(infos) ⇒ Object
36
37
38
39
40
|
# File 'lib/marty/diagnostic/base.rb', line 36
def self.process_status_only infos
return infos unless status_only
infos.map { |info| info.map { |test, result| [test, result['status']] }.to_h }
end
|