forked from sysdiglabs/sysdig-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestore_dashboards.py
50 lines (41 loc) · 1.57 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
49
50
#!/usr/bin/env python
#
# Save/restore dashboards
#
import os
import sys
import zipfile
import json
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
from sdcclient import SdcClient
#
# 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 = SdcClient(sdc_token)
zipf = zipfile.ZipFile(dashboard_state_file, 'r')
dashboard_conf_items = ['showAsType', 'filterRoot', 'linkMetrics',
'singleTimeNavigation', 'gridConfiguration', 'responsive',
'nodesNoiseFilter', 'compareWith', 'format', 'linksNoiseFilter',
'filterProcesses', 'isLegendExpanded', 'inhertitTimeNavigation',
'schema', 'sortAscending', 'mapDataLimit', 'metrics', 'filterExtNodes',
'sorting', 'name', 'sourceExploreView', 'items', 'showAs', 'eventsFilter',
'timeMode', 'isShared', 'sourceDrilldownView', 'filterExpression']
for info in zipf.infolist():
data = zipf.read(info.filename)
j = json.loads(data)
k = {}
for item in j.keys():
if item in dashboard_conf_items:
k[item] = j[item]
res = sdclient.create_dashboard_with_configuration(k)
if res[0] == False:
print "Dashboard creation failed for dashboard name %s with error %s" % (j['name'], res[1])