forked from sysdiglabs/sysdig-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_sysdig_capture.py
executable file
·62 lines (52 loc) · 1.45 KB
/
create_sysdig_capture.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
#
# Creates a sysdig capture, waits for termination and prints the download URL.
#
import os
import sys
import time
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
from sdcclient import SdcClient
#
# Parse arguments
#
if len(sys.argv) not in (5, 6):
print 'usage: %s <sysdig-token> hostname capture_name duration [filter]' % sys.argv[0]
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
sys.exit(1)
sdc_token = sys.argv[1]
hostname = sys.argv[2]
capture_name = sys.argv[3]
duration = sys.argv[4]
capture_filter = ''
if len(sys.argv) == 6:
capture_filter = sys.argv[5]
#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token)
res = sdclient.create_sysdig_capture(hostname, capture_name, int(duration), capture_filter)
#
# Show the list of metrics
#
if res[0]:
capture = res[1]['dump']
else:
print res[1]
sys.exit(1)
while True:
res = sdclient.poll_sysdig_capture(capture)
if res[0]:
capture = res[1]['dump']
else:
print res[1]
sys.exit(1)
print 'Capture is in state ' + capture['status']
if capture['status'] in ('requested', 'capturing', 'uploading'):
pass
elif capture['status'] in ('error', 'uploadingError'):
sys.exit(1)
elif capture['status'] in ('done', 'uploaded'):
print 'Download at: ' + sdclient.url + capture['downloadURL']
sys.exit(0)
time.sleep(1)