PyMISP icon indicating copy to clipboard operation
PyMISP copied to clipboard

Extend events() method to accept page and limit parameters

Open chrisinmtown opened this issue 3 years ago • 1 comments

Extend the PyMISP events() function to accept and send limit & page path parameters to match the behavior of the MISP web UI, which accepts URLs like this and adjusts the page accordingly:

https://misp.my-company.com/events/index/page:1/limit:5

chrisinmtown avatar May 12 '21 16:05 chrisinmtown

Just guessing, I would implement it like this:

diff --git a/pymisp/api.py b/pymisp/api.py
index 82eb2ca..b17fa4a 100644
--- a/pymisp/api.py
+++ b/pymisp/api.py
@@ -295,12 +295,20 @@ class PyMISP:
 
     # ## BEGIN Event ##
 
-    def events(self, pythonify: bool = False) -> Union[Dict, List[MISPEvent]]:
-        """Get all the events from the MISP instance
+    def events(self, limit: Optional[int] = None, page: Optional[int] = None,
+               pythonify: bool = False,) -> Union[Dict, List[MISPEvent]]:
+        """Get events from the MISP instance. If no limit or page parameters
+        are set, return all events.
 
+        :param limit: Limit the number of results returned, for example 10 events
+        :param page: If a limit is set, sets the page to be returned. page 3, limit 100 will return records 201->300
         :param pythonify: Returns a list of PyMISP Objects instead of the plain json output. Warning: it might use a lot of RAM
         """
         r = self._prepare_request('GET', 'events/index')
+        if limit:
+            r = r + f'/limit:{limit}'
+            if page:
+                r = r + f'/page:{page}'
         events_r = self._check_json_response(r)
         if not (self.global_pythonify or pythonify) or 'errors' in events_r:
             return events_r

chrisinmtown avatar May 12 '21 16:05 chrisinmtown