mirror of https://github.com/MISP/PyMISP
parent
48e1211ed8
commit
2b9663cdf4
|
@ -100,18 +100,19 @@ class PyMISP(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Make sure the MISP instance is working and the URL is valid
|
# Make sure the MISP instance is working and the URL is valid
|
||||||
response = self.get_version()
|
|
||||||
misp_version = response['version'].split('.')
|
|
||||||
pymisp_version = __version__.split('.')
|
pymisp_version = __version__.split('.')
|
||||||
for a, b in zip(misp_version, pymisp_version):
|
response = self.get_recommended_api_version()
|
||||||
if a == b:
|
if not response.get('version'):
|
||||||
continue
|
warnings.warn("Unable to check the recommended PyMISP version (MISP <2.4.60), please upgrade.")
|
||||||
elif a < b:
|
else:
|
||||||
warnings.warn("Remote MISP instance (v{}) older than PyMISP (v{}). You should update your MISP instance, or install an older PyMISP version.".format(response['version'], __version__))
|
recommended_pymisp_version = response['version'].split('.')
|
||||||
else: # a > b
|
for a, b in zip(pymisp_version, recommended_pymisp_version):
|
||||||
# NOTE: That can happen and should not be blocking
|
if a == b:
|
||||||
warnings.warn("Remote MISP instance (v{}) newer than PyMISP (v{}). Please check if a newer version of PyMISP is available.".format(response['version'], __version__))
|
continue
|
||||||
continue
|
elif a > b:
|
||||||
|
warnings.warn("The version of PyMISP recommended by the MISP instance ({}) is older than the one you're using now ({}). Please upgrade the MISP instance or use an older PyMISP version.".format(response['version'], __version__))
|
||||||
|
else: # a < b
|
||||||
|
warnings.warn("The version of PyMISP recommended by the MISP instance ({}) is newer than the one you're using now ({}). Please upgrade PyMISP.".format(response['version'], __version__))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise PyMISPError('Unable to connect to MISP ({}). Please make sure the API key and the URL are correct (http/https is required): {}'.format(self.root_url, e))
|
raise PyMISPError('Unable to connect to MISP ({}). Please make sure the API key and the URL are correct (http/https is required): {}'.format(self.root_url, e))
|
||||||
|
@ -1045,6 +1046,13 @@ class PyMISP(object):
|
||||||
else:
|
else:
|
||||||
return {'error': 'Impossible to retrieve the version of the master branch.'}
|
return {'error': 'Impossible to retrieve the version of the master branch.'}
|
||||||
|
|
||||||
|
def get_recommended_api_version(self):
|
||||||
|
"""Returns the recommended API version from the server"""
|
||||||
|
session = self.__prepare_session()
|
||||||
|
url = urljoin(self.root_url, 'servers/getPyMISPVersion.json')
|
||||||
|
response = session.get(url)
|
||||||
|
return self._check_response(response)
|
||||||
|
|
||||||
def get_version(self):
|
def get_version(self):
|
||||||
"""Returns the version of the instance."""
|
"""Returns the version of the instance."""
|
||||||
session = self.__prepare_session()
|
session = self.__prepare_session()
|
||||||
|
|
|
@ -177,7 +177,7 @@ class MISPAttribute(object):
|
||||||
if kwargs.get('sig'):
|
if kwargs.get('sig'):
|
||||||
self.sig = kwargs['sig']
|
self.sig = kwargs['sig']
|
||||||
if kwargs.get('Tag'):
|
if kwargs.get('Tag'):
|
||||||
self.Tag = kwargs['Tag']
|
self.Tag = [t for t in kwargs['Tag'] if t]
|
||||||
|
|
||||||
# If the user wants to disable correlation, let them. Defaults to False.
|
# If the user wants to disable correlation, let them. Defaults to False.
|
||||||
self.disable_correlation = kwargs.get("disable_correlation", False)
|
self.disable_correlation = kwargs.get("disable_correlation", False)
|
||||||
|
@ -217,6 +217,8 @@ class MISPAttribute(object):
|
||||||
to_return = {'type': self.type, 'category': self.category, 'to_ids': self.to_ids,
|
to_return = {'type': self.type, 'category': self.category, 'to_ids': self.to_ids,
|
||||||
'distribution': self.distribution, 'value': self.value,
|
'distribution': self.distribution, 'value': self.value,
|
||||||
'comment': self.comment, 'disable_correlation': self.disable_correlation}
|
'comment': self.comment, 'disable_correlation': self.disable_correlation}
|
||||||
|
if self.uuid:
|
||||||
|
to_return['uuid'] = self.uuid
|
||||||
if self.sig:
|
if self.sig:
|
||||||
to_return['sig'] = self.sig
|
to_return['sig'] = self.sig
|
||||||
if self.sharing_group_id:
|
if self.sharing_group_id:
|
||||||
|
@ -234,9 +236,8 @@ class MISPAttribute(object):
|
||||||
to_return = self._json()
|
to_return = self._json()
|
||||||
if self.id:
|
if self.id:
|
||||||
to_return['id'] = self.id
|
to_return['id'] = self.id
|
||||||
if self.uuid:
|
|
||||||
to_return['uuid'] = self.uuid
|
|
||||||
if self.timestamp:
|
if self.timestamp:
|
||||||
|
# Should never be set on an update, MISP will automatically set it to now
|
||||||
to_return['timestamp'] = int(time.mktime(self.timestamp.timetuple()))
|
to_return['timestamp'] = int(time.mktime(self.timestamp.timetuple()))
|
||||||
if self.deleted is not None:
|
if self.deleted is not None:
|
||||||
to_return['deleted'] = self.deleted
|
to_return['deleted'] = self.deleted
|
||||||
|
@ -484,7 +485,7 @@ class MISPEvent(object):
|
||||||
if kwargs.get('Galaxy'):
|
if kwargs.get('Galaxy'):
|
||||||
self.Galaxy = kwargs['Galaxy']
|
self.Galaxy = kwargs['Galaxy']
|
||||||
if kwargs.get('Tag'):
|
if kwargs.get('Tag'):
|
||||||
self.Tag = kwargs['Tag']
|
self.Tag = [t for t in kwargs['Tag'] if t]
|
||||||
if kwargs.get('sig'):
|
if kwargs.get('sig'):
|
||||||
self.sig = kwargs['sig']
|
self.sig = kwargs['sig']
|
||||||
if kwargs.get('global_sig'):
|
if kwargs.get('global_sig'):
|
||||||
|
@ -545,6 +546,7 @@ class MISPEvent(object):
|
||||||
if self.publish_timestamp:
|
if self.publish_timestamp:
|
||||||
to_return['Event']['publish_timestamp'] = int(time.mktime(self.publish_timestamp.timetuple()))
|
to_return['Event']['publish_timestamp'] = int(time.mktime(self.publish_timestamp.timetuple()))
|
||||||
if self.timestamp:
|
if self.timestamp:
|
||||||
|
# Should never be set on an update, MISP will automatically set it to now
|
||||||
to_return['Event']['timestamp'] = int(time.mktime(self.timestamp.timetuple()))
|
to_return['Event']['timestamp'] = int(time.mktime(self.timestamp.timetuple()))
|
||||||
to_return['Event'] = _int_to_str(to_return['Event'])
|
to_return['Event'] = _int_to_str(to_return['Event'])
|
||||||
if self.attributes:
|
if self.attributes:
|
||||||
|
|
Loading…
Reference in New Issue