Skip to content

Commit 4b93140

Browse files
committed
added an example to save and load dashboards
1 parent 775426a commit 4b93140

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

examples/dashboard_save_load.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
#
3+
# Save the first user dashboard to file and then use create_dashboard_from_file()
4+
# to apply the stored dasboard again with a different filter.
5+
#
6+
import os
7+
import sys
8+
import json
9+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
10+
from sdcclient import SdcClient
11+
12+
#
13+
# Parse arguments
14+
#
15+
if len(sys.argv) != 2:
16+
print 'usage: %s <sysdig-token>' % sys.argv[0]
17+
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
18+
sys.exit(1)
19+
20+
sdc_token = sys.argv[1]
21+
22+
#
23+
# Instantiate the SDC client
24+
#
25+
sdclient = SdcClient(sdc_token)
26+
27+
#
28+
# Serialize the first user dashboard to disk
29+
#
30+
res = sdclient.get_dashboards()
31+
32+
if not res[0]:
33+
print res[1]
34+
sys.exit(1)
35+
36+
if len(res[1][u'dashboards']) > 0:
37+
with open('dashboard.json', 'w') as outf:
38+
json.dump(res[1][u'dashboards'][0], outf)
39+
else:
40+
print 'the user has no dashboards. Exiting.'
41+
sys.exit(0)
42+
43+
#
44+
# Now create the dashboard from the file. We use a filter for the Cassandra process
45+
# as an example.
46+
#
47+
48+
dashboardFilter = "proc.name = cassandra"
49+
50+
res = sdclient.create_dashboard_from_file('test dasboard from file', 'dashboard.json', dashboardFilter)
51+
52+
if res[0]:
53+
print 'Dashboard created successfully'
54+
else:
55+
print res[1]
56+
sys.exit(1)

sdcclient/_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def create_dashboard_from_dashboard(self, newdashname, templatename, filter):
707707
#
708708
return self.create_dashboard_from_template(newdashname, dboard, filter)
709709

710-
def create_dashboard_from_file(self, newdashname, filename, scope):
710+
def create_dashboard_from_file(self, newdashname, filename, filter):
711711
#
712712
# Load the Dashboard
713713
#
@@ -720,7 +720,7 @@ def create_dashboard_from_file(self, newdashname, filename, scope):
720720
#
721721
# Create the new dashboard
722722
#
723-
self.create_dashboard_from_template(newdashname, dboard, scope)
723+
return self.create_dashboard_from_template(newdashname, dboard, filter)
724724

725725
def delete_dashboard(self, dashboard):
726726
if 'id' not in dashboard:

0 commit comments

Comments
 (0)