-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdashboard_backup_v1_restore_v2.py
executable file
·60 lines (50 loc) · 1.63 KB
/
dashboard_backup_v1_restore_v2.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
#!/usr/bin/env python
#
# Save the first user dashboard to file and then use create_dashboard_from_file()
# to apply the stored dasboard again with a different filter.
#
import sys
from sdcclient import SdMonitorClient
from sdcclient import SdMonitorClientV1
#
# Parse arguments
#
if len(sys.argv) != 5:
print(f'usage: {sys.argv[0]} <sysdig-v1-url> <sysdig-v1-token> <sysdig-v2-url> <sysdig-v2-token>')
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
sys.exit(1)
sdc_v1_url = sys.argv[1]
sdc_v1_token = sys.argv[2]
sdc_v2_url = sys.argv[3]
sdc_v2_token = sys.argv[4]
#
# Instantiate the SDC client
#
sdclient_v2 = SdMonitorClient(sdc_v2_token, sdc_url=sdc_v2_url)
sdclient_v1 = SdMonitorClientV1(sdc_v1_token, sdc_url=sdc_v1_url)
#
# Serialize the first user dashboard to disk
#
ok, res = sdclient_v1.get_dashboards()
if not ok:
print(res)
sys.exit(1)
for dashboard in res['dashboards']:
file_name = '{}.json'.format(dashboard['id'])
print(('Saving v1 dashboard {} to file {}...'.format(
dashboard['name'], file_name)))
sdclient_v1.save_dashboard_to_file(dashboard, file_name)
print('Importing dashboard to v2...')
ok, res = sdclient_v2.create_dashboard_from_file(
'import of {}'.format(dashboard['name']),
file_name,
None,
shared=dashboard['isShared'],
public=dashboard['isPublic'])
if ok:
print(('Dashboard {} imported!'.format(dashboard['name'])))
sdclient_v2.delete_dashboard(res['dashboard'])
else:
print(('Dashboard {} import failed:'.format(dashboard['name'])))
print(res)
print('\n')