Replace Z with +00:00 for promtimes

This commit is contained in:
Benedikt Ziemons 2020-09-24 16:35:01 +02:00
parent b06179ad90
commit e48aa8cbda
Signed by: ben
GPG key ID: 0F54A7ED232D3319

7
wmn.py
View file

@ -18,7 +18,7 @@ room_pattern = re.compile(r'^[!#]\w+:[\w\-.]+$')
# prometheus has to many sub-second digits in their timestamp, # prometheus has to many sub-second digits in their timestamp,
# so we get rid of nanoseconds here # 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: config.yml Example:
@ -211,7 +211,10 @@ def process_prometheus_request():
match = promtime_to_isotime_pattern.match(date_string) match = promtime_to_isotime_pattern.match(date_string)
if match is None: if match is None:
abort(400, f'could not parse promtime "{date_string}" with pattern "{promtime_to_isotime_pattern}"') 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]: 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.""" """Takes the alert object and returns (text, html) as a string tuple."""