forked from GithubBackups/healthchecks
Adding "Overall status" badge.
This commit is contained in:
parent
edfcac5942
commit
1b7d4f6f3e
@ -289,7 +289,11 @@ def badges(request):
|
|||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"page": "profile",
|
"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)
|
return render(request, "accounts/badges.html", ctx)
|
||||||
|
@ -13,8 +13,15 @@ urlpatterns = [
|
|||||||
|
|
||||||
url(r'^badge/([\w-]+)/([\w-]{8})/([\w-]+).svg$', views.badge,
|
url(r'^badge/([\w-]+)/([\w-]{8})/([\w-]+).svg$', views.badge,
|
||||||
name="hc-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,
|
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),
|
url(r'^api/v1/status/$', views.status),
|
||||||
]
|
]
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from datetime import timedelta as td
|
from datetime import timedelta as td
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.http import (HttpResponse, HttpResponseForbidden,
|
from django.http import (HttpResponse, HttpResponseForbidden,
|
||||||
HttpResponseNotFound, JsonResponse)
|
HttpResponseNotFound, JsonResponse)
|
||||||
@ -168,9 +169,15 @@ def badge(request, username, signature, tag, format="svg"):
|
|||||||
return HttpResponseNotFound()
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
status = "up"
|
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:
|
for check in q:
|
||||||
if tag not in check.tags_list():
|
if tag != "*" and tag not in check.tags_list():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if status == "up" and check.in_grace_period():
|
if status == "up" and check.in_grace_period():
|
||||||
@ -183,7 +190,7 @@ def badge(request, username, signature, tag, format="svg"):
|
|||||||
if format == "json":
|
if format == "json":
|
||||||
return JsonResponse({"status": status})
|
return JsonResponse({"status": status})
|
||||||
|
|
||||||
svg = get_badge_svg(tag, status)
|
svg = get_badge_svg(label, status)
|
||||||
return HttpResponse(svg, content_type="image/svg+xml")
|
return HttpResponse(svg, content_type="image/svg+xml")
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,7 +50,13 @@ def check_signature(username, tag, sig):
|
|||||||
|
|
||||||
|
|
||||||
def get_badge_url(username, tag, format="svg"):
|
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)
|
sig = base64_hmac(str(username), tag, settings.SECRET_KEY)
|
||||||
|
|
||||||
|
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])
|
url = reverse(view, args=[username, sig[:8], tag])
|
||||||
|
|
||||||
return settings.SITE_ROOT + url
|
return settings.SITE_ROOT + url
|
||||||
|
@ -121,7 +121,7 @@ USE_L10N = True
|
|||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
SITE_ROOT = "http://localhost:8000"
|
SITE_ROOT = "http://localhost:8000"
|
||||||
SITE_NAME = "healthchecks.io"
|
SITE_NAME = MASTER_BADGE_LABEL = "healthchecks.io"
|
||||||
PING_ENDPOINT = SITE_ROOT + "/ping/"
|
PING_ENDPOINT = SITE_ROOT + "/ping/"
|
||||||
PING_EMAIL_DOMAIN = HOST
|
PING_EMAIL_DOMAIN = HOST
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
|
@ -29,6 +29,11 @@
|
|||||||
background-color: #ffebea;
|
background-color: #ffebea;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.table td.overall-status {
|
||||||
|
padding-top: 32px;
|
||||||
|
border-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
#badges-json {
|
#badges-json {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,17 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% 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>
|
||||||
<table id="badges-json" class="badges table">
|
<table id="badges-json" class="badges table">
|
||||||
{% for urldict in urls %}
|
{% for urldict in urls %}
|
||||||
@ -62,6 +73,15 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% 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>
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>
|
<p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user