From 92c6fc6c3f00d5d13fab387b2a32f01652e33fe7 Mon Sep 17 00:00:00 2001 From: akaila-splunk Date: Tue, 14 Jun 2022 17:52:52 +0530 Subject: [PATCH] updated saved search history method - added support for passing additional arguments in saved search history method --- splunklib/client.py | 7 +++++-- tests/test_saved_search.py | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/splunklib/client.py b/splunklib/client.py index b57c9b3cf..e6f45b67f 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -3212,12 +3212,15 @@ def fired_alerts(self): item=AlertGroup) return c - def history(self): + def history(self, **kwargs): """Returns a list of search jobs corresponding to this saved search. + :param `kwargs`: Additional arguments (optional). + :type kwargs: ``dict`` + :return: A list of :class:`Job` objects. """ - response = self.get("history") + response = self.get("history", **kwargs) entries = _load_atom_entries(response) if entries is None: return [] jobs = [] diff --git a/tests/test_saved_search.py b/tests/test_saved_search.py index 28d6436d1..c15921c0c 100755 --- a/tests/test_saved_search.py +++ b/tests/test_saved_search.py @@ -170,6 +170,27 @@ def test_history(self): finally: job.cancel() + def test_history_with_options(self): + try: + old_jobs = self.saved_search.history() + old_jobs_cnt = len(old_jobs) + + curr_job_cnt = 50 + for _ in range(curr_job_cnt): + job = self.saved_search.dispatch() + while not job.is_ready(): + sleep(0.1) + + # fetching all the jobs + history = self.saved_search.history(count=0) + self.assertEqual(len(history), old_jobs_cnt + curr_job_cnt) + + # fetching 3 jobs + history = self.saved_search.history(count=3) + self.assertEqual(len(history), 3) + finally: + job.cancel() + def test_scheduled_times(self): self.saved_search.update(cron_schedule='*/5 * * * *', is_scheduled=True) scheduled_times = self.saved_search.scheduled_times()