forked from sysdiglabs/sysdig-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_events.py
More file actions
executable file
·73 lines (60 loc) · 1.4 KB
/
Copy pathlist_events.py
File metadata and controls
executable file
·73 lines (60 loc) · 1.4 KB
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
#!/usr/bin/env python
#
# Get user events from Sysdig Cloud
#
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
from sdcclient import SdcClient
def print_events(data):
for event in data['events']:
severity = event['severity'] if event.get('severity') else 'not set'
print 'time: %d, name: %s, description: %s, severity: %s' % (event['timestamp'], event['name'], event['description'], severity)
#
# 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 = SdcClient(sdc_token)
#
# Get the entire list of events
#
res = sdclient.get_events()
if res[0]:
print_events(res[1])
else:
print res[1]
sys.exit(1)
#
# Get the events that match a period in time
#
res = sdclient.get_events(from_ts=1460365211, to_ts=1460465211)
if res[0]:
print_events(res[1])
else:
print res[1]
sys.exit(1)
#
# Get the events that match a name
#
res = sdclient.get_events(name='test event')
if res[0]:
print_events(res[1])
else:
print res[1]
sys.exit(1)
#
# Get the events that match a tag/value pair
#
res = sdclient.get_events(tags="tag1 = 'value1'")
if res[0]:
print_events(res[1])
else:
print res[1]
sys.exit(1)