Skip to content

Commit 331bf91

Browse files
nestorsalcedamstemm
authored andcommitted
Add sampling support for get_policy_events_* methods (#50)
* Add support for sampling parameter when retrieving policy events When sampling parameter is present in context and has a value, use it for building the URL * Add a sampling parameter to get_policy_events_duration method With sampling support I'm able to keep consistency with UI policy event timeline. * Add a sampling parameter to get_policy_events_range method This is the same case that get_policy_events_duration: With sampling I'm able to keep consistency with UI policy event timeline.
1 parent acdedd3 commit 331bf91

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

sdcclient/_client.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,11 @@ def set_user_falco_rules(self, rules_content):
19391939
return self._set_falco_rules("user", rules_content)
19401940

19411941
def _get_policy_events_int(self, ctx):
1942-
res = requests.get(self.url + '/api/policyEvents?from={:d}&to={:d}&offset={}&limit={}'.format(int(ctx['from']), int(ctx['to']), ctx['offset'], ctx['limit']), headers=self.hdrs, verify=self.ssl_verify)
1942+
policy_events_url = self.url + '/api/policyEvents?from={:d}&to={:d}&offset={}&limit={}'.format(int(ctx['from']), int(ctx['to']), ctx['offset'], ctx['limit'])
1943+
if 'sampling' in ctx:
1944+
policy_events_url += '&sampling={:d}'.format(int(ctx['sampling']))
1945+
1946+
res = requests.get(policy_events_url, headers=self.hdrs, verify=self.ssl_verify)
19431947
if not self._checkResponse(res):
19441948
return [False, self.lasterr]
19451949

@@ -1948,14 +1952,15 @@ def _get_policy_events_int(self, ctx):
19481952

19491953
return [True, {"ctx": ctx, "data": res.json()}]
19501954

1951-
def get_policy_events_range(self, from_sec, to_sec):
1955+
def get_policy_events_range(self, from_sec, to_sec, sampling=None):
19521956
'''**Description**
19531957
Fetch all policy events that occurred in the time range [from_sec:to_sec]. This method is used in conjunction
19541958
with :func:`~sdcclient.SdSecureClient.get_more_policy_events` to provide paginated access to policy events.
19551959
19561960
**Arguments**
19571961
- from_sec: the start of the timerange for which to get events
19581962
- end_sec: the end of the timerange for which to get events
1963+
- sampling: sample all policy events using *sampling* interval.
19591964
19601965
**Success Return Value**
19611966
An array containing:
@@ -1972,15 +1977,19 @@ def get_policy_events_range(self, from_sec, to_sec):
19721977
"offset": 0,
19731978
"limit": 1000}
19741979

1980+
if sampling is not None:
1981+
ctx["sampling"] = sampling
1982+
19751983
return self._get_policy_events_int(ctx)
19761984

1977-
def get_policy_events_duration(self, duration_sec):
1985+
def get_policy_events_duration(self, duration_sec, sampling=None):
19781986
'''**Description**
19791987
Fetch all policy events that occurred in the last duration_sec seconds. This method is used in conjunction with
19801988
:func:`~sdcclient.SdSecureClient.get_more_policy_events` to provide paginated access to policy events.
19811989
19821990
**Arguments**
19831991
- duration_sec: Fetch all policy events that have occurred in the last *duration_sec* seconds.
1992+
- sampling: Sample all policy events using *sampling* interval.
19841993
19851994
**Success Return Value**
19861995
An array containing:
@@ -2001,6 +2010,9 @@ def get_policy_events_duration(self, duration_sec):
20012010
"offset": 0,
20022011
"limit": 1000}
20032012

2013+
if sampling is not None:
2014+
ctx["sampling"] = sampling
2015+
20042016
return self._get_policy_events_int(ctx)
20052017

20062018
def get_more_policy_events(self, ctx):

0 commit comments

Comments
 (0)