Skip to content

Commit 2adde31

Browse files
committed
Test case for HEC event
1 parent a44a8f1 commit 2adde31

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

splunklib/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ def get(self, path_segment="", owner=None, app=None, sharing=None, **query):
783783
path = path_segment
784784
else:
785785
if not self.path.endswith('/') and path_segment != "":
786-
self.path = self.path if path_segment.startswith('/') else self.path + '/'
786+
self.path = self.path if path_segment != "" else self.path + '/'
787787
path = self.service._abspath(self.path + path_segment, owner=owner,
788788
app=app, sharing=sharing)
789789
# ^-- This was "%s%s" % (self.path, path_segment).
@@ -845,7 +845,7 @@ def post(self, path_segment="", owner=None, app=None, sharing=None, **query):
845845
path = path_segment
846846
else:
847847
if not self.path.endswith('/') and path_segment != "":
848-
self.path = self.path if path_segment.startswith('/') else self.path + '/'
848+
self.path = self.path if path_segment != "" else self.path + '/'
849849
path = self.service._abspath(self.path + path_segment, owner=owner, app=app, sharing=sharing)
850850
return self.service.post(path, owner=owner, app=app, sharing=sharing, **query)
851851

tests/test_service.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ 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+
body = response.body.read()
179+
self.assertEqual(body.code, 200)
180+
170181

171182
class TestCookieAuthentication(unittest.TestCase):
172183
def setUp(self):

0 commit comments

Comments
 (0)