From 6a8b2ff5103f3698ed67007fe1164f464cad85b0 Mon Sep 17 00:00:00 2001 From: Sean Whalen Date: Tue, 2 Jan 2024 21:12:36 -0500 Subject: [PATCH] Add S3 output support for SMTP TLS reports --- parsedmarc/cli.py | 3 +-- parsedmarc/s3.py | 15 +++++++++++---- parsedmarc/syslog.py | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/parsedmarc/cli.py b/parsedmarc/cli.py index 3a045653..4923fbea 100644 --- a/parsedmarc/cli.py +++ b/parsedmarc/cli.py @@ -203,8 +203,7 @@ def process_reports(reports_): error_.__str__())) try: if opts.s3_bucket: - pass - # TODO: save SMTP TLS reports to S3 + s3_client.save_smtp_tls_report_to_s3(report) except Exception as error_: logger.error("S3 Error: {0}".format(error_.__str__())) try: diff --git a/parsedmarc/s3.py b/parsedmarc/s3.py index e8269abc..d7060467 100644 --- a/parsedmarc/s3.py +++ b/parsedmarc/s3.py @@ -48,11 +48,18 @@ def save_aggregate_report_to_s3(self, report): def save_forensic_report_to_s3(self, report): self.save_report_to_s3(report, 'forensic') + def save_smtp_tls_report_to_s3(self, report): + self.save_report_to_s3(report, "smtp_tls") + def save_report_to_s3(self, report, report_type): - report_date = human_timestamp_to_datetime( - report["report_metadata"]["begin_date"] - ) - report_id = report["report_metadata"]["report_id"] + if report_type == "smtp_tls": + report_date = report["begin_date"] + report_id = report["report_id"] + else: + report_date = human_timestamp_to_datetime( + report["report_metadata"]["begin_date"] + ) + report_id = report["report_metadata"]["report_id"] path_template = "{0}/{1}/year={2}/month={3:02d}/day={4:02d}/{5}.json" object_path = path_template.format( self.bucket_path, diff --git a/parsedmarc/syslog.py b/parsedmarc/syslog.py index 94f56a43..0fc47002 100644 --- a/parsedmarc/syslog.py +++ b/parsedmarc/syslog.py @@ -35,7 +35,7 @@ def save_forensic_report_to_syslog(self, forensic_reports): rows = parsed_forensic_reports_to_csv_rows(forensic_reports) for row in rows: self.logger.info(json.dumps(row)) - + def save_smtp_tls_report_to_syslog(self, smtp_tls_reports): rows = parsed_smtp_tls_reports_to_csv_rows(smtp_tls_reports) for row in rows: