mirror of https://github.com/MISP/PyMISP
Fix python3 compat. Make Pep8 happy.
parent
a42be22f78
commit
8241d4ce93
|
@ -1,6 +1,7 @@
|
||||||
*.pyc
|
*.pyc
|
||||||
examples/keys.py
|
examples/keys.py
|
||||||
examples/cudeso.py
|
examples/cudeso.py
|
||||||
|
examples/feed-generator/output/*.json
|
||||||
build/*
|
build/*
|
||||||
dist/*
|
dist/*
|
||||||
pymisp.egg-info/*
|
pymisp.egg-info/*
|
||||||
|
|
|
@ -1,26 +1,21 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from pymisp import PyMISP
|
from pymisp import PyMISP
|
||||||
from settings import *
|
from settings import url, key, ssl, outputdir, filters, valid_attribute_distribution_levels
|
||||||
|
|
||||||
|
|
||||||
objectsToSave = {
|
objectsToSave = {'Orgc': {'fields': ['name', 'uuid'],
|
||||||
'Orgc': {
|
|
||||||
'fields': ['name', 'uuid'],
|
|
||||||
'multiple': False,
|
'multiple': False,
|
||||||
},
|
},
|
||||||
'Tag': {
|
'Tag': {'fields': ['name', 'colour', 'exportable'],
|
||||||
'fields': ['name', 'colour', 'exportable'],
|
|
||||||
'multiple': True,
|
'multiple': True,
|
||||||
},
|
},
|
||||||
'Attribute': {
|
'Attribute': {'fields': ['uuid', 'value', 'category', 'type',
|
||||||
'fields': ['uuid', 'value', 'category', 'type',
|
'comment', 'data', 'timestamp', 'to_ids'],
|
||||||
'comment', 'data', 'timestamp',
|
|
||||||
'to_ids'],
|
|
||||||
'multiple': True,
|
'multiple': True,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -43,15 +38,15 @@ def init():
|
||||||
|
|
||||||
|
|
||||||
def saveEvent(misp, uuid):
|
def saveEvent(misp, uuid):
|
||||||
try:
|
|
||||||
event = misp.get_event(uuid)
|
event = misp.get_event(uuid)
|
||||||
|
if not event.json().get('Event'):
|
||||||
|
print('Error while fetching event: {}'.format(event.json()['message']))
|
||||||
|
sys.exit('Could not create file for event ' + uuid + '.')
|
||||||
event = __cleanUpEvent(event)
|
event = __cleanUpEvent(event)
|
||||||
event = json.dumps(event)
|
event = json.dumps(event)
|
||||||
eventFile = open(os.path.join(outputdir, uuid + '.json'), 'w')
|
eventFile = open(os.path.join(outputdir, uuid + '.json'), 'w')
|
||||||
eventFile.write(event)
|
eventFile.write(event)
|
||||||
eventFile.close()
|
eventFile.close()
|
||||||
except:
|
|
||||||
sys.exit('Could not create file for event ' + uuid + '.')
|
|
||||||
|
|
||||||
|
|
||||||
def __cleanUpEvent(event):
|
def __cleanUpEvent(event):
|
||||||
|
@ -103,7 +98,8 @@ def saveManifest(manifest):
|
||||||
manifestFile = open(os.path.join(outputdir, 'manifest.json'), 'w')
|
manifestFile = open(os.path.join(outputdir, 'manifest.json'), 'w')
|
||||||
manifestFile.write(json.dumps(manifest))
|
manifestFile.write(json.dumps(manifest))
|
||||||
manifestFile.close()
|
manifestFile.close()
|
||||||
except:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
sys.exit('Could not create the manifest file.')
|
sys.exit('Could not create the manifest file.')
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,8 +108,7 @@ def __addEventToManifest(event):
|
||||||
for eventTag in event['EventTag']:
|
for eventTag in event['EventTag']:
|
||||||
tags.append({'name': eventTag['Tag']['name'],
|
tags.append({'name': eventTag['Tag']['name'],
|
||||||
'colour': eventTag['Tag']['colour']})
|
'colour': eventTag['Tag']['colour']})
|
||||||
return {
|
return {'Orgc': event['Orgc'],
|
||||||
'Orgc': event['Orgc'],
|
|
||||||
'Tag': tags,
|
'Tag': tags,
|
||||||
'info': event['info'],
|
'info': event['info'],
|
||||||
'date': event['date'],
|
'date': event['date'],
|
||||||
|
@ -138,8 +133,7 @@ if __name__ == '__main__':
|
||||||
for event in events:
|
for event in events:
|
||||||
saveEvent(misp, event['uuid'])
|
saveEvent(misp, event['uuid'])
|
||||||
manifest[event['uuid']] = __addEventToManifest(event)
|
manifest[event['uuid']] = __addEventToManifest(event)
|
||||||
print "Event " + str(counter) + "/" + str(total) + " exported."
|
print("Event " + str(counter) + "/" + str(total) + " exported.")
|
||||||
counter += 1
|
counter += 1
|
||||||
saveManifest(manifest)
|
saveManifest(manifest)
|
||||||
print 'Manifest saved. Feed creation completed.'
|
print('Manifest saved. Feed creation completed.')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue