@@ -42,12 +42,27 @@ def __checkResponse(self, res):
4242
4343
4444 def get_user_info (self ):
45+ '''**Description**
46+ Get details about the current user.
47+
48+ **Success Return Value**
49+ A dictionary containing information about the user, for example its email and the maximum number of agents it can install.
50+
51+ **Example**
52+ `examples/print_user_info.py <https://github.com/draios/python-sdc-client/blob/master/examples/print_user_info.py>`_
53+ '''
4554 res = requests .get (self .url + '/api/user/me' , headers = self .hdrs )
4655 if not self .__checkResponse (res ):
4756 return [False , self .lasterr ]
4857 return [True , res .json ()]
4958
5059 def get_user_token (self ):
60+ '''**Description**
61+ Return the API token of the current user.
62+
63+ **Success Return Value**
64+ A string containing the user token.
65+ '''
5166 res = requests .get (self .url + '/api/token' , headers = self .hdrs )
5267 if not self .__checkResponse (res ):
5368 return [False , self .lasterr ]
@@ -69,6 +84,12 @@ def get_connected_agents(self):
6984 return [True , data ['agents' ]]
7085
7186 def get_n_connected_agents (self ):
87+ '''**Description**
88+ Return the number of agents currently connected to Sysdig Cloud for the current user.
89+
90+ **Success Return Value**
91+ An integer number.
92+ '''
7293 res = requests .get (self .url + '/api/agents/connected' , headers = self .hdrs )
7394 if not self .__checkResponse (res ):
7495 return [False , self .lasterr ]
@@ -80,7 +101,7 @@ def get_alerts(self):
80101 Retrieve the list of alerts configured by the user.
81102
82103 **Success Return Value**
83- An array of alert JSON objects , with the format described at `this link <https://app.sysdigcloud.com/apidocs/#!/Alerts/get_api_alerts>`__
104+ An array of alert dictionaries , with the format described at `this link <https://app.sysdigcloud.com/apidocs/#!/Alerts/get_api_alerts>`__
84105
85106 **Example**
86107 `examples/list_alerts.py <https://github.com/draios/python-sdc-client/blob/master/examples/list_alerts.py>`_
@@ -91,6 +112,21 @@ def get_alerts(self):
91112 return [True , res .json ()]
92113
93114 def get_notifications (self , from_ts , to_ts , state = None , resolved = None ):
115+ '''**Description**
116+ Returns the list of Sysdig Cloud alert notifications.
117+
118+ **Arguments**
119+ - **from_ts**: filter events by start time. Timestamp format is in UTC (seconds).
120+ - **to_ts**: filter events by start time. Timestamp format is in UTC (seconds).
121+ - **state**: filter events by alert state. Supported values are ``OK`` and ``ACTIVE``.
122+ - **resolved**: filter events by resolution status. Supported values are ``True`` and ``False``.
123+
124+ **Success Return Value**
125+ A dictionary containing the list of notifications.
126+
127+ **Example**
128+ `examples/list_alert_notifications.py <https://github.com/draios/python-sdc-client/blob/master/examples/list_alert_notifications.py>`_
129+ '''
94130 params = {}
95131
96132 if from_ts is not None :
@@ -111,6 +147,19 @@ def get_notifications(self, from_ts, to_ts, state=None, resolved=None):
111147 return [True , res .json ()]
112148
113149 def update_notification_resolution (self , notification , resolved ):
150+ '''**Description**
151+ Updates the resolution status of an alert notification.
152+
153+ **Arguments**
154+ - **notification**: notification object as returned by :func:`~sdcclient._client.SdcClient.get_notifications`.
155+ - **resolved**: new resolution status. Supported values are ``True`` and ``False``.
156+
157+ **Success Return Value**
158+ The updated notification.
159+
160+ **Example**
161+ `examples/resolve_alert_notifications.py <https://github.com/draios/python-sdc-client/blob/master/examples/resolve_alert_notifications.py>`_
162+ '''
114163 if 'id' not in notification :
115164 return [False , 'Invalid notification format' ]
116165
@@ -243,7 +292,7 @@ def delete_alert(self, alert):
243292 Deletes an alert.
244293
245294 **Arguments**
246- - **alert**: the alert object as returned by :func:`~sdcclient._client.SdcClient.get_alerts`.
295+ - **alert**: the alert dictionary as returned by :func:`~sdcclient._client.SdcClient.get_alerts`.
247296
248297 **Success Return Value**
249298 ``None``.
@@ -305,6 +354,15 @@ def delete_notification_channel(self, channel):
305354 return [True , None ]
306355
307356 def get_explore_grouping_hierarchy (self ):
357+ '''**Description**
358+ Return the user's current grouping hierarchy as visible in the Explore tab of Sysdig Cloud.
359+
360+ **Success Return Value**
361+ A list containing the list of the user's Explore grouping criteria.
362+
363+ **Example**
364+ `examples/print_explore_grouping.py <https://github.com/draios/python-sdc-client/blob/master/examples/print_explore_grouping.py>`_
365+ '''
308366 res = requests .get (self .url + '/api/groupConfigurations' , headers = self .hdrs )
309367 if not self .__checkResponse (res ):
310368 return [False , self .lasterr ]
@@ -329,6 +387,12 @@ def get_explore_grouping_hierarchy(self):
329387 return [False , 'corrupted groupConfigurations API response, missing "explore" entry' ]
330388
331389 def set_explore_grouping_hierarchy (self , new_hierarchy ):
390+ '''**Description**
391+ Changes the grouping hierarchy in the Explore panel of the current user.
392+
393+ **Arguments**
394+ - **new_hierarchy**: a list of sysdig segmentation metrics indicating the new grouping hierarchy.
395+ '''
332396 body = {
333397 'id' : 'explore' ,
334398 'groups' : [{'groupBy' :[]}]
@@ -345,6 +409,15 @@ def set_explore_grouping_hierarchy(self, new_hierarchy):
345409 return [True , None ]
346410
347411 def get_data_retention_info (self ):
412+ '''**Description**
413+ Return the list of data retention intervals, with beginning and end UTC time for each of them. Sysdig Cloud performs rollups of the data it stores. This means that data is stored at different time granularities depending on how far back in time it is. This call can be used to know what precision you can expect before you make a call to :func:`~sdcclient._client.SdcClient.get_data`.
414+
415+ **Success Return Value**
416+ A dictionary containing the list of available sampling intervals.
417+
418+ **Example**
419+ `examples/print_data_retention_info.py <https://github.com/draios/python-sdc-client/blob/master/examples/print_data_retention_info.py>`_
420+ '''
348421 res = requests .get (self .url + '/api/history/timelines/' , headers = self .hdrs )
349422 if not self .__checkResponse (res ):
350423 return [False , self .lasterr ]
@@ -700,6 +773,18 @@ def add_dashboard_panel(self, dashboard, name, panel_type, metrics, scope=None,
700773 return [True , res .json ()]
701774
702775 def remove_dashboard_panel (self , dashboard , panel_name ):
776+ '''**Description**
777+ Removes a panel from the dashboard. The panel to remove is identified by the specified ``name``.
778+
779+ **Arguments**
780+ - **name**: name of the panel to find and remove
781+
782+ **Success Return Value**
783+ A dictionary showing the details of the edited dashboard.
784+
785+ **Example**
786+ `examples/dashboard.py <https://github.com/draios/python-sdc-client/blob/master/examples/dashboard.py>`_
787+ '''
703788 #
704789 # Clone existing dashboard...
705790 #
@@ -965,6 +1050,23 @@ def delete_dashboard(self, dashboard):
9651050 return [True , None ]
9661051
9671052 def post_event (self , name , description = None , severity = None , event_filter = None , tags = None ):
1053+ '''**Description**
1054+ 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.
1055+
1056+ **Arguments**
1057+ - **name**: the name of the new event.
1058+ - **description**: a longer description offering detailed information about the event.
1059+ - **severity**: syslog style from 0 (high) to 7 (low).
1060+ - **event_filter**: metadata, in Sysdig Cloud format, of nodes to associate with the event, e.g. ``host.hostName = 'ip-10-1-1-1' and container.name = 'foo'``.
1061+ - **tags**: a list of key-value dictionaries that can be used to tag the event. Can be used for filtering/segmenting purposes in Sysdig Cloud.
1062+
1063+ **Success Return Value**
1064+ A dictionary describing the new event.
1065+
1066+ **Examples**
1067+ - `examples/post_event_simple.py <https://github.com/draios/python-sdc-client/blob/master/examples/post_event_simple.py>`_
1068+ - `examples/post_event.py <https://github.com/draios/python-sdc-client/blob/master/examples/post_event.py>`_
1069+ '''
9681070 edata = {
9691071 'event' : {
9701072 'name' : name
@@ -989,6 +1091,21 @@ def post_event(self, name, description=None, severity=None, event_filter=None, t
9891091 return [True , res .json ()]
9901092
9911093 def get_events (self , name = None , from_ts = None , to_ts = None , tags = None ):
1094+ '''**Description**
1095+ Returns the list of Sysdig Cloud events.
1096+
1097+ **Arguments**
1098+ - **name**: filter events by name.
1099+ - **from_ts**: filter events by start time. Timestamp format is in UTC (seconds).
1100+ - **to_ts**: filter events by end time. Timestamp format is in UTC (seconds).
1101+ - **tags**: filter events by tags. Can be, for example ``tag1 = 'value1'``.
1102+
1103+ **Success Return Value**
1104+ A dictionary containing the list of events.
1105+
1106+ **Example**
1107+ `examples/list_events.py <https://github.com/draios/python-sdc-client/blob/master/examples/list_events.py>`_
1108+ '''
9921109 params = {}
9931110
9941111 if name is not None :
@@ -1080,18 +1197,48 @@ def get_data(self, metrics, start_ts, end_ts=0, sampling_s=0,
10801197 return [True , res .json ()]
10811198
10821199 def get_metrics (self ):
1200+ '''**Description**
1201+ Return the metric list that can be used for data requests/alerts/dashboards.
1202+
1203+ **Success Return Value**
1204+ A dictionary containing the list of available metrics.
1205+
1206+ **Example**
1207+ `examples/list_metrics.py <https://github.com/draios/python-sdc-client/blob/master/examples/list_metrics.py>`_
1208+ '''
10831209 res = requests .get (self .url + '/api/data/metrics' , headers = self .hdrs )
10841210 if not self .__checkResponse (res ):
10851211 return [False , self .lasterr ]
10861212 return [True , res .json ()]
10871213
10881214 def get_sysdig_captures (self ):
1215+ '''**Description**
1216+ Returns the list of sysdig captures for the user.
1217+
1218+ **Success Return Value**
1219+ A dictionary containing the list of captures.
1220+
1221+ **Example**
1222+ `examples/list_sysdig_captures.py <https://github.com/draios/python-sdc-client/blob/master/examples/list_sysdig_captures.py>`_
1223+ '''
10891224 res = requests .get (self .url + '/api/sysdig' , headers = self .hdrs )
10901225 if not self .__checkResponse (res ):
10911226 return [False , self .lasterr ]
10921227 return [True , res .json ()]
10931228
10941229 def poll_sysdig_capture (self , capture ):
1230+ '''**Description**
1231+ Fetch the updated state of a sysdig capture. Can be used to poll the status of a capture that has been previously created and started with :func:`~sdcclient._client.SdcClient.create_sysdig_capture`.
1232+
1233+ **Arguments**
1234+ - **capture**: the capture object as returned by :func:`~sdcclient._client.SdcClient.get_sysdig_captures` or :func:`~sdcclient._client.SdcClient.create_sysdig_capture`.
1235+
1236+ **Success Return Value**
1237+ A dictionary showing the updated details of the capture. Use the ``status`` field to check the progress of a capture.
1238+
1239+ **Example**
1240+ `examples/create_sysdig_capture.py <https://github.com/draios/python-sdc-client/blob/master/examples/create_sysdig_capture.py>`_
1241+ '''
10951242 if 'id' not in capture :
10961243 return [False , 'Invalid capture format' ]
10971244
@@ -1238,13 +1385,34 @@ def edit_user(self, user_email, firstName=None, lastName=None, roles=None, teams
12381385 return [True , 'Successfully edited user' ]
12391386
12401387 def get_teams (self , team_filter = '' ):
1388+ '''**Description**
1389+ Return the set of teams that match the filter specified. The *team_filter* should be a substring of the names of the teams to be returned.
1390+
1391+ **Arguments**
1392+ - **team_filter**: the team filter to match when returning the list of teams
1393+
1394+ **Success Return Value**
1395+ The teams that match the filter.
1396+ '''
12411397 res = requests .get (self .url + '/api/teams' , headers = self .hdrs )
12421398 if not self .__checkResponse (res ):
12431399 return [False , self .lasterr ]
12441400 ret = filter (lambda t : team_filter in t ['name' ],res .json ()['teams' ])
12451401 return [True , ret ]
12461402
12471403 def get_team (self , name ):
1404+ '''**Description**
1405+ Return the team with the specified team name, if it is present.
1406+
1407+ **Arguments**
1408+ - **name**: the name of the team to return
1409+
1410+ **Success Return Value**
1411+ The requested team.
1412+
1413+ **Example**
1414+ `examples/user_team_mgmt.py <https://github.com/draios/python-sdc-client/blob/master/examples/user_team_mgmt.py>`_
1415+ '''
12481416 res = self .get_teams (name )
12491417 if res [0 ] == False :
12501418 return res
@@ -1399,6 +1567,12 @@ def delete_team(self, name):
13991567 return [True , None ]
14001568
14011569 def switch_user_team (self , new_team_id ):
1570+ '''**Description**
1571+ Switches the current user context to the specified team. In other words, this function makes it possible to start operating in the context of a different team without having to use the token of that team.
1572+
1573+ **Arguments**
1574+ - **new_team_id**: the numeric ID of the team (such as returned by :func:`~sdcclient._client.SdcClient.get_team_ids`) to switch to.
1575+ '''
14021576 res = self .get_user_info ()
14031577 if not res [0 ]:
14041578 return res
0 commit comments