Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 63e944e

Browse files
author
Samuel Hassine
committed
[client] Allow consume remote custom live stream
1 parent ed075f3 commit 63e944e

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

pycti/connector/opencti_connector_helper.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def stop(self) -> None:
242242

243243
class ListenStream(threading.Thread):
244244
def __init__(
245-
self, helper, callback, url, token, verify_ssl, start_timestamp
245+
self, helper, callback, url, token, verify_ssl, start_timestamp, live_stream_id
246246
) -> None:
247247
threading.Thread.__init__(self)
248248
self.helper = helper
@@ -251,6 +251,7 @@ def __init__(
251251
self.token = token
252252
self.verify_ssl = verify_ssl
253253
self.start_timestamp = start_timestamp
254+
self.live_stream_id = live_stream_id
254255
self.exit = False
255256

256257
def run(self) -> None: # pylint: disable=too-many-branches
@@ -266,13 +267,17 @@ def run(self) -> None: # pylint: disable=too-many-branches
266267
# If URL and token are provided, likely consuming a remote stream
267268
if self.url is not None and self.token is not None:
268269
# If a live stream ID, appending the URL
269-
live_stream_uri = (
270-
f"/{self.helper.connect_live_stream_id}"
271-
if self.helper.connect_live_stream_id is not None
272-
else ""
273-
)
270+
if self.live_stream_id is not None:
271+
live_stream_uri = f"/{self.live_stream_id}"
272+
elif self.helper.connect_live_stream_id is not None:
273+
live_stream_uri = f"/{self.helper.connect_live_stream_id}"
274+
else:
275+
live_stream_uri = ""
274276
# Live stream "from" should be empty if start from the beginning
275-
if self.helper.connect_live_stream_id is not None:
277+
if (
278+
self.live_stream_id is not None
279+
or self.helper.connect_live_stream_id is not None
280+
):
276281
live_stream_from = (
277282
f"?from={current_state['connectorLastEventId']}"
278283
if current_state["connectorLastEventId"] != "-"
@@ -509,14 +514,21 @@ def listen_stream(
509514
token=None,
510515
verify_ssl=None,
511516
start_timestamp=None,
517+
live_stream_id=None,
512518
) -> ListenStream:
513519
"""listen for messages and register callback function
514520
515521
:param message_callback: callback function to process messages
516522
"""
517523

518524
self.listen_stream = ListenStream(
519-
self, message_callback, url, token, verify_ssl, start_timestamp
525+
self,
526+
message_callback,
527+
url,
528+
token,
529+
verify_ssl,
530+
start_timestamp,
531+
live_stream_id,
520532
)
521533
self.listen_stream.start()
522534
return self.listen_stream

0 commit comments

Comments
 (0)