diff --git a/examples/last.py b/examples/last.py index f7e5773..ed07be5 100755 --- a/examples/last.py +++ b/examples/last.py @@ -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) diff --git a/examples/search.py b/examples/search.py index a895f6d..0f6fee6 100644 --- a/examples/search.py +++ b/examples/search.py @@ -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__': diff --git a/examples/searchall.py b/examples/searchall.py index 97f19e9..6efe548 100755 --- a/examples/searchall.py +++ b/examples/searchall.py @@ -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__': diff --git a/pymisp/api.py b/pymisp/api.py index c1f3470..e60383f 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -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}