3
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
|
# File 'lib/nrde/dashboard_exporter.rb', line 3
def self.exporter(guid, personal_api_key = nil, width = '2000', height = '2000', new_relic_region = 'US')
begin
raise "A New Relic API key is required." if personal_api_key.nil?
= {}
["Content-Type"] = "application/json"
["API-Key"] = personal_api_key
endpointUrl = new_relic_region == 'EU' ? 'https://api.eu.newrelic.com/graphql' : 'https://api.newrelic.com/graphql'
raise "Dashboard GUID required." if guid.nil?
nr_query_json = {"query" => "mutation { dashboardCreateSnapshotUrl(guid: \"#{guid}\")}"}
uri = URI.parse(endpointUrl)
https = Net::HTTP.new(uri.host,uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.path, )
req.body = nr_query_json.to_json
res = https.request(req)
nr_snapshopt_url = JSON.parse(res.body)['data']['dashboardCreateSnapshotUrl']
nr_download_uri = URI("#{nr_snapshopt_url}&width=#{width}&height=#{height}")
response = Net::HTTP.get_response(nr_download_uri)
return response
rescue => e
p "PDF Download failed #{nr_download_uri} #{response.code}"
end
end
|