-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdelete_event.py
executable file
·62 lines (46 loc) · 1.07 KB
/
delete_event.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
60
61
62
#!/usr/bin/env python
#
# Delete user events from Sysdig Cloud
#
import getopt
import sys
from sdcclient import SdMonitorClient
#
# Parse arguments
#
def usage():
print(('usage: %s [-e|--event <name>] <sysdig-token>' % sys.argv[0]))
print('-e|--event: Name of event to delete')
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
sys.exit(1)
try:
opts, args = getopt.getopt(sys.argv[1:], "e:", ["event="])
except getopt.GetoptError:
usage()
event_name = "test_event_name"
for opt, arg in opts:
if opt in ("-e", "--event"):
event_name = arg
if len(args) != 1:
usage()
sdc_token = args[0]
#
# Instantiate the SDC client
#
sdclient = SdMonitorClient(sdc_token)
#
# Get the events that match a name
#
ok, res = sdclient.get_events(name=event_name)
if not ok:
print(res)
sys.exit(1)
#
# Delete the first event among the returned ones
#
for event in res['events']:
print(("Deleting event " + event['name']))
ok, res = sdclient.delete_event(event)
if not ok:
print(res)
sys.exit(1)