chg: [api] add /info entrypoint to give details about the version of threat actor galaxy loaded
parent
a8de744ca1
commit
9e41395073
|
@ -5,6 +5,7 @@ from tornado.escape import json_decode, json_encode
|
|||
import os.path
|
||||
import sys
|
||||
import json
|
||||
import datetime
|
||||
|
||||
class Query(tornado.web.RequestHandler):
|
||||
|
||||
|
@ -47,10 +48,15 @@ class Get(tornado.web.RequestHandler):
|
|||
result = {'error': 'UUID is not known in the MISP galaxy threat-actor'}
|
||||
return self.write("{}".format(json.dumps(result)))
|
||||
|
||||
class Info(tornado.web.RequestHandler):
|
||||
|
||||
def get(self):
|
||||
return self.write("{}".format(json.dumps(tai_info)))
|
||||
|
||||
application = tornado.web.Application([
|
||||
(r"/query", Query),
|
||||
(r"/get/(.*)", Get)
|
||||
(r"/get/(.*)", Get),
|
||||
(r"/info", Info)
|
||||
])
|
||||
|
||||
if not (os.path.exists('../misp-galaxy/clusters/threat-actor.json')):
|
||||
|
@ -61,17 +67,25 @@ with open('../misp-galaxy/clusters/threat-actor.json', 'rb') as galaxyta:
|
|||
|
||||
tai_full = {}
|
||||
tai_names = {}
|
||||
tai_info = {}
|
||||
|
||||
tai_info['version'] = threat_actors['version']
|
||||
tai_info['number_actors'] = 0
|
||||
tai_info['number_synonyms'] = 0
|
||||
tai_info['started'] = datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
||||
|
||||
for threat_actor in threat_actors['values']:
|
||||
tai_full[threat_actor['uuid']] = threat_actor
|
||||
tai_names[threat_actor['value'].lower()] = []
|
||||
tai_names[threat_actor['value'].lower()].append(threat_actor['uuid'])
|
||||
tai_info['number_actors'] += 1
|
||||
if 'meta' in threat_actor:
|
||||
if 'synonyms' in threat_actor['meta']:
|
||||
for synonym in threat_actor['meta']['synonyms']:
|
||||
if not synonym.lower() in tai_names:
|
||||
tai_names[synonym.lower()] = []
|
||||
tai_names[synonym.lower()].append(threat_actor['uuid'])
|
||||
tai_info['number_synonyms'] += 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue