-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathrestore_dashboards.py
executable file
·48 lines (39 loc) · 1.06 KB
/
restore_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
#!/usr/bin/env python
#
# Save/restore dashboards
#
import json
import sys
import zipfile
from sdcclient import SdMonitorClient
#
# Parse arguments
#
if len(sys.argv) != 3:
print(('usage: %s <sysdig-token> <file-name>' % sys.argv[0]))
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
sys.exit(1)
sdc_token = sys.argv[1]
dashboard_state_file = sys.argv[2]
#
# Instantiate the SDC client
#
sdclient = SdMonitorClient(sdc_token)
zipf = zipfile.ZipFile(dashboard_state_file, 'r')
for info in zipf.infolist():
data = zipf.read(info.filename)
try:
j = json.loads(data)
except ValueError:
print(('Invalid JSON file found in ZIP file ' + info.filename + ': skipping'))
continue
#
# Handle old files
#
if 'dashboard' in j:
j = j['dashboard']
ok, res = sdclient.create_dashboard_with_configuration(j)
if ok:
print(('Restored Dashboard named: ' + j['name']))
else:
print(("Dashboard creation failed for dashboard name %s with error %s" % (j['name'], res)))