From f4808719b0d86008aa7f36e25ef4cb294b3fca42 Mon Sep 17 00:00:00 2001 From: Alex Kelly Date: Wed, 12 Jan 2022 12:08:53 -0500 Subject: [PATCH] refactor(formatter/pingdom): build message content line-by-line feat(formatter/pingdom): add tags to output (if set) --- matrix_webhook/formatters/pingdom.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/matrix_webhook/formatters/pingdom.py b/matrix_webhook/formatters/pingdom.py index a5d6dfa..b728f97 100644 --- a/matrix_webhook/formatters/pingdom.py +++ b/matrix_webhook/formatters/pingdom.py @@ -8,17 +8,20 @@ def formatter(data, headers): check_id = data["check_id"] check_name = data["check_name"] current_state = data["current_state"] + tags = data["tags"] local_time = datetime.fromtimestamp(data["state_changed_timestamp"]) if data["check_type"].lower() == "http": # http https or http_custom check types try: check_url = data["check_params"]["full_url"] - data["body"] = ( - f"###{check_name} is {current_state}\n\n{check_url}" - f" marked {current_state} at {local_time} ⚬ " - f"[view details](https://my.pingdom.com/reports/responsetime#check={check_id})" - ) + message = "" + message += f"###{check_name} is {current_state}\n\n{check_url}" + message += f" marked {current_state} at {local_time} ⚬ " + message += f"[view details](https://my.pingdom.com/reports/responsetime#check={check_id})" + if tags: + message += f"\n\nTags: {tags}" + data["body"] = message except Exception as error: data["body"] = ( f"Error: An attempt to post from pingdom was malformed "