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.
pull/103/head
Deventual 2017-08-03 14:19:48 +03:00 committed by GitHub
parent 533b69d944
commit c8d962a594
1 changed files with 21 additions and 7 deletions

View File

@ -372,12 +372,26 @@ class PyMISP(object):
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)