Fix unserializable datetime objects
This fixes the issue where publishing non JSON serializable objects to MozDef causes errors. This fix converts datetime objects to iso formatted dates.
This commit is contained in:
Родитель
4285803970
Коммит
430e321b77
|
@ -11,14 +11,23 @@
|
|||
from security_monkey import app
|
||||
import botocore.exceptions, botocore.parsers
|
||||
import mozdef_client
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
def json_serial(obj):
|
||||
"""JSON serializer for objects not serializable by default json code"""
|
||||
|
||||
if isinstance(obj, datetime):
|
||||
serial = obj.isoformat()
|
||||
return serial
|
||||
raise TypeError("Type not serializable")
|
||||
|
||||
def publish_to_mozdef(summary='',
|
||||
details={}):
|
||||
msg = mozdef_client.MozDefEvent('')
|
||||
msg.summary = summary
|
||||
msg.tags = ['asap']
|
||||
msg.details = details
|
||||
msg.details = json.loads(json.dumps(details, default=json_serial))
|
||||
region, account_id, queue_name = app.config.get(
|
||||
'SQS_QUEUE_ARN').split(':')[3:]
|
||||
|
||||
|
@ -36,4 +45,4 @@ def publish_to_mozdef(summary='',
|
|||
app.logger.critical(
|
||||
"Alerter: Attempt to send message to SQS queue {} in account {} "
|
||||
"in region {} failed with error {}".format(
|
||||
queue_name, account_id, region, e))
|
||||
queue_name, account_id, region, e))
|
||||
|
|
Загрузка…
Ссылка в новой задаче