-
Notifications
You must be signed in to change notification settings - Fork 44
/
list_events.py
executable file
·90 lines (72 loc) · 1.55 KB
/
list_events.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
#
# Get user events from Sysdig Cloud
#
import sys
from sdcclient import SdMonitorClient
def print_events(data):
for event in data['events']:
event['sev'] = event.get('severity', 'not set')
event['description'] = event.get('description', 'not set')
print(('id: %(id)s, time: %(timestamp)d, name: %(name)s, description: %(description)s, severity: %(sev)s'
% event))
#
# Parse arguments
#
if len(sys.argv) != 2:
print(('usage: %s <sysdig-token>' % sys.argv[0]))
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
sys.exit(1)
sdc_token = sys.argv[1]
#
# Instantiate the SDC client
#
sdclient = SdMonitorClient(sdc_token)
#
# Get the entire list of events
#
ok, res = sdclient.get_events()
if ok:
print_events(res)
else:
print(res)
sys.exit(1)
#
# Get the events before other event
#
if len(res['events']) > 0:
ok, res = sdclient.get_events(pivot=res['events'][-1]["id"])
else:
ok, res = True, {"events": []}
if ok:
print_events(res)
else:
print(res)
sys.exit(1)
#
# Get the events that match a category
#
ok, res = sdclient.get_events(category=["kubernetes"])
if ok:
print_events(res)
else:
print(res)
sys.exit(1)
#
# Get the events that match a status
#
ok, res = sdclient.get_events(status=['triggered', 'unacknowledged'])
if ok:
print_events(res)
else:
print(res)
sys.exit(1)
#
# Get the last event only
#
ok, res = sdclient.get_events(limit=1)
if ok:
print_events(res)
else:
print(res)
sys.exit(1)