From 7a2f228b802a8f6ef861e585482d510c2aaff121 Mon Sep 17 00:00:00 2001 From: Guus Bosman Date: Wed, 6 Dec 2023 20:03:45 -0500 Subject: [PATCH 1/2] Handle log messages in the modem with "Time Not Specified" Ignore these since they don't belong in a time-series database, given that they don't have a timestamp --- moto/modem_log.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/moto/modem_log.py b/moto/modem_log.py index c98e9a7..1698006 100644 --- a/moto/modem_log.py +++ b/moto/modem_log.py @@ -41,13 +41,19 @@ def from_response(cls, response: str) -> Generator[Self, None, None]: Parse a raw log string into a generator of ModemLog objects. """ for line in response.split("}-{"): - yield cls.from_line(line) + modemlog = cls.from_line(line) + if modemlog is not None: + yield modemlog + @classmethod def from_line(cls, line: str) -> Self: """ Parse a single log line into a ModemLog object. """ + if "Time Not Established" in line: + return None + timestamp_str, line = line.split("\n", 1) timestamp = parse_datetime(timestamp_str.replace("^", " ")) timestamp.replace(tzinfo=gettz(os.getenv("TZ", "UTC"))) From 299df431b1061b30a467787e44893767611e22de Mon Sep 17 00:00:00 2001 From: Guus Bosman Date: Wed, 6 Dec 2023 20:12:26 -0500 Subject: [PATCH 2/2] More in general, skip lines that break parsing. An empty modem log for example, will cause a failure. --- moto/modem_log.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/moto/modem_log.py b/moto/modem_log.py index 1698006..a8fa295 100644 --- a/moto/modem_log.py +++ b/moto/modem_log.py @@ -52,8 +52,10 @@ def from_line(cls, line: str) -> Self: Parse a single log line into a ModemLog object. """ if "Time Not Established" in line: + return None + if "\n" not in line: return None - + timestamp_str, line = line.split("\n", 1) timestamp = parse_datetime(timestamp_str.replace("^", " ")) timestamp.replace(tzinfo=gettz(os.getenv("TZ", "UTC")))