Skip to content

Commit

Permalink
[client] Implement timeout on HTTP requests / RabbitMQ consumption + …
Browse files Browse the repository at this point in the history
…heartbeat (#726)
  • Loading branch information
SamuelHassine committed Sep 10, 2024
1 parent e0c3a8e commit 2e01c16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pycti/api/opencti_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ def query(self, query, variables=None):
verify=self.ssl_verify,
cert=self.cert,
proxies=self.proxies,
timeout=300,
)
# If no
else:
Expand All @@ -340,6 +341,7 @@ def query(self, query, variables=None):
verify=self.ssl_verify,
cert=self.cert,
proxies=self.proxies,
timeout=300,
)
# Build response
if r.status_code == 200:
Expand Down Expand Up @@ -383,6 +385,7 @@ def fetch_opencti_file(self, fetch_uri, binary=False, serialize=False):
verify=self.ssl_verify,
cert=self.cert,
proxies=self.proxies,
timeout=300,
)
if binary:
if serialize:
Expand Down
5 changes: 5 additions & 0 deletions pycti/connector/opencti_connector_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ def run(self) -> None:
# Connect the broker
self.pika_credentials = pika.PlainCredentials(self.user, self.password)
self.pika_parameters = pika.ConnectionParameters(
heartbeat=10,
blocked_connection_timeout=10,
host=self.host,
port=self.port,
virtual_host=self.vhost,
Expand Down Expand Up @@ -466,6 +468,7 @@ def ping(self) -> None:
"Connector state has been remotely reset",
{"state": self.get_state()},
)

if self.in_error:
self.in_error = False
self.connector_logger.info("API Ping back to normal")
Expand Down Expand Up @@ -1714,6 +1717,8 @@ def send_stix2_bundle(self, bundle: str, **kwargs) -> list:
self.connector_config["connection"]["pass"],
)
pika_parameters = pika.ConnectionParameters(
heartbeat=10,
blocked_connection_timeout=10,
host=self.connector_config["connection"]["host"],
port=self.connector_config["connection"]["port"],
virtual_host=self.connector_config["connection"]["vhost"],
Expand Down

0 comments on commit 2e01c16

Please sign in to comment.