From e48aa8cbda82fdadb51613f2eb4d3426ee64e14d Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Thu, 24 Sep 2020 16:35:01 +0200 Subject: [PATCH] Replace Z with +00:00 for promtimes --- wmn.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wmn.py b/wmn.py index dac5075..3e328c6 100644 --- a/wmn.py +++ b/wmn.py @@ -18,7 +18,7 @@ room_pattern = re.compile(r'^[!#]\w+:[\w\-.]+$') # prometheus has to many sub-second digits in their timestamp, # so we get rid of nanoseconds here -promtime_to_isotime_pattern = re.compile(r'([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6})(?:[0-9]{3})(Z)') +promtime_to_isotime_pattern = re.compile(r'([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6})(?:[0-9]{3})(Z|[+-][0-9]{2}:[0-9]{2})') """ config.yml Example: @@ -211,7 +211,10 @@ def process_prometheus_request(): match = promtime_to_isotime_pattern.match(date_string) if match is None: abort(400, f'could not parse promtime "{date_string}" with pattern "{promtime_to_isotime_pattern}"') - return datetime.fromisoformat(''.join(match.groups())) + grps = list(match.groups()) + if grps[-1] == 'Z': + grps[-1] = '+00:00' + return datetime.fromisoformat(''.join(grps)) def extract_alert_message(alert: typing.Dict[str, typing.Any]) -> typing.Tuple[str, str]: """Takes the alert object and returns (text, html) as a string tuple."""