diff --git a/moz-security-monkey/moz_security_monkey/common/utils/utils.py b/moz-security-monkey/moz_security_monkey/common/utils/utils.py index 91a5041..44b0c93 100644 --- a/moz-security-monkey/moz_security_monkey/common/utils/utils.py +++ b/moz-security-monkey/moz_security_monkey/common/utils/utils.py @@ -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)) \ No newline at end of file + queue_name, account_id, region, e))