chg: Make sure publishing the MISP event is done in the background

pull/309/head
Raphaël Vinot 2021-12-20 16:50:29 +01:00
parent 3055a850b7
commit b80dc1aab3
1 changed files with 7 additions and 0 deletions

View File

@ -93,7 +93,14 @@ class MISP():
to_return = [] to_return = []
for event in events: for event in events:
try: try:
# NOTE: POST the event as published publishes inline, which can tak a long time.
# Here, we POST as not published, and trigger the publishing in a second call.
background_publish = event.published
if background_publish:
event.published = False
new_event = self.client.add_event(event, pythonify=True) new_event = self.client.add_event(event, pythonify=True)
if background_publish and isinstance(new_event, MISPEvent):
self.client.publish(new_event)
except requests.exceptions.ReadTimeout: except requests.exceptions.ReadTimeout:
return {'error': 'The connection to MISP timed out, try increasing the timeout in the config.'} return {'error': 'The connection to MISP timed out, try increasing the timeout in the config.'}
if isinstance(new_event, MISPEvent): if isinstance(new_event, MISPEvent):