From c8d962a594864fd19ec4d98c07d6d18048b5fff5 Mon Sep 17 00:00:00 2001 From: Deventual Date: Thu, 3 Aug 2017 14:19:48 +0300 Subject: [PATCH] Implemented much faster publish method to replace the old one new publish method that is less resourceful and also having the ability to send emails (same as the web interface). The method depends on the publish misp api method instead of update. --- pymisp/api.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pymisp/api.py b/pymisp/api.py index a908c6e..859fcb6 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -371,14 +371,28 @@ class PyMISP(object): else: eid = e.id return self.update_event(eid, e) - - def publish(self, event): - e = self._make_mispevent(event) - if e.published: + + def publish(self, event, alert=True): + """Publish event (with or without alert email) + :param event: pass event or event id (as string or int) to publish + :param alert: set to True by default (send alerting email) if False will not send alert + :return publish status + """ + if type(event) is int or type(event) is str: + full_event = self._make_mispevent(self.get_event(event)) + event_id = event + else: + full_event = self._make_mispevent(event) + event_id = full_event.id + if full_event.published: return {'error': 'Already published'} - e.publish() - return self.update(e) - + session = self.__prepare_session() + if not alert: + url = urljoin(self.root_url, 'events/publish/{}'.format(event_id)) + else: + url = urljoin(self.root_url, 'events/alert/{}'.format(event_id)) + response = session.post(url) + def change_threat_level(self, event, threat_level_id): e = self._make_mispevent(event) e.threat_level_id = threat_level_id