Skip to content

Commit 53aebf0

Browse files
tweaks
1 parent 8dcea4e commit 53aebf0

File tree

6 files changed

+83
-22
lines changed

6 files changed

+83
-22
lines changed

README.md

+62-11
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,20 @@ Usage
2828

2929
_Note:_ in order to use this API you must obtain a Sysdig Cloud token. You can get your user's token in the _Sysdig Cloud API_ section of the [settings](https://app.sysdigcloud.com/#/settings/user) page.
3030

31-
The library exports a single class, `SdcClient`, that is used to connect to Sysdig Cloud and execute actions.
31+
The library exports a single class, `SdcClient`, that is used to connect to Sysdig Cloud and execute actions. It can be instantiated like this:
32+
33+
``` python
34+
from sdcclient import SdcClient
35+
36+
sdc_token = "MY_API_TOKEN"
37+
38+
#
39+
# Instantiate the SDC client
40+
#
41+
sdclient = SdcClient(sdc_token)
42+
```
43+
44+
Once instantiated, all the methods documented below can be called on the object.
3245

3346
####Return Values
3447
Every method in the SdcClient class returns **a list with two entries**. The first one is a boolean value indicating if the call was successful. The second entry depends on the result:
@@ -97,6 +110,21 @@ A dictionary showing the details of the new dashboard.
97110
**Example**
98111
[examples/create_dashboard.py](examples/create_dashboard.py).
99112

113+
#### `create_sysdig_capture(self, hostname, capture_name, duration, capture_filter='', folder='/')`
114+
**Description**
115+
Create a new sysdig capture. The capture will be immediately started.
116+
**Arguments**
117+
- **hostname**: the hostname of the instrumented host where the capture will be taken.
118+
- **capture_name**: the name of the capture.
119+
- **duration**: the duration of the capture, in seconds.
120+
- **capture_filter**: a sysdig filter expression.
121+
- **folder**: directory in the S3 bucket where the capture will be saved.
122+
123+
**Success Return Value**
124+
A dictionary showing the details of the new capture.
125+
**Example**
126+
[examples/create_sysdig_capture.py](examples/create_sysdig_capture.py).
127+
100128
#### `delete_alert(self, alert)`
101129
**Description**
102130
Deletes an alert.
@@ -200,13 +228,17 @@ A dictionary containing the list of available metrics.
200228
**Example**
201229
[examples/list_metrics.py](examples/list_metrics.py).
202230

231+
#### `get_connected_agents(self)`
232+
**Description**
233+
Return the agents currently connected to Sysdig Cloud for the current user.
234+
**Success Return Value**
235+
A list of the agents with all their attributes.
236+
203237
#### `get_n_connected_agents(self)`
204238
**Description**
205239
Return the number of agents currently connected to Sysdig Cloud for the current user.
206240
**Success Return Value**
207241
An integer number.
208-
**Example**
209-
[examples/print_user_info.py](examples/print_user_info.py).
210242

211243
#### `get_notifications(self, from_ts, to_ts, state=None, resolved=None)`
212244
**Description**
@@ -222,17 +254,13 @@ A dictionary containing the list of notifications.
222254
**Example**
223255
[examples/list_alert_notifications.py](examples/list_alert_notifications.py).
224256

225-
#### `update_notification_resolution(self, notification, resolved)`
257+
#### `get_sysdig_captures(self)`
226258
**Description**
227-
Updates the resolution status of an alert notification.
228-
**Arguments**
229-
- **notification**: notification object as returned by `get_notifications()`.
230-
- **resolved**: new resolution status. Supported values are `True` and `False.
231-
259+
Returns the list of sysdig captures for the user.
232260
**Success Return Value**
233-
The updated notification.
261+
A dictionary containing the list of captures.
234262
**Example**
235-
[examples/resolve_alert_notifications.py](examples/resolve_alert_notifications.py).
263+
[examples/list_sysdig_captures.py](examples/list_sysdig_captures.py).
236264

237265
#### `get_user_info(self)`
238266
**Description**
@@ -242,6 +270,17 @@ A dictionary containing information about the user, for example its email and th
242270
**Example**
243271
[examples/print_user_info.py](examples/print_user_info.py).
244272

273+
#### `poll_sysdig_capture(self, capture)`
274+
**Description**
275+
Fetch the updates state of a sysdig capture. Can be used to poll the status of a capture that has been previously created and started with `create_sysdig_capture`.
276+
**Arguments**
277+
- **capture**: the capture object as returned by `get_sysdig_captures()` or `create_sysdig_capture()`.
278+
279+
**Success Return Value**
280+
A dictionary showing the updated details of the capture. Use the `status` field to check the progress of a capture.
281+
**Example**
282+
[examples/create_sysdig_capture.py](examples/create_sysdig_capture.py).
283+
245284
#### `post_event(self, name, description=None, severity=6, host=None, tags=None)`
246285
**Description**
247286
You can use this method you use to send an event to Sysdig Cloud. The events you post are available in the Events tab in the Sysdig Cloud UI and can be overlied to charts.
@@ -256,3 +295,15 @@ You can use this method you use to send an event to Sysdig Cloud. The events you
256295
A dictionary describing the new event.
257296
**Example**
258297
[examples/post_event.py](examples/post_event.py).
298+
299+
#### `update_notification_resolution(self, notification, resolved)`
300+
**Description**
301+
Updates the resolution status of an alert notification.
302+
**Arguments**
303+
- **notification**: notification object as returned by `get_notifications()`.
304+
- **resolved**: new resolution status. Supported values are `True` and `False.
305+
306+
**Success Return Value**
307+
The updated notification.
308+
**Example**
309+
[examples/resolve_alert_notifications.py](examples/resolve_alert_notifications.py).

examples/create_sysdig_capture.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@
3737
# Show the list of metrics
3838
#
3939
if res[0]:
40-
capture = res[1]
40+
capture = res[1]['dump']
4141
else:
4242
print res[1]
4343
sys.exit(1)
4444

4545
while True:
4646
res = sdclient.poll_sysdig_capture(capture)
4747
if res[0]:
48-
capture = res[1]
48+
capture = res[1]['dump']
4949
else:
5050
print res[1]
5151
sys.exit(1)

examples/list_alert_notifications.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
1010
from sdcclient import SdcClient
1111

12+
def print_notifications(notifications):
13+
for notification in notifications:
14+
values = []
15+
for entity in notification['entities']:
16+
for value in entity['metricValues']:
17+
values.append(str(value['value']))
18+
19+
print "#%s, State: %s, Severity: %s, Scope: %s, Condition: %s, Value: %s, Resolved: %s" % \
20+
(notification['id'], notification['state'], notification['severity'], notification['filter'], notification['condition'], ','.join(values), notification['resolved'])
21+
1222
#
1323
# Parse arguments
1424
#
@@ -29,7 +39,7 @@
2939
#
3040
res = sdclient.get_notifications(from_ts=int(time.time()-86400), to_ts=int(time.time()))
3141

32-
print res[1]
42+
print_notifications(res[1]['notifications'])
3343
if not res[0]:
3444
sys.exit(1)
3545

@@ -38,7 +48,7 @@
3848
#
3949
res = sdclient.get_notifications(from_ts=int(time.time()-86400), to_ts=int(time.time()), state='ACTIVE')
4050

41-
print res[1]
51+
print_notifications(res[1]['notifications'])
4252
if not res[0]:
4353
sys.exit(1)
4454

@@ -47,7 +57,7 @@
4757
#
4858
res = sdclient.get_notifications(from_ts=int(time.time()-86400), to_ts=int(time.time()), state='OK')
4959

50-
print res[1]
60+
print_notifications(res[1]['notifications'])
5161
if not res[0]:
5262
sys.exit(1)
5363

@@ -56,6 +66,6 @@
5666
#
5767
res = sdclient.get_notifications(from_ts=int(time.time()-86400), to_ts=int(time.time()), resolved=True)
5868

59-
print res[1]
69+
print_notifications(res[1]['notifications'])
6070
if not res[0]:
6171
sys.exit(1)

examples/resolve_alert_notifications.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#
2929
# Get the unresolved notifications in the last day
3030
#
31-
res = sdclient.get_notifications(from_ts=int(time.time() - num_days_to_resolve * 86400),
31+
res = sdclient.get_notifications(from_ts=int(time.time() - int(num_days_to_resolve) * 86400),
3232
to_ts=int(time.time()), resolved=False)
3333

3434
if not res[0]:

sdcclient/_client.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ def get_sysdig_captures(self):
601601
r = requests.get(self.url + '/api/sysdig', headers=self.hdrs)
602602
if not self.__checkResponse(r):
603603
return [False, self.lasterr]
604-
return [True, r.json()['dumps']]
604+
return [True, r.json()]
605605

606606
def poll_sysdig_capture(self, capture):
607607
if 'id' not in capture:
@@ -610,7 +610,7 @@ def poll_sysdig_capture(self, capture):
610610
r = requests.get(self.url + '/api/sysdig/' + str(capture['id']), headers=self.hdrs)
611611
if not self.__checkResponse(r):
612612
return [False, self.lasterr]
613-
return [True, r.json()['dump']]
613+
return [True, r.json()]
614614

615615
def create_sysdig_capture(self, hostname, capture_name, duration, capture_filter='', folder='/'):
616616
res = self.get_connected_agents()
@@ -639,4 +639,4 @@ def create_sysdig_capture(self, hostname, capture_name, duration, capture_filter
639639
r = requests.post(self.url + '/api/sysdig', headers=self.hdrs, data=json.dumps(data))
640640
if not self.__checkResponse(r):
641641
return [False, self.lasterr]
642-
return [True, r.json()['dump']]
642+
return [True, r.json()]

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup
22

33
setup(name='sdcclient',
4-
version='0.1.0',
4+
version='0.2.0',
55
description='Python client for Sysdig Cloud',
66
url='http://github.com/draios/python-sdc-client',
77
author='sysdig Inc.',

0 commit comments

Comments
 (0)