Skip to content

Commit

Permalink
[connectors] Update connectors and Python lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Hassine committed Jul 7, 2019
1 parent c17646f commit 83a7b29
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion opencti-integration/connectors
Submodule connectors updated 1 files
+71 −32 misp/misp.py
31 changes: 15 additions & 16 deletions opencti-worker/worker_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ def __init__(self, verbose=True):
self.config['opencti']['verbose']
)

# Initialize the RabbitMQ connection
credentials = pika.PlainCredentials(self.config['rabbitmq']['username'], self.config['rabbitmq']['password'])
connection = pika.BlockingConnection(pika.ConnectionParameters(
host=self.config['rabbitmq']['hostname'],
port=self.config['rabbitmq']['port'],
virtual_host='/',
credentials=credentials
))
self.channel = connection.channel()
self.channel.exchange_declare(exchange='opencti', exchange_type='topic', durable=True)
self.channel.queue_declare('opencti-export', durable=True)
self.channel.queue_bind(exchange='opencti', queue='opencti-export', routing_key='export.*.*')

def export_action(self, ch, method, properties, body):
try:
data = json.loads(body)
Expand All @@ -57,14 +44,26 @@ def export_action(self, ch, method, properties, body):
return False

def consume(self):
self.channel.basic_consume(queue='opencti-export', on_message_callback=self.export_action, auto_ack=True)
self.channel.start_consuming()
# Initialize the RabbitMQ connection
credentials = pika.PlainCredentials(self.config['rabbitmq']['username'], self.config['rabbitmq']['password'])
connection = pika.BlockingConnection(pika.ConnectionParameters(
host=self.config['rabbitmq']['hostname'],
port=self.config['rabbitmq']['port'],
virtual_host='/',
credentials=credentials
))
channel = connection.channel()
channel.exchange_declare(exchange='opencti', exchange_type='topic', durable=True)
channel.queue_declare('opencti-export', durable=True)
channel.queue_bind(exchange='opencti', queue='opencti-export', routing_key='export.*.*')
channel.basic_consume(queue='opencti-export', on_message_callback=self.export_action, auto_ack=True)
channel.start_consuming()


if __name__ == '__main__':
worker_export = WorkerExport()
while True:
try:
worker_export = WorkerExport()
worker_export.consume()
except Exception as e:
print(e)
Expand Down
31 changes: 15 additions & 16 deletions opencti-worker/worker_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ def __init__(self, verbose=True):
self.config['opencti']['verbose']
)

# Initialize the RabbitMQ connection
credentials = pika.PlainCredentials(self.config['rabbitmq']['username'], self.config['rabbitmq']['password'])
connection = pika.BlockingConnection(pika.ConnectionParameters(
host=self.config['rabbitmq']['hostname'],
port=self.config['rabbitmq']['port'],
virtual_host='/',
credentials=credentials
))
self.channel = connection.channel()
self.channel.exchange_declare(exchange='opencti', exchange_type='topic', durable=True)
self.channel.queue_declare('opencti-import', durable=True)
self.channel.queue_bind(exchange='opencti', queue='opencti-import', routing_key='import.*.*')

def import_action(self, ch, method, properties, body):
try:
data = json.loads(body)
Expand All @@ -50,14 +37,26 @@ def import_action(self, ch, method, properties, body):
return False

def consume(self):
self.channel.basic_consume(queue='opencti-import', on_message_callback=self.import_action, auto_ack=True)
self.channel.start_consuming()
# Initialize the RabbitMQ connection
credentials = pika.PlainCredentials(self.config['rabbitmq']['username'], self.config['rabbitmq']['password'])
connection = pika.BlockingConnection(pika.ConnectionParameters(
host=self.config['rabbitmq']['hostname'],
port=self.config['rabbitmq']['port'],
virtual_host='/',
credentials=credentials
))
channel = connection.channel()
channel.exchange_declare(exchange='opencti', exchange_type='topic', durable=True)
channel.queue_declare('opencti-import', durable=True)
channel.queue_bind(exchange='opencti', queue='opencti-import', routing_key='import.*.*')
channel.basic_consume(queue='opencti-import', on_message_callback=self.import_action, auto_ack=True)
channel.start_consuming()


if __name__ == '__main__':
worker_import = WorkerImport()
while True:
try:
worker_import = WorkerImport()
worker_import.consume()
except Exception as e:
print(e)
Expand Down

0 comments on commit 83a7b29

Please sign in to comment.