-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdelete_dashboard.py
executable file
·59 lines (47 loc) · 1.14 KB
/
delete_dashboard.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
53
54
55
56
57
58
59
#!/usr/bin/env python
#
# This example shows how to delete a dashboard
#
import getopt
import sys
from sdcclient import SdMonitorClient
#
# Parse arguments
#
def usage():
print(('usage: %s [-p|--pattern <name>] <sysdig-token>' % sys.argv[0]))
print('-p|--pattern: Delete all dashboards containing the provided pattern')
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
sys.exit(1)
try:
opts, args = getopt.getopt(sys.argv[1:], "p:", ["pattern="])
except getopt.GetoptError:
usage()
pattern = "API Test"
for opt, arg in opts:
if opt in ("-p", "--pattern"):
pattern = arg
if len(args) != 1:
usage()
sdc_token = args[0]
#
# Instantiate the SDC client
#
sdclient = SdMonitorClient(sdc_token)
#
# List the dashboards
#
ok, res = sdclient.get_dashboards()
if not ok:
print(res)
sys.exit(1)
#
# Delete all the dashboards containing pattern
#
for dashboard in res['dashboards']:
if pattern in dashboard['name']:
print(("Deleting " + dashboard['name']))
ok, res = sdclient.delete_dashboard(dashboard)
if not ok:
print(res)
sys.exit(1)