PyMISP/examples/last.py

45 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pymisp import PyMISP
2016-03-21 21:24:15 +01:00
from keys import misp_url, misp_key, misp_verifycert
import argparse
import os
import json
# Usage for pipe masters: ./last.py -l 5h | jq .
def init(url, key):
2016-02-12 11:30:56 +01:00
return PyMISP(url, key, misp_verifycert, 'json')
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')
else:
print('No results for that time period')
exit(0)
else:
with open(out, 'w') as f:
2017-04-06 14:23:04 +02:00
f.write(json.dumps(result['response']))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Download latest events from a MISP instance.')
parser.add_argument("-l", "--last", required=True, help="can be defined in days, hours, minutes (for example 5d or 12h or 30m).")
parser.add_argument("-o", "--output", help="Output file")
args = parser.parse_args()
if args.output is not None and os.path.exists(args.output):
print('Output file already exists, abord.')
exit(0)
2015-11-06 10:14:45 +01:00
misp = init(misp_url, misp_key)
download_last(misp, args.last, args.output)