Class: ForemanRhCloud::Ping
- Inherits:
-
Object
- Object
- ForemanRhCloud::Ping
show all
- Extended by:
- CertAuth
- Defined in:
- app/models/foreman_rh_cloud/ping.rb
Constant Summary
collapse
- OK_RETURN_CODE =
'ok'.freeze
- FAIL_RETURN_CODE =
'FAIL'.freeze
Class Method Summary
collapse
Methods included from CertAuth
cert_auth_available?, execute_cloud_request, foreman_certificate
#candlepin_id_cert, #cp_owner_id, #upstream_owner
#execute_cloud_request
Class Method Details
.exception_watch(result, &blk) ⇒ Object
31
32
33
|
# File 'app/models/foreman_rh_cloud/ping.rb', line 31
def exception_watch(result, &blk)
::Katello::Ping.exception_watch(result, &blk)
end
|
.iop_smart_proxy_url ⇒ Object
9
10
11
|
# File 'app/models/foreman_rh_cloud/ping.rb', line 9
def iop_smart_proxy_url
@iop_smart_proxy_url ||= ForemanRhCloud.iop_smart_proxy.url
end
|
.logger ⇒ Object
65
66
67
|
# File 'app/models/foreman_rh_cloud/ping.rb', line 65
def logger
Rails.logger
end
|
.ping ⇒ Object
35
36
37
|
# File 'app/models/foreman_rh_cloud/ping.rb', line 35
def ping
ping_services
end
|
.ping! ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/models/foreman_rh_cloud/ping.rb', line 39
def ping!
result = ping_services
if result[:status] != OK_RETURN_CODE
failed_names = result[:services].reject do |_name, details|
details[:status] == OK_RETURN_CODE
end
raise "The following services have not been started or are reporting errors: #{failed_names.keys.join(', ')}"
end
result
end
|
.ping_service(service_name, service_result_hash) ⇒ Object
83
84
85
86
87
|
# File 'app/models/foreman_rh_cloud/ping.rb', line 83
def ping_service(service_name, service_result_hash)
exception_watch(service_result_hash) do
ping_url(service_urls[service_name])
end
end
|
.ping_services ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/models/foreman_rh_cloud/ping.rb', line 52
def ping_services
result = {}
services.each do |service|
result[service] = {}
ping_service(service, result[service])
end
result = { :services => result }
result[:status] = result[:services].each_value.any? { |v| v[:status] == FAIL_RETURN_CODE } ? FAIL_RETURN_CODE : OK_RETURN_CODE
result
end
|
.ping_url(url) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/models/foreman_rh_cloud/ping.rb', line 69
def ping_url(url)
response = execute_cloud_request(
method: :get,
url: url
)
return {} if response.empty?
begin
result = JSON.parse(response).with_indifferent_access
rescue JSON::ParserError, NoMethodError
result = { :response => response.body&.strip }
end
result
end
|
.service_urls ⇒ Object
13
14
15
16
17
18
|
# File 'app/models/foreman_rh_cloud/ping.rb', line 13
def service_urls
{
:advisor => "#{iop_smart_proxy_url}/api/insights/v1/status/live/",
:vulnerability => "#{iop_smart_proxy_url}/api/vulnerability/v1/apistatus",
}
end
|
.services ⇒ Object
20
21
22
|
# File 'app/models/foreman_rh_cloud/ping.rb', line 20
def services
service_urls.keys
end
|
.status ⇒ Object
24
25
26
27
28
29
|
# File 'app/models/foreman_rh_cloud/ping.rb', line 24
def status
{
iop_smart_proxy_exists: ForemanRhCloud.with_iop_smart_proxy?,
timeUTC: Time.zone.now.getutc,
}
end
|