Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions sdcclient/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,11 @@ def set_user_falco_rules(self, rules_content):
return self._set_falco_rules("user", rules_content)

def _get_policy_events_int(self, ctx):
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)
policy_events_url = self.url + '/api/policyEvents?from={:d}&to={:d}&offset={}&limit={}'.format(int(ctx['from']), int(ctx['to']), ctx['offset'], ctx['limit'])
if 'sampling' in ctx:
policy_events_url += '&sampling={:d}'.format(int(ctx['sampling']))

res = requests.get(policy_events_url, headers=self.hdrs, verify=self.ssl_verify)
if not self._checkResponse(res):
return [False, self.lasterr]

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

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

def get_policy_events_range(self, from_sec, to_sec):
def get_policy_events_range(self, from_sec, to_sec, sampling=None):
'''**Description**
Fetch all policy events that occurred in the time range [from_sec:to_sec]. This method is used in conjunction
with :func:`~sdcclient.SdSecureClient.get_more_policy_events` to provide paginated access to policy events.

**Arguments**
- from_sec: the start of the timerange for which to get events
- end_sec: the end of the timerange for which to get events
- sampling: sample all policy events using *sampling* interval.

**Success Return Value**
An array containing:
Expand All @@ -1972,15 +1977,19 @@ def get_policy_events_range(self, from_sec, to_sec):
"offset": 0,
"limit": 1000}

if sampling is not None:
ctx["sampling"] = sampling

return self._get_policy_events_int(ctx)

def get_policy_events_duration(self, duration_sec):
def get_policy_events_duration(self, duration_sec, sampling=None):
'''**Description**
Fetch all policy events that occurred in the last duration_sec seconds. This method is used in conjunction with
:func:`~sdcclient.SdSecureClient.get_more_policy_events` to provide paginated access to policy events.

**Arguments**
- duration_sec: Fetch all policy events that have occurred in the last *duration_sec* seconds.
- sampling: Sample all policy events using *sampling* interval.

**Success Return Value**
An array containing:
Expand All @@ -2001,6 +2010,9 @@ def get_policy_events_duration(self, duration_sec):
"offset": 0,
"limit": 1000}

if sampling is not None:
ctx["sampling"] = sampling

return self._get_policy_events_int(ctx)

def get_more_policy_events(self, ctx):
Expand Down