-
Notifications
You must be signed in to change notification settings - Fork 44
/
dashboard_save_load.py
executable file
·52 lines (42 loc) · 1.15 KB
/
dashboard_save_load.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
#!/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
#
# Parse arguments
#
if len(sys.argv) != 2:
print(('usage: %s <sysdig-token>' % sys.argv[0]))
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
sys.exit(1)
sdc_token = sys.argv[1]
#
# Instantiate the SDC client
#
sdclient = SdMonitorClient(sdc_token)
#
# Serialize the first user dashboard to disk
#
ok, res = sdclient.get_dashboards()
if not ok:
print(res)
sys.exit(1)
if len(res['dashboards']) > 0:
sdclient.save_dashboard_to_file(res['dashboards'][0], 'dashboard.json')
else:
print('the user has no dashboards. Exiting.')
sys.exit(0)
#
# Now create the dashboard from the file. We use a filter for the Cassandra process
# as an example.
#
dashboardFilter = 'proc.name = "cassandra"'
ok, res = sdclient.create_dashboard_from_file('test dasboard from file', 'dashboard.json', dashboardFilter)
if ok:
print('Dashboard created successfully')
else:
print(res)
sys.exit(1)