Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pycti/opencti_connector_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ def _create_channel(self):
def _create_queue(self):
if self.channel is not None:
config_encoded = base64.b64encode(json.dumps(self.config).encode('utf-8')).decode('utf-8')
self.channel.queue_delete(self.queue_name)
self.channel.queue_declare(self.queue_name, durable=True, arguments={'config': config_encoded})
check = self.channel.queue_declare(self.queue_name, durable=True, passive=True, arguments={'config': config_encoded})
if not check:
self.channel.queue_delete(self.queue_name)
self.channel.queue_declare(self.queue_name, durable=True, arguments={'config': config_encoded})
self.channel.queue_bind(queue=self.queue_name, exchange=EXCHANGE_NAME, routing_key=self.routing_key)

def _reconnect(self):
self.connection = self._connect()
self.channel = self._create_channel()
self._create_queue()

def send_stix2_bundle(self, bundle, entities_types=[]):
bundles = self.split_stix2_bundle(bundle)
Expand All @@ -89,7 +90,7 @@ def _send_bundle(self, type, bundle, entities_types=[]):
:param bundle: A valid STIX2 bundle
:param entities_types: Entities types to ingest
"""
if not self.channel.is_open:
if self.channel is None or not self.channel.is_open:
self._reconnect()

# Validate the STIX 2 bundle
Expand Down
2 changes: 1 addition & 1 deletion pycti/opencti_stix2.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def import_object(self, stix_object, update=False):
title,
external_reference['description'] if 'description' in external_reference else None,
published,
'external',
'Threat Report',
2
)['id']

Expand Down