-
Notifications
You must be signed in to change notification settings - Fork 130
/
migrate_all_dashboards.py
52 lines (41 loc) · 1.45 KB
/
migrate_all_dashboards.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
from datadog import initialize, api
options = {
'api_key': '<API KEY ORIGINAL ACCOUNT>',
'app_key': '<APP KEY ORIGINAL ACCOUNT>'
}
initialize(**options)
dashboard_ids = []
dashboard_data = []
## Gather all the dashboard IDs in original account
response = api.Dashboard.get_all()
dashboards = response["dashboards"]
for dashboard in dashboards:
id = dashboard['id']
dashboard_ids.append(id)
print (dashboard_ids)
## Gather dashboard data via dashboard IDs
for dashboard_id in dashboard_ids:
dashboard = api.Dashboard.get(dashboard_id)
dashboard_data.append(dashboard)
options = {
'api_key': '<API KEY NEW ACCOUNT>',
'app_key': '<APP KEY NEW ACCOUNT>'
}
initialize(**options)
## Iterate through dashboard data and create a new dashboard in new account
for dashboard in dashboard_data:
id = dashboard['id']
print('-------------------------------------------------------------------')
print(f'Creating new dashboard with id:{id}')
print('-------------------------------------------------------------------')
new = api.Dashboard.create(
title=dashboard['title'],
author_name=dashboard['author_name'],
widgets=dashboard['widgets'],
layout_type=dashboard['layout_type'],
description=dashboard['description'],
is_read_only=dashboard['is_read_only'],
notify_list=dashboard['notify_list'],
template_variables=dashboard['template_variables'],
)
print('Done importing all dashboards!')