refactor: clean-up 'weird' formatting

This commit is contained in:
Alex Kelly 2021-11-04 00:17:24 -04:00
parent 87ac023631
commit 8e5a90ec1f

View file

@ -4,12 +4,14 @@ from datetime import datetime
def formatter(data, headers): def formatter(data, headers):
"""Pretty-print a pingdom notification.""" """Pretty-print a pingdom notification."""
# JSON data formatting was obtained from https://www.pingdom.com/resources/webhooks/ # JSON data formatting was obtained from https://www.pingdom.com/resources/webhooks/
# these are common to all check types
check_id = data["check_id"] check_id = data["check_id"]
check_name = data["check_name"] check_name = data["check_name"]
current_state = data["current_state"] current_state = data["current_state"]
local_time = datetime.fromtimestamp(data["state_changed_timestamp"]) local_time = datetime.fromtimestamp(data["state_changed_timestamp"])
if data["check_type"].lower() == "http": if data["check_type"].lower() == "http":
# http https or http_custom check types
try: try:
check_url = data["check_params"]["full_url"] check_url = data["check_params"]["full_url"]
data["body"] = ( data["body"] = (
@ -18,13 +20,11 @@ def formatter(data, headers):
f"[view details](https://my.pingdom.com/reports/responsetime#check={check_id})" f"[view details](https://my.pingdom.com/reports/responsetime#check={check_id})"
) )
except Exception as error: except Exception as error:
data[ data["body"] = (
"body" f"Error: An attempt to post from pingdom was malformed "
] = ( "(or I don't know how to handle what was sent).\n\n"
f"Error: An attempt to post from pingdom was malformed " f"{repr(error)}"
"(or I don't know how to handle what was sent).\n\n" )
f"{repr(error)}"
)
elif data["check_type"].lower() == "dns": elif data["check_type"].lower() == "dns":
# There are a bunch of values that are blanke when you do a test # There are a bunch of values that are blanke when you do a test
# so ignore them if value is unset # so ignore them if value is unset