Merge branch 'master' of github.com:MISP/PyMISP

pull/80/head
Hannah Ward 2017-05-03 09:47:44 +01:00
commit d2b0c506a4
No known key found for this signature in database
GPG Key ID: 6F3BAD60DE190290
4 changed files with 16 additions and 13 deletions

View File

@ -19,8 +19,7 @@ def download_last(m, last, out=None):
result = m.download_last(last)
if out is None:
if 'response' in result:
for e in result['response']:
print(json.dumps(e) + '\n')
print(json.dumps(result['response']))
else:
print('No results for that time period')
exit(0)

View File

@ -18,12 +18,10 @@ def search(m, quiet, url, controller, out=None, **kwargs):
for e in result['response']:
print('{}{}{}\n'.format(url, '/events/view/', e['Event']['id']))
elif out is None:
for e in result['response']:
print(json.dumps(e) + '\n')
print(json.dumps(result['response']))
else:
with open(out, 'w') as f:
for e in result['response']:
f.write(json.dumps(e) + '\n')
f.write(json.dumps(result['response']))
if __name__ == '__main__':

View File

@ -18,12 +18,10 @@ def searchall(m, search, quiet, url, out=None):
for e in result['response']:
print('{}{}{}\n'.format(url, '/events/view/', e['Event']['id']))
elif out is None:
for e in result['response']:
print(json.dumps(e) + '\n')
print(json.dumps(result['response']))
else:
with open(out, 'w') as f:
for e in result['response']:
f.write(json.dumps(e) + '\n')
f.write(json.dumps(result['response']))
if __name__ == '__main__':

View File

@ -790,7 +790,7 @@ class PyMISP(object):
def search_index(self, published=None, eventid=None, tag=None, datefrom=None,
dateuntil=None, eventinfo=None, threatlevel=None, distribution=None,
analysis=None, attribute=None, org=None, async_callback=None):
analysis=None, attribute=None, org=None, async_callback=None, normalize=False):
"""Search only at the index level. Use ! infront of value as NOT, default OR
If using async, give a callback that takes 2 args, session and response:
basic usage is
@ -807,6 +807,7 @@ class PyMISP(object):
:param analysis: Analysis level(s) (0,1,2) | str or list
:param org: Organisation(s) | str or list
:param async_callback: Function to call when the request returns (if running async)
:param normalize: Normalize output | True or False
"""
allowed = {'published': published, 'eventid': eventid, 'tag': tag, 'Dateuntil': dateuntil,
'Datefrom': datefrom, 'eventinfo': eventinfo, 'threatlevel': threatlevel,
@ -836,11 +837,18 @@ class PyMISP(object):
if self.asynch:
if not async_callback:
warnings.warn("You haven't provided a callback!")
response = session.get(url, background_callback=async_callback)
response = session.post(url, data=json.dumps(to_post), background_callback=async_callback)
else:
response = session.post(url, data=json.dumps(to_post))
return self._check_response(response)
res = self._check_response(response)
if normalize:
to_return = {'response': []}
for elem in res['response']:
tmp = {'Event': elem}
to_return['response'].append(tmp)
res = to_return
return res
def search_all(self, value):
query = {'value': value, 'searchall': 1}