Skip to content

Commit 9674099

Browse files
committed
Merge branch 'master' into teams-api
2 parents 8983ddb + c077e24 commit 9674099

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

examples/dashboard_save_load.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
dashboardFilter = "proc.name = cassandra"
48+
49+
res = sdclient.create_dashboard_from_file('test dasboard from file', 'dashboard.json', dashboardFilter)
50+
51+
if res[0]:
52+
print 'Dashboard created successfully'
53+
else:
54+
print res[1]
55+
sys.exit(1)

sdcclient/_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def create_dashboard_from_dashboard(self, newdashname, templatename, filter):
748748
#
749749
return self.create_dashboard_from_template(newdashname, dboard, filter)
750750

751-
def create_dashboard_from_file(self, newdashname, filename, scope):
751+
def create_dashboard_from_file(self, newdashname, filename, filter):
752752
#
753753
# Load the Dashboard
754754
#
@@ -761,7 +761,7 @@ def create_dashboard_from_file(self, newdashname, filename, scope):
761761
#
762762
# Create the new dashboard
763763
#
764-
self.create_dashboard_from_template(newdashname, dboard, scope)
764+
return self.create_dashboard_from_template(newdashname, dboard, filter)
765765

766766
def delete_dashboard(self, dashboard):
767767
if 'id' not in dashboard:

0 commit comments

Comments
 (0)