Skip to content
Snippets Groups Projects
Commit 4e7a5619 authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Show health checks on system status page

parent 23c12a46
No related branches found
No related tags found
1 merge request!261Resolve "Implement django-health-check"
......@@ -63,11 +63,6 @@ INSTALLED_APPS = [
"polymorphic",
"django_global_request",
"dbbackup",
"health_check",
"health_check.db",
"health_check.cache",
"health_check.storage",
"health_check.contrib.psutil",
"settings_context_processor",
"sass_processor",
"easyaudit",
......@@ -90,6 +85,11 @@ INSTALLED_APPS = [
"django_otp",
"otp_yubikey",
"aleksis.core",
"health_check",
"health_check.db",
"health_check.cache",
"health_check.storage",
"health_check.contrib.psutil",
"dynamic_preferences",
"dynamic_preferences.users.apps.UserPreferencesConfig",
"impersonate",
......
......@@ -63,6 +63,40 @@
</div>
</div>
<div class="card">
<div class="card-content">
<span class="card-title"> {% blocktrans %}System health checks{% endblocktrans %}</span>
<table>
<thead>
<tr>
<th colspan="2">{% trans "Service" %}</th>
<th>{% trans "Status" %}</th>
<th>{% trans "Time taken" %}</th>
</tr>
</thead>
<tbody>
{% for plugin in plugins %}
<tr>
<td>
{% if plugin.status %}
<i class="material-icons green-text" aria-hidden="true">check</i>
{% else %}
<i class="material-icons red-text" aria-hidden="true">warning</i>
{% endif %}
</td>
<td>{{ plugin.identifier }}</td>
<td>
{{ plugin.pretty_status }}
</td>
<td>{{ plugin.time_taken|floatformat:4 }} {% trans "seconds" %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% if tasks %}
<div class="card">
......
......@@ -19,7 +19,7 @@ urlpatterns = [
path("about/", views.about, name="about_aleksis"),
path("admin/", admin.site.urls),
path("data_management/", views.data_management, name="data_management"),
path("status/", views.system_status, name="system_status"),
path("status/", views.SystemStatus.as_view(), name="system_status"),
path("", include(tf_urls)),
path("accounts/logout/", auth_views.LogoutView.as_view(), name="logout"),
path("persons", views.persons, name="persons"),
......
......@@ -15,6 +15,7 @@ from guardian.shortcuts import get_objects_for_user
from haystack.inputs import AutoQuery
from haystack.query import SearchQuerySet
from haystack.views import SearchView
from health_check.views import MainView
from rules.contrib.views import permission_required
from .filters import GroupFilter
......@@ -300,22 +301,28 @@ def data_management(request: HttpRequest) -> HttpResponse:
return render(request, "core/management/data_management.html", context)
@permission_required("core.view_system_status")
def system_status(request: HttpRequest) -> HttpResponse:
class SystemStatus(MainView, PermissionRequiredMixin):
"""View giving information about the system status."""
template_name = "core/pages/system_status.html"
permission_required = "core.view_system_status"
context = {}
if "django_celery_results" in settings.INSTALLED_APPS:
from django_celery_results.models import TaskResult # noqa
from celery.task.control import inspect # noqa
if inspect().registered_tasks():
job_list = list(inspect().registered_tasks().values())[0]
results = []
for job in job_list:
results.append(TaskResult.objects.filter(task_name=job).last())
context["tasks"] = results
return render(request, "core/pages/system_status.html", context)
def get(self, request, *args, **kwargs):
status_code = 500 if self.errors else 200
if "django_celery_results" in settings.INSTALLED_APPS:
from django_celery_results.models import TaskResult # noqa
from celery.task.control import inspect # noqa
if inspect().registered_tasks():
job_list = list(inspect().registered_tasks().values())[0]
results = []
for job in job_list:
results.append(TaskResult.objects.filter(task_name=job).last())
context = {"plugins": self.plugins, "status_code": status_code}
return self.render_to_response(context, status=status_code)
@permission_required(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment