mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-15 09:24:11 +00:00
Fix grouping and sorting in the text version of the report/nag emails
Fixes: #679
This commit is contained in:
parent
874548874c
commit
65cef0b271
5 changed files with 54 additions and 15 deletions
|
@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
- Fix the display of ignored pings with non-zero exit status
|
- Fix the display of ignored pings with non-zero exit status
|
||||||
- Fix a race condition in the "Change Email" flow
|
- Fix a race condition in the "Change Email" flow
|
||||||
|
- Fix grouping and sorting in the text version of the report/nag emails (#679)
|
||||||
|
|
||||||
## v2.2.1 - 2022-06-13
|
## v2.2.1 - 2022-06-13
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,26 @@ from hc.api.management.commands.sendreports import Command
|
||||||
from hc.api.models import Check
|
from hc.api.models import Check
|
||||||
from hc.test import BaseTestCase
|
from hc.test import BaseTestCase
|
||||||
|
|
||||||
|
NAG_TEXT = """Hello,
|
||||||
|
|
||||||
|
This is a hourly reminder sent by Mychecks.
|
||||||
|
|
||||||
|
One check is currently DOWN.
|
||||||
|
|
||||||
|
|
||||||
|
Alices Project
|
||||||
|
==============
|
||||||
|
|
||||||
|
Status Name Last Ping
|
||||||
|
------ ---------------------------------------- ----------------------
|
||||||
|
DOWN Foo now
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
Cheers,
|
||||||
|
Mychecks
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class SendReportsTestCase(BaseTestCase):
|
class SendReportsTestCase(BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -28,6 +48,7 @@ class SendReportsTestCase(BaseTestCase):
|
||||||
|
|
||||||
# And it needs at least one check that has been pinged.
|
# And it needs at least one check that has been pinged.
|
||||||
self.check = Check(project=self.project, last_ping=now())
|
self.check = Check(project=self.project, last_ping=now())
|
||||||
|
self.check.name = "Foo"
|
||||||
self.check.status = "down"
|
self.check.status = "down"
|
||||||
self.check.save()
|
self.check.save()
|
||||||
|
|
||||||
|
@ -114,6 +135,8 @@ class SendReportsTestCase(BaseTestCase):
|
||||||
self.assertNotIn(str(self.check.code), email.body)
|
self.assertNotIn(str(self.check.code), email.body)
|
||||||
self.assertNotIn(str(self.check.code), html)
|
self.assertNotIn(str(self.check.code), html)
|
||||||
|
|
||||||
|
self.assertEqual(email.body, NAG_TEXT)
|
||||||
|
|
||||||
def test_it_obeys_next_nag_date(self):
|
def test_it_obeys_next_nag_date(self):
|
||||||
self.profile.next_nag_date = now() + td(days=1)
|
self.profile.next_nag_date = now() + td(days=1)
|
||||||
self.profile.save()
|
self.profile.save()
|
||||||
|
|
|
@ -34,7 +34,7 @@ def site_name():
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def absolute_site_logo_url():
|
def absolute_site_logo_url():
|
||||||
""" Return absolute URL to site's logo.
|
"""Return absolute URL to site's logo.
|
||||||
|
|
||||||
Uses settings.SITE_LOGO_URL if set, uses
|
Uses settings.SITE_LOGO_URL if set, uses
|
||||||
/static/img/logo.png as fallback.
|
/static/img/logo.png as fallback.
|
||||||
|
@ -111,7 +111,7 @@ def not_down_key(check):
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def sortchecks(checks, key):
|
def sortchecks(checks, key):
|
||||||
"""Sort the list of checks in-place by given key, then by status=down. """
|
"""Sort the list of checks in-place by given key, then by status=down."""
|
||||||
|
|
||||||
if key == "created":
|
if key == "created":
|
||||||
checks.sort(key=lambda check: check.created)
|
checks.sort(key=lambda check: check.created)
|
||||||
|
@ -137,7 +137,7 @@ def num_down_title(num_down):
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def down_title(check):
|
def down_title(check):
|
||||||
""" Prepare title tag for the Details page.
|
"""Prepare title tag for the Details page.
|
||||||
|
|
||||||
If the check is down, return "DOWN - Name - site_name".
|
If the check is down, return "DOWN - Name - site_name".
|
||||||
Otherwise, return "Name - site_name".
|
Otherwise, return "Name - site_name".
|
||||||
|
@ -153,7 +153,7 @@ def down_title(check):
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def break_underscore(s):
|
def break_underscore(s):
|
||||||
""" Add zero-width-space characters after underscores. """
|
"""Add zero-width-space characters after underscores."""
|
||||||
|
|
||||||
if len(s) > 30:
|
if len(s) > 30:
|
||||||
s = s.replace("_", "_\u200b")
|
s = s.replace("_", "_\u200b")
|
||||||
|
@ -163,7 +163,7 @@ def break_underscore(s):
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def fix_asterisks(s):
|
def fix_asterisks(s):
|
||||||
""" Prepend asterisks with "Combining Grapheme Joiner" characters. """
|
"""Prepend asterisks with "Combining Grapheme Joiner" characters."""
|
||||||
|
|
||||||
return s.replace("*", "\u034f*")
|
return s.replace("*", "\u034f*")
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ FORMATTED_PING_ENDPOINT = (
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def format_ping_endpoint(ping_url):
|
def format_ping_endpoint(ping_url):
|
||||||
""" Wrap the ping endpoint in span tags for styling with CSS. """
|
"""Wrap the ping endpoint in span tags for styling with CSS."""
|
||||||
|
|
||||||
assert ping_url.startswith(settings.PING_ENDPOINT)
|
assert ping_url.startswith(settings.PING_ENDPOINT)
|
||||||
tail = ping_url[len(settings.PING_ENDPOINT) :]
|
tail = ping_url[len(settings.PING_ENDPOINT) :]
|
||||||
|
@ -230,3 +230,8 @@ def format_ping_endpoint(ping_url):
|
||||||
@register.filter
|
@register.filter
|
||||||
def mask_key(key):
|
def mask_key(key):
|
||||||
return key[:4] + "*" * len(key[4:])
|
return key[:4] + "*" * len(key[4:])
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def underline(s):
|
||||||
|
return "=" * len(str(s))
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
{% load hc_extras %}
|
{% load hc_extras %}Hello,
|
||||||
Hello,
|
|
||||||
|
|
||||||
{% if nag %}This is a {% if nag_period == 3600 %}hourly {% endif %}{% if nag_period == 86400 %}daily {% endif %}reminder sent by {% site_name %}.
|
{% if nag %}This is a {% if nag_period == 3600 %}hourly {% endif %}{% if nag_period == 86400 %}daily {% endif %}reminder sent by {% site_name %}.
|
||||||
|
|
||||||
{% if num_down == 1%}One check is currently DOWN.{% else %}{{ num_down }} checks are currently DOWN.{% endif %}{% else %}This is a {{ monthly_or_weekly }} report sent by {% site_name %}.{% endif %}
|
{% if num_down == 1%}One check is currently DOWN.{% else %}{{ num_down }} checks are currently DOWN.{% endif %}{% else %}This is a {{ monthly_or_weekly }} report sent by {% site_name %}.{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% include 'emails/summary-text.html' %}
|
{% include 'emails/summary-text.html' %}
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
Cheers,
|
Cheers,
|
||||||
{% site_name %}
|
{% site_name %}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,18 @@
|
||||||
{% load humanize hc_extras %}
|
{% load humanize hc_extras linemode %}{% linemode %}
|
||||||
Status | Name | Last Ping
|
{% regroup checks by project as groups %}
|
||||||
--------+------------------------------------------+-----------------------{% for check in checks %}
|
|
||||||
{{ check.get_status|ljust:"6" }} | {{ check.name|default:'unnamed'|ljust:"40" }} | {% if check.last_ping %}{{ check.last_ping|naturaltime }}{% else %}Never{% endif %}{% endfor %}
|
|
||||||
|
|
||||||
|
{% for group in groups %}
|
||||||
|
{% line %}{% endline %}
|
||||||
|
{% line %}{% endline %}
|
||||||
|
{% line %}{{ group.grouper|safe }}{% endline %}
|
||||||
|
{% line %}{{ group.grouper|underline }}{% endline %}
|
||||||
|
{% line %}{% endline %}
|
||||||
|
{% line %}Status Name Last Ping{% endline %}
|
||||||
|
{% line %}------ ---------------------------------------- ----------------------{% endline %}
|
||||||
|
{% for check in group.list|sortchecks:sort %}
|
||||||
|
{% with check.get_status as status %}
|
||||||
|
{% line %}{% if status == "down" %}{{ status|upper|ljust:"6" }}{% else %}{{ status|ljust:"6" }}{% endif %} {{ check.name_then_code|safe|ljust:"40" }} {% if check.last_ping %}{{ check.last_ping|naturaltime }}{% else %}Never{% endif %}{% endline %}
|
||||||
|
{% endwith %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endlinemode %}
|
Loading…
Add table
Reference in a new issue