Skip to content

Commit d2dda58

Browse files
delete_dashboard + example + doc
1 parent 1cc670d commit d2dda58

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ A dictionary containing the list of available sampling intervals.
150150
**Example**
151151
[examples/list_dashboards.py](examples/list_dashboards.py).
152152

153+
#### `delete_dashboards(self, dashname))`
154+
**Description**
155+
Deletes a dashboard given its name.
156+
**Success Return Value**
157+
A boolean with the status of the operation
158+
**Example**
159+
[examples/delete_dashboard.py](examples/delete_dashboard.py).
160+
153161
#### `get_explore_grouping_hierarchy(self)`
154162
**Description**
155163
Return the user's current Explore gourping hierarchy.

examples/delete_dashboard.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
#
3+
# This example shows how to delete a dashboard
4+
#
5+
6+
import sys
7+
sys.path.insert(0, '../')
8+
from sdcclient import SdcClient
9+
10+
#
11+
# Parse arguments
12+
#
13+
if len(sys.argv) != 2:
14+
print 'usage: %s <sysdig-token>' % sys.argv[0]
15+
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
16+
sys.exit(0)
17+
18+
sdc_token = sys.argv[1]
19+
20+
#
21+
# Instantiate the SDC client
22+
#
23+
sdclient = SdcClient(sdc_token)
24+
25+
res = sdclient.delete_dashboard("API test - cassandra in prod")
26+
if res:
27+
print 'Dashboard deleted successfully'
28+
else:
29+
print res[1]
30+
sys.exit(0)
31+
32+
res = sdclient.delete_dashboard("API test - cassandra in dev")
33+
if res:
34+
print 'Dashboard deleted successfully'
35+
else:
36+
print res[1]
37+
sys.exit(0)

sdcclient/_client.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ def create_dashboard_from_dashboard(self, newdashname, templatename, filter):
426426
break
427427

428428
if dboard is None:
429-
print 'can\'t find dashboard ' + templatename + ' to use as a template'
430-
sys.exit(0)
429+
self.lasterr = 'can\'t find dashboard ' + templatename + ' to use as a template'
430+
return [False, self.lasterr]
431431

432432
#
433433
# Create the dashboard
@@ -449,6 +449,22 @@ def create_dashboard_from_file(self, newdashname, filename, scope):
449449
#
450450
self.create_dashboard_from_template(newdashname, dboard, scope)
451451

452+
def delete_dashboard(self, dashname):
453+
r = requests.get(self.url + '/ui/dashboards', headers=self.hdrs)
454+
if not self.__checkResponse(r):
455+
return [False, self.lasterr]
456+
457+
j = r.json()
458+
459+
460+
for db in j['dashboards']:
461+
if db['name'] == dashname:
462+
r = requests.delete(self.url + '/ui/dashboards/' + str(db['id']), headers=self.hdrs)
463+
if not self.__checkResponse(r):
464+
return [False, self.lasterr]
465+
466+
return True
467+
452468
'''
453469
Annotations format:
454470

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup
22

33
setup(name='sdcclient',
4-
version='0.3',
4+
version='0.1.0',
55
description='Python client for Sysdig Cloud',
66
url='http://github.com/draios/python-sdc-client',
77
author='sysdig Inc.',

0 commit comments

Comments
 (0)