From 07f04fc5e9b57b51d02826a654c27d814495323a Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Thu, 25 Nov 2021 00:11:31 +0530 Subject: [PATCH 1/7] Update client.py --- splunklib/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/splunklib/client.py b/splunklib/client.py index 21d27a6e..0f4d884b 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -724,7 +724,7 @@ class Endpoint(object): """ def __init__(self, service, path): self.service = service - self.path = path if path.endswith('/') else path + '/' + self.path = path #if path.endswith('/') else path + '/' def get(self, path_segment="", owner=None, app=None, sharing=None, **query): """Performs a GET operation on the path segment relative to this endpoint. @@ -782,6 +782,8 @@ def get(self, path_segment="", owner=None, app=None, sharing=None, **query): if path_segment.startswith('/'): path = path_segment else: + if not self.path.endswith('/'): + self.path = self.path if self.path != "" and path_segment.startswith('/') else self.path + '/' path = self.service._abspath(self.path + path_segment, owner=owner, app=app, sharing=sharing) # ^-- This was "%s%s" % (self.path, path_segment). @@ -842,6 +844,8 @@ def post(self, path_segment="", owner=None, app=None, sharing=None, **query): if path_segment.startswith('/'): path = path_segment else: + if not self.path.endswith('/'): + self.path = self.path if self.path != "" and path_segment.startswith('/') else self.path + '/' path = self.service._abspath(self.path + path_segment, owner=owner, app=app, sharing=sharing) return self.service.post(path, owner=owner, app=app, sharing=sharing, **query) From b2d7bdee0ebc561d92eba71873306a9220600df7 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Fri, 26 Nov 2021 21:20:47 +0530 Subject: [PATCH 2/7] Update client.py --- splunklib/client.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/splunklib/client.py b/splunklib/client.py index 0f4d884b..84e6d070 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -782,8 +782,8 @@ def get(self, path_segment="", owner=None, app=None, sharing=None, **query): if path_segment.startswith('/'): path = path_segment else: - if not self.path.endswith('/'): - self.path = self.path if self.path != "" and path_segment.startswith('/') else self.path + '/' + if not self.path.endswith('/') and path_segment != "": + self.path = self.path if path_segment.startswith('/') else self.path + '/' path = self.service._abspath(self.path + path_segment, owner=owner, app=app, sharing=sharing) # ^-- This was "%s%s" % (self.path, path_segment). @@ -844,9 +844,10 @@ def post(self, path_segment="", owner=None, app=None, sharing=None, **query): if path_segment.startswith('/'): path = path_segment else: - if not self.path.endswith('/'): - self.path = self.path if self.path != "" and path_segment.startswith('/') else self.path + '/' + if not self.path.endswith('/') and path_segment != "": + self.path = self.path if path_segment.startswith('/') else self.path + '/' path = self.service._abspath(self.path + path_segment, owner=owner, app=app, sharing=sharing) + print(path) return self.service.post(path, owner=owner, app=app, sharing=sharing, **query) From a44a8f1d12cd258f6fd1cf6516e50ae733762244 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Fri, 26 Nov 2021 21:21:25 +0530 Subject: [PATCH 3/7] Update client.py --- splunklib/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/splunklib/client.py b/splunklib/client.py index 84e6d070..3ed8d729 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -847,7 +847,6 @@ def post(self, path_segment="", owner=None, app=None, sharing=None, **query): if not self.path.endswith('/') and path_segment != "": self.path = self.path if path_segment.startswith('/') else self.path + '/' path = self.service._abspath(self.path + path_segment, owner=owner, app=app, sharing=sharing) - print(path) return self.service.post(path, owner=owner, app=app, sharing=sharing, **query) From 2adde31aaf755274d55afa78ee2a6722a85e4646 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Wed, 1 Dec 2021 17:52:02 +0530 Subject: [PATCH 4/7] Test case for HEC event --- splunklib/client.py | 4 ++-- tests/test_service.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/splunklib/client.py b/splunklib/client.py index 3ed8d729..0dbdb168 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -783,7 +783,7 @@ def get(self, path_segment="", owner=None, app=None, sharing=None, **query): path = path_segment else: if not self.path.endswith('/') and path_segment != "": - self.path = self.path if path_segment.startswith('/') else self.path + '/' + self.path = self.path if path_segment != "" else self.path + '/' path = self.service._abspath(self.path + path_segment, owner=owner, app=app, sharing=sharing) # ^-- This was "%s%s" % (self.path, path_segment). @@ -845,7 +845,7 @@ def post(self, path_segment="", owner=None, app=None, sharing=None, **query): path = path_segment else: if not self.path.endswith('/') and path_segment != "": - self.path = self.path if path_segment.startswith('/') else self.path + '/' + self.path = self.path if path_segment != "" else self.path + '/' path = self.service._abspath(self.path + path_segment, owner=owner, app=app, sharing=sharing) return self.service.post(path, owner=owner, app=app, sharing=sharing, **query) diff --git a/tests/test_service.py b/tests/test_service.py index df78f54f..406c47a3 100755 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -167,6 +167,17 @@ def _create_unauthenticated_service(self): 'scheme': self.opts.kwargs['scheme'] }) + #To check the HEC event endpoint using Endpoint instance + def test_hec_event(self): + import json + service_hec = client.connect(host='localhost', scheme='https', port=8088, + token="11111111-1111-1111-1111-1111111111113") + event_collector_endpoint = client.Endpoint(service_hec, "/services/collector/event") + msg = {"index": "main", "event": "Hello World"} + response = event_collector_endpoint.post("", body=json.dumps(msg)) + body = response.body.read() + self.assertEqual(body.code, 200) + class TestCookieAuthentication(unittest.TestCase): def setUp(self): From ea8dae0e49bedf5fb516c8e589e82a891cbebc74 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Wed, 1 Dec 2021 18:14:57 +0530 Subject: [PATCH 5/7] Update test_service.py --- tests/test_service.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_service.py b/tests/test_service.py index 406c47a3..d1fa8911 100755 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -175,8 +175,7 @@ def test_hec_event(self): event_collector_endpoint = client.Endpoint(service_hec, "/services/collector/event") msg = {"index": "main", "event": "Hello World"} response = event_collector_endpoint.post("", body=json.dumps(msg)) - body = response.body.read() - self.assertEqual(body.code, 200) + self.assertEqual(response.status,200) class TestCookieAuthentication(unittest.TestCase): From dbfd038f324390acaa5a2d3511f5f9af254983aa Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Wed, 1 Dec 2021 18:28:14 +0530 Subject: [PATCH 6/7] Update client.py --- splunklib/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/splunklib/client.py b/splunklib/client.py index 0dbdb168..63b8d637 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -783,7 +783,7 @@ def get(self, path_segment="", owner=None, app=None, sharing=None, **query): path = path_segment else: if not self.path.endswith('/') and path_segment != "": - self.path = self.path if path_segment != "" else self.path + '/' + self.path = self.path + '/' path = self.service._abspath(self.path + path_segment, owner=owner, app=app, sharing=sharing) # ^-- This was "%s%s" % (self.path, path_segment). @@ -845,7 +845,7 @@ def post(self, path_segment="", owner=None, app=None, sharing=None, **query): path = path_segment else: if not self.path.endswith('/') and path_segment != "": - self.path = self.path if path_segment != "" else self.path + '/' + self.path = self.path + '/' path = self.service._abspath(self.path + path_segment, owner=owner, app=app, sharing=sharing) return self.service.post(path, owner=owner, app=app, sharing=sharing, **query) From f054c827c7b8c63d8040b48982e1a3c3a1c6e183 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Wed, 1 Dec 2021 18:49:09 +0530 Subject: [PATCH 7/7] Update client.py removed commented code --- splunklib/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/splunklib/client.py b/splunklib/client.py index 63b8d637..860f0c85 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -724,7 +724,7 @@ class Endpoint(object): """ def __init__(self, service, path): self.service = service - self.path = path #if path.endswith('/') else path + '/' + self.path = path def get(self, path_segment="", owner=None, app=None, sharing=None, **query): """Performs a GET operation on the path segment relative to this endpoint.