From 4049c8e915b3b84b5ee6d1f8edf470bcfbde7abb Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 19 Nov 2020 12:35:09 +1100 Subject: [PATCH] Adds framework for "server health" display - Adds global context object "system_healthy" (boolean) - Framework for running system health checks - Updated system info forms - Displays warning next to user menu if system health errors exist (cherry picked from commit ce6d626ab39147fc389de90815ca8baae2385d82) --- InvenTree/InvenTree/context.py | 9 ++++++++ InvenTree/InvenTree/settings.py | 1 + InvenTree/InvenTree/status.py | 39 +++++++++++++++++++++++++++++++++ InvenTree/InvenTree/views.py | 2 +- InvenTree/templates/about.html | 5 ----- InvenTree/templates/navbar.html | 15 +++++++++++-- InvenTree/templates/stats.html | 27 +++++++++++++++++++++++ 7 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 InvenTree/InvenTree/status.py diff --git a/InvenTree/InvenTree/context.py b/InvenTree/InvenTree/context.py index aa66402ed6..8753749e3f 100644 --- a/InvenTree/InvenTree/context.py +++ b/InvenTree/InvenTree/context.py @@ -7,9 +7,18 @@ Provides extra global data to all templates. from InvenTree.status_codes import SalesOrderStatus, PurchaseOrderStatus from InvenTree.status_codes import BuildStatus, StockStatus +import InvenTree.status + from users.models import RuleSet +def health_status(request): + + return { + "system_healthy": InvenTree.status.check_system_health(), + } + + def status_codes(request): return { diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 3fc16464c6..d0695c4b7d 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -227,6 +227,7 @@ TEMPLATES = [ 'django.template.context_processors.i18n', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'InvenTree.context.health_status', 'InvenTree.context.status_codes', 'InvenTree.context.user_roles', ], diff --git a/InvenTree/InvenTree/status.py b/InvenTree/InvenTree/status.py new file mode 100644 index 0000000000..ec2422a254 --- /dev/null +++ b/InvenTree/InvenTree/status.py @@ -0,0 +1,39 @@ +""" +Provides system status functionality checks. +""" + +from django.utils.translation import ugettext as _ + +import logging + + +logger = logging.getLogger(__name__) + + +def check_system_health(**kwargs): + """ + Check that the InvenTree system is running OK. + + Returns True if all system checks pass. + """ + + result = True + + if not check_celery_worker(**kwargs): + result = False + logger.warning(_("Celery worker check failed")) + + if not result: + logger.warning(_("InvenTree system health checks failed")) + + return result + + +def check_celery_worker(**kwargs): + """ + Check that a celery worker is running. + """ + + # TODO - Checks that the configured celery worker thing is running + + return True diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index b2ef8f965a..d392c4cb62 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -792,7 +792,7 @@ class DatabaseStatsView(AjaxView): """ View for displaying database statistics """ ajax_template_name = "stats.html" - ajax_form_title = _("Database Statistics") + ajax_form_title = _("System Information") def get_context_data(self, **kwargs): diff --git a/InvenTree/templates/about.html b/InvenTree/templates/about.html index 0fbeef8454..80b29742ef 100644 --- a/InvenTree/templates/about.html +++ b/InvenTree/templates/about.html @@ -16,11 +16,6 @@
- - - - - diff --git a/InvenTree/templates/navbar.html b/InvenTree/templates/navbar.html index 148a96c583..9dafd5769e 100644 --- a/InvenTree/templates/navbar.html +++ b/InvenTree/templates/navbar.html @@ -52,7 +52,11 @@ diff --git a/InvenTree/templates/stats.html b/InvenTree/templates/stats.html index 5b194f17a5..7b8a9bb93a 100644 --- a/InvenTree/templates/stats.html +++ b/InvenTree/templates/stats.html @@ -4,6 +4,33 @@
{% trans "Instance Name" %}{% inventree_instance_name %}
{% trans "InvenTree Version" %}{% inventree_version %}
+ + + + + + + + + + + + + + + + {% if not system_healthy %} + {% for issue in system_issues %} + + {% endfor %} + {% endif %} +
{% trans "Server" %}
{% trans "Instance Name" %}{% inventree_instance_name %}
{% trans "Server status" %} + {% if system_healthy %} + {% trans "Healthy" %} + {% else %} + {% trans "Issues detected" %} + {% endif %} +
{% trans "Parts" %}