Puppet Function: complyadm::status_check
- Defined in:
- lib/puppet/functions/complyadm/status_check.rb
- Function type:
- Ruby 4.x API
Overview
containers are running.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/puppet/functions/complyadm/status_check.rb', line 6 Puppet::Functions.create_function(:'complyadm::status_check') do # @param resolvable_hostname The resolvable hostname to check # @return boolean - true if the status api endpoint returns healthy, false if not dispatch :status_check do param 'String', :resolvable_hostname return_type 'Boolean' end def status_check(resolvable_hostname) uri = URI("https://#{resolvable_hostname}") max_attempts = 30 sleep_duration_secs = 5 call_function('out::message', "Checking connectivity from bolt runner to #{uri}") (1..max_attempts).each do |i| attempt = "Attempt #{i} of #{max_attempts}:" begin Net::HTTP.start(uri.host, uri.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) do |https| request = Net::HTTP::Get.new(uri) response = https.request(request) return true if response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection) # if 'healthy' == response.body.downcase # call_function('out::message', "#{attempt} Received healthy response, all services up and running.") # return true # else # call_function('out::message', "#{attempt} Reached #{uri}, but did not receive healthy status response. Waiting another 5 seconds.") # end call_function('out::message', "#{attempt} Error Reaching #{uri}. Got http code #{response.code}. Waiting another 5 seconds and trying again.") end rescue StandardError => e call_function('out::message', "#{attempt} Error Reaching #{uri}. #{e.}. Waiting another 5 seconds and trying again.") end sleep sleep_duration_secs end false end end |