Browse Source

Adding "Overall status" badge.

pull/142/head
Pēteris Caune 7 years ago
parent
commit
1b7d4f6f3e
7 changed files with 57 additions and 8 deletions
  1. +5
    -1
      hc/accounts/views.py
  2. +8
    -1
      hc/api/urls.py
  3. +10
    -3
      hc/api/views.py
  4. +8
    -2
      hc/lib/badges.py
  5. +1
    -1
      hc/settings.py
  6. +5
    -0
      static/css/settings.css
  7. +20
    -0
      templates/accounts/badges.html

+ 5
- 1
hc/accounts/views.py View File

@ -289,7 +289,11 @@ def badges(request):
ctx = {
"page": "profile",
"urls": urls
"urls": urls,
"master": {
"svg": get_badge_url(username, "*"),
"json": get_badge_url(username, "*", format="json")
}
}
return render(request, "accounts/badges.html", ctx)


+ 8
- 1
hc/api/urls.py View File

@ -13,8 +13,15 @@ urlpatterns = [
url(r'^badge/([\w-]+)/([\w-]{8})/([\w-]+).svg$', views.badge,
name="hc-badge"),
url(r'^badge/([\w-]+)/([\w-]{8}).svg$', views.badge,
{"tag": "*"}, name="hc-badge-all"),
url(r'^badge/([\w-]+)/([\w-]{8})/([\w-]+).json$', views.badge,
{"format": "json"}, name="hc-badge-json", ),
{"format": "json"}, name="hc-badge-json"),
url(r'^badge/([\w-]+)/([\w-]{8}).json$', views.badge,
{"format": "json", "tag": "*"}, name="hc-badge-json-all"),
url(r'^api/v1/status/$', views.status),
]

+ 10
- 3
hc/api/views.py View File

@ -1,5 +1,6 @@
from datetime import timedelta as td
from django.conf import settings
from django.db import connection
from django.http import (HttpResponse, HttpResponseForbidden,
HttpResponseNotFound, JsonResponse)
@ -168,9 +169,15 @@ def badge(request, username, signature, tag, format="svg"):
return HttpResponseNotFound()
status = "up"
q = Check.objects.filter(user__username=username, tags__contains=tag)
q = Check.objects.filter(user__username=username)
if tag != "*":
q = q.filter(tags__contains=tag)
label = tag
else:
label = settings.MASTER_BADGE_LABEL
for check in q:
if tag not in check.tags_list():
if tag != "*" and tag not in check.tags_list():
continue
if status == "up" and check.in_grace_period():
@ -183,7 +190,7 @@ def badge(request, username, signature, tag, format="svg"):
if format == "json":
return JsonResponse({"status": status})
svg = get_badge_svg(tag, status)
svg = get_badge_svg(label, status)
return HttpResponse(svg, content_type="image/svg+xml")


+ 8
- 2
hc/lib/badges.py View File

@ -50,7 +50,13 @@ def check_signature(username, tag, sig):
def get_badge_url(username, tag, format="svg"):
view = "hc-badge-json" if format == "json" else "hc-badge"
sig = base64_hmac(str(username), tag, settings.SECRET_KEY)
url = reverse(view, args=[username, sig[:8], tag])
if tag == "*":
view = "hc-badge-json-all" if format == "json" else "hc-badge-all"
url = reverse(view, args=[username, sig[:8]])
else:
view = "hc-badge-json" if format == "json" else "hc-badge"
url = reverse(view, args=[username, sig[:8], tag])
return settings.SITE_ROOT + url

+ 1
- 1
hc/settings.py View File

@ -121,7 +121,7 @@ USE_L10N = True
USE_TZ = True
SITE_ROOT = "http://localhost:8000"
SITE_NAME = "healthchecks.io"
SITE_NAME = MASTER_BADGE_LABEL = "healthchecks.io"
PING_ENDPOINT = SITE_ROOT + "/ping/"
PING_EMAIL_DOMAIN = HOST
STATIC_URL = '/static/'


+ 5
- 0
static/css/settings.css View File

@ -29,6 +29,11 @@
background-color: #ffebea;
}
.table td.overall-status {
padding-top: 32px;
border-top: 0;
}
#badges-json {
display: none;
}


+ 20
- 0
templates/accounts/badges.html View File

@ -51,6 +51,17 @@
</td>
</tr>
{% endfor %}
<tr>
<td class="overall-status" colspan="2">Overall status:</td>
</tr>
<tr>
<td>
<img src="{{ master.svg }}" alt="" />
</td>
<td class="svg-url">
<code>{{ master.svg }}</code>
</td>
</tr>
</table>
<table id="badges-json" class="badges table">
{% for urldict in urls %}
@ -62,6 +73,15 @@
</td>
</tr>
{% endfor %}
<tr>
<td class="overall-status" colspan="2">Overall status:</td>
</tr>
<tr>
<td class="json-response" data-url="{{ master.json }}">
<td class="json-url">
<code>{{ master.json }}</code>
</td>
</tr>
</table>
{% else %}
<p>


Loading…
Cancel
Save