Puppet Function: checkmk::registration_server
- Defined in:
- lib/puppet/functions/checkmk/registration_server.rb
- Function type:
- Ruby 4.x API
Overview
Gets the registration port from the CheckMK server and returns the hostname and port for cmk-agent-ctl register
4 5 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 |
# File 'lib/puppet/functions/checkmk/registration_server.rb', line 4 Puppet::Functions.create_function(:'checkmk::registration_server') do dispatch :registration_server do param 'String', :url param 'String', :site_name return_type 'String' end def registration_server(url, site_name) uri = URI("#{url}/#{site_name}/check_mk/api/1.0/domain-types/internal/actions/discover-receiver/invoke") request = Net::HTTP::Get.new(uri) registration_port = '' Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) do |response| case response.code when '200' registration_port = response.body else raise Puppet::Error, "Failed to get registration port: { type: #{response.class}, code: #{response.code} }" end end end "#{uri.hostname}:#{registration_port}" rescue Errno::ECONNREFUSED => e call_function('warning', "Failed to connect, using default value of 8000: #{e}") "#{URI(url).hostname}:8000" end end |