9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/prometheus_exporter_hcloud_sd/hetzner_servers.rb', line 9
def self.private_ips
token = ENV.fetch("HCLOUD_READ_TOKEN")
response = Net::HTTP.get(SERVERS_URI, { Authorization: "Bearer #{token}" })
json_response = JSON.parse(response, symbolize_names: true)
json_response.fetch(:servers, []).map do |server|
server.fetch(:private_net, [{}]).first.fetch(:ip, nil)
end.compact
rescue KeyError
raise Thor::Error, "Cannot continue.\nPlease set the HCLOUD_READ_TOKEN environment variable."
end
|