-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportAllDashboards.py
78 lines (65 loc) · 1.73 KB
/
ExportAllDashboards.py
1
2
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import requests
import json
import yaml
import os
apiKey= input("Enter API Key:")
query="""
{
actor {
entitySearch(queryBuilder: {type: DASHBOARD}) {
results {
entities {
... on DashboardEntityOutline {
guid
name
}
}
}
}
}
}
"""
query1="""
{
actor {
entity(guid: "%s") {
... on DashboardEntity {
pages {
name
widgets {
visualization { id }
title
layout { row width height column }
rawConfiguration
}
}
}
}
}
}
"""
url = "https://api.newrelic.com/graphql"
headers = {"content-type": "application/yaml", "Accept-Charset": "UTF-8","Api-Key": "%s" %apiKey}
headers1 = {"content-type": "application/json", "Accept-Charset": "UTF-8","Api-Key": "%s" %apiKey}
r = requests.get(url, data=query, headers=headers)
listOfAllDashboard = r.text
path = os.getcwd()+'\\new-relic-repo\\dashboards'
os.chdir(path)
with open('listOfAllDashboard.yaml','w') as yaml_file:
list1 = yaml.load(listOfAllDashboard, Loader=yaml.FullLoader)
result= (list1["data"]["actor"]["entitySearch"]["results"]["entities"])
array_length=len(result)
yaml_file.close()
os.remove("listOfAllDashboard.yaml")
for i in range(array_length):
guidList=(result[i]["guid"])
nameList=(result[i]["name"])
print(guidList)
print(nameList)
if not ' / ' in nameList:
r1 = requests.get(url, data=query1 %guidList, headers=headers1)
dashaboardData = r1.json()
result1= (dashaboardData["data"]["actor"]["entity"]["pages"][0])
with open('%s.json' %nameList, 'w') as f:
json.dump(result1,f,indent=2)
f.close()