|
1 | 1 | #!/usr/bin/env ruby |
2 | 2 |
|
3 | | -require 'json' |
4 | | -require 'net/http' |
5 | | -require 'uri' |
6 | | - |
7 | | -# reporting_url fetches the Kuberhealthy reporting endpoint from the environment. |
8 | | -def reporting_url |
9 | | - url = ENV['KH_REPORTING_URL'] |
10 | | - return url if url && !url.empty? |
11 | | - raise 'KH_REPORTING_URL not set' |
12 | | -end |
13 | | - |
14 | | -# run_uuid fetches the unique run identifier from the environment. |
15 | | -def run_uuid |
16 | | - uuid = ENV['KH_RUN_UUID'] |
17 | | - return uuid if uuid && !uuid.empty? |
18 | | - raise 'KH_RUN_UUID not set' |
19 | | -end |
20 | | - |
21 | | -# post_status sends a status report back to Kuberhealthy. |
22 | | -def post_status(ok:, errors: []) |
23 | | - uri = URI(reporting_url) |
24 | | - req = Net::HTTP::Post.new(uri) |
25 | | - req['Content-Type'] = 'application/json' |
26 | | - req['kh-run-uuid'] = run_uuid |
27 | | - req.body = JSON.generate({ ok: ok, errors: errors }) |
28 | | - Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| |
29 | | - http.request(req) |
30 | | - end |
31 | | -end |
32 | | - |
33 | | -# report_success tells Kuberhealthy the check passed. |
34 | | -def report_success |
35 | | - post_status(ok: true, errors: []) |
36 | | -end |
37 | | - |
38 | | -# report_failure tells Kuberhealthy the check failed with messages. |
39 | | -def report_failure(messages) |
40 | | - post_status(ok: false, errors: messages) |
41 | | -end |
| 3 | +require 'kuberhealthy/client' |
42 | 4 |
|
43 | 5 | begin |
44 | 6 | # TODO: add check logic here. For now, always succeed. |
45 | | - report_success |
| 7 | + Kuberhealthy::Client.report_success |
46 | 8 | rescue StandardError => e |
47 | | - report_failure([e.message]) |
| 9 | + Kuberhealthy::Client.report_failure([e.message]) |
48 | 10 | end |
0 commit comments