Skip to content

Commit 89e53c0

Browse files
authored
Merge pull request #419 from splunk/hec_endpoint_issue
Hec endpoint issue
2 parents 611f4a3 + f054c82 commit 89e53c0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

splunklib/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ class Endpoint(object):
724724
"""
725725
def __init__(self, service, path):
726726
self.service = service
727-
self.path = path if path.endswith('/') else path + '/'
727+
self.path = path
728728

729729
def get(self, path_segment="", owner=None, app=None, sharing=None, **query):
730730
"""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):
782782
if path_segment.startswith('/'):
783783
path = path_segment
784784
else:
785+
if not self.path.endswith('/') and path_segment != "":
786+
self.path = self.path + '/'
785787
path = self.service._abspath(self.path + path_segment, owner=owner,
786788
app=app, sharing=sharing)
787789
# ^-- This was "%s%s" % (self.path, path_segment).
@@ -842,6 +844,8 @@ def post(self, path_segment="", owner=None, app=None, sharing=None, **query):
842844
if path_segment.startswith('/'):
843845
path = path_segment
844846
else:
847+
if not self.path.endswith('/') and path_segment != "":
848+
self.path = self.path + '/'
845849
path = self.service._abspath(self.path + path_segment, owner=owner, app=app, sharing=sharing)
846850
return self.service.post(path, owner=owner, app=app, sharing=sharing, **query)
847851

tests/test_service.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ def _create_unauthenticated_service(self):
167167
'scheme': self.opts.kwargs['scheme']
168168
})
169169

170+
#To check the HEC event endpoint using Endpoint instance
171+
def test_hec_event(self):
172+
import json
173+
service_hec = client.connect(host='localhost', scheme='https', port=8088,
174+
token="11111111-1111-1111-1111-1111111111113")
175+
event_collector_endpoint = client.Endpoint(service_hec, "/services/collector/event")
176+
msg = {"index": "main", "event": "Hello World"}
177+
response = event_collector_endpoint.post("", body=json.dumps(msg))
178+
self.assertEqual(response.status,200)
179+
170180

171181
class TestCookieAuthentication(unittest.TestCase):
172182
def setUp(self):

0 commit comments

Comments
 (0)