From 479ba85a5ae574ffe9eb55c98146cf27ab5410b9 Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Tue, 12 Dec 2023 22:47:14 +0100 Subject: [PATCH] Add bulk export, only last event --- example/example_client.py | 8 ++++++++ leakix/client.py | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/example/example_client.py b/example/example_client.py index 31a0312..42701e2 100644 --- a/example/example_client.py +++ b/example/example_client.py @@ -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) @@ -124,3 +131,4 @@ def example_bulk_service(): example_get_plugins() example_bulk_export() example_bulk_service() + example_bulk_export_last_event() diff --git a/leakix/client.py b/leakix/client.py index 09c5ca8..ee20948 100644 --- a/leakix/client.py +++ b/leakix/client.py @@ -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: