Skip to content

Commit

Permalink
Merge pull request #7 from LeakIX/dw/add-bulk-export-only-last-event
Browse files Browse the repository at this point in the history
Add bulk export, only last event
  • Loading branch information
dannywillems authored Dec 17, 2023
2 parents 732d9e8 + 479ba85 commit a10df6a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions example/example_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ def example_bulk_export():
print(response.json())


def example_bulk_export_last_event():
raw_query = '+plugin:"SmbPlugin" +country:"Belgium"'
query = RawQuery(raw_query)
response = CLIENT.bulk_export_last_event([query])
print(response.json())


def example_bulk_service():
raw_query = "+\"window.onload=function(){ url ='/webui';window.location.href=url;}\" +port:443"
query = RawQuery(raw_query)
Expand All @@ -124,3 +131,4 @@ def example_bulk_service():
example_get_plugins()
example_bulk_export()
example_bulk_service()
example_bulk_export_last_event()
13 changes: 13 additions & 0 deletions leakix/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ def bulk_export(self, queries: Optional[List[Query]] = None):
return ErrorResponse(response=r, response_json=r.json())
return r

def bulk_export_last_event(self, queries: Optional[List[Query]] = None):
response = self.bulk_export(queries)
if response.is_success():
for aggreg in response.json():
events = aggreg.events
sorted_events = sorted(
events,
key=lambda event: event.time,
reverse=True,
)
aggreg.events = [sorted_events[0]]
return response

def bulk_service(self, queries: Optional[List[Query]] = None):
url = "%s/bulk/service" % (self.base_url)
if queries is None or len(queries) == 0:
Expand Down

0 comments on commit a10df6a

Please # to comment.