forked from GithubBackups/healthchecks
"My Checks" page: show the number of failed checks in the page title.
This commit is contained in:
parent
464d05c99f
commit
9ae4235c9b
@ -73,3 +73,11 @@ def sortchecks(checks, key):
|
|||||||
@register.filter
|
@register.filter
|
||||||
def trunc(s):
|
def trunc(s):
|
||||||
return s[:150]
|
return s[:150]
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def num_down_title(num_down):
|
||||||
|
if num_down:
|
||||||
|
return "%d down – %s" % (num_down, settings.SITE_NAME)
|
||||||
|
else:
|
||||||
|
return settings.SITE_NAME
|
||||||
|
@ -24,7 +24,7 @@ from hc.front.forms import (AddWebhookForm, NameTagsForm,
|
|||||||
TimeoutForm, AddUrlForm, AddEmailForm,
|
TimeoutForm, AddUrlForm, AddEmailForm,
|
||||||
AddOpsGenieForm, CronForm, AddSmsForm)
|
AddOpsGenieForm, CronForm, AddSmsForm)
|
||||||
from hc.front.schemas import telegram_callback
|
from hc.front.schemas import telegram_callback
|
||||||
from hc.front.templatetags.hc_extras import sortchecks
|
from hc.front.templatetags.hc_extras import num_down_title, sortchecks
|
||||||
from hc.lib import jsonschema
|
from hc.lib import jsonschema
|
||||||
from pytz import all_timezones
|
from pytz import all_timezones
|
||||||
from pytz.exceptions import UnknownTimeZoneError
|
from pytz.exceptions import UnknownTimeZoneError
|
||||||
@ -35,9 +35,10 @@ VALID_SORT_VALUES = ("name", "-name", "last_ping", "-last_ping", "created")
|
|||||||
|
|
||||||
|
|
||||||
def _tags_statuses(checks):
|
def _tags_statuses(checks):
|
||||||
tags, down, grace = {}, {}, {}
|
tags, down, grace, num_down = {}, {}, {}, 0
|
||||||
for check in checks:
|
for check in checks:
|
||||||
if check.get_status() == "down":
|
if check.get_status() == "down":
|
||||||
|
num_down += 1
|
||||||
for tag in check.tags_list():
|
for tag in check.tags_list():
|
||||||
down[tag] = "down"
|
down[tag] = "down"
|
||||||
elif check.in_grace_period():
|
elif check.in_grace_period():
|
||||||
@ -49,7 +50,7 @@ def _tags_statuses(checks):
|
|||||||
|
|
||||||
tags.update(grace)
|
tags.update(grace)
|
||||||
tags.update(down)
|
tags.update(down)
|
||||||
return tags
|
return tags, num_down
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@ -61,12 +62,14 @@ def my_checks(request):
|
|||||||
checks = list(Check.objects.filter(user=request.team.user))
|
checks = list(Check.objects.filter(user=request.team.user))
|
||||||
sortchecks(checks, request.profile.sort)
|
sortchecks(checks, request.profile.sort)
|
||||||
|
|
||||||
pairs = list(_tags_statuses(checks).items())
|
tags_statuses, num_down = _tags_statuses(checks)
|
||||||
|
pairs = list(tags_statuses.items())
|
||||||
pairs.sort(key=lambda pair: pair[0].lower())
|
pairs.sort(key=lambda pair: pair[0].lower())
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"page": "checks",
|
"page": "checks",
|
||||||
"checks": checks,
|
"checks": checks,
|
||||||
|
"num_down": num_down,
|
||||||
"now": timezone.now(),
|
"now": timezone.now(),
|
||||||
"tags": pairs,
|
"tags": pairs,
|
||||||
"ping_endpoint": settings.PING_ENDPOINT,
|
"ping_endpoint": settings.PING_ENDPOINT,
|
||||||
@ -93,7 +96,12 @@ def status(request):
|
|||||||
"last_ping": render_to_string("front/last_ping_cell.html", ctx)
|
"last_ping": render_to_string("front/last_ping_cell.html", ctx)
|
||||||
})
|
})
|
||||||
|
|
||||||
return JsonResponse({"details": details, "tags": _tags_statuses(checks)})
|
tags_statuses, num_down = _tags_statuses(checks)
|
||||||
|
return JsonResponse({
|
||||||
|
"details": details,
|
||||||
|
"tags": tags_statuses,
|
||||||
|
"title": num_down_title(num_down)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def _welcome_check(request):
|
def _welcome_check(request):
|
||||||
|
@ -297,6 +297,11 @@ $(function () {
|
|||||||
this.setAttribute("class", "btn btn-xs " + status);
|
this.setAttribute("class", "btn btn-xs " + status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (document.title != data.title) {
|
||||||
|
document.title = data.title;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load compress staticfiles hc_extras %}
|
{% load compress staticfiles hc_extras %}
|
||||||
|
|
||||||
{% block title %}My Checks - {% site_name %}{% endblock %}
|
{% block title %}{{ num_down|num_down_title }}{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<span class="n">URL</span> <span class="o">=</span> <span class="s2">"{{ ping_url }}"</span>
|
<span class="n">URL</span> <span class="o">=</span> <span class="s2">"{{ ping_url }}"</span>
|
||||||
|
|
||||||
<span class="k">def</span> <span class="nf">do_work</span><span class="p">():</span>
|
<span class="k">def</span> <span class="nf">do_work</span><span class="p">():</span>
|
||||||
<span class="c1"># Do actual work here.</span>
|
<span class="c1"># Do your number crunching, backup dumping, newsletter sending work here.</span>
|
||||||
<span class="c1"># Return a truthy value on success.</span>
|
<span class="c1"># Return a truthy value on success.</span>
|
||||||
<span class="c1"># Return a falsy value or throw an exception on failure.</span>
|
<span class="c1"># Return a falsy value or throw an exception on failure.</span>
|
||||||
<span class="k">return</span> <span class="bp">True</span>
|
<span class="k">return</span> <span class="bp">True</span>
|
||||||
|
@ -2,7 +2,7 @@ import requests
|
|||||||
URL = "PING_URL"
|
URL = "PING_URL"
|
||||||
|
|
||||||
def do_work():
|
def do_work():
|
||||||
# Do actual work here.
|
# Do your number crunching, backup dumping, newsletter sending work here.
|
||||||
# Return a truthy value on success.
|
# Return a truthy value on success.
|
||||||
# Return a falsy value or throw an exception on failure.
|
# Return a falsy value or throw an exception on failure.
|
||||||
return True
|
return True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user