From 2e8571b0d3b05e16bfa83966977d5f7ab51eeb04 Mon Sep 17 00:00:00 2001 From: Yasuhiro Harada Date: Mon, 13 Mar 2023 23:15:01 +0900 Subject: [PATCH] Fix fluentd timestamp --- Source/Interfaces/FluentdInterface.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Interfaces/FluentdInterface.py b/Source/Interfaces/FluentdInterface.py index 92af778..c6f5c67 100644 --- a/Source/Interfaces/FluentdInterface.py +++ b/Source/Interfaces/FluentdInterface.py @@ -1,5 +1,6 @@ from . import _Interface import logging +import datetime from fluent import sender @@ -39,9 +40,13 @@ def logger(self): def _send_message(self, msg, content_type, **kwargs): + creation_time = datetime.datetime.strptime(msg['CreationTime'], "%Y-%m-%dT%H:%M:%S").replace(tzinfo=datetime.timezone.utc) + unixtime = int(creation_time.timestamp()) + try: msg['tenant'] = self.tenant_name - self.logger.emit(content_type, msg) + self.logger.emit_with_time(content_type, unixtime, msg) + self.successfully_sent += 1 except Exception as e: logging.error("Error outputting to Fluentd: {}".format(e))