Merge branch 'patch-8' of https://github.com/Deventual/PyMISP into Deventual-patch-8

pull/105/head
Raphaël Vinot 2017-08-04 19:17:26 +02:00
commit 57778d2b0b
1 changed files with 22 additions and 6 deletions

View File

@ -378,12 +378,28 @@ 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)
return self._check_response(response)
def change_threat_level(self, event, threat_level_id):
e = self._make_mispevent(event)