mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1136 from SchrodingersGat/warning-icon
Add framework for "health checks"
This commit is contained in:
commit
6b104fbb8b
@ -7,9 +7,18 @@ Provides extra global data to all templates.
|
|||||||
from InvenTree.status_codes import SalesOrderStatus, PurchaseOrderStatus
|
from InvenTree.status_codes import SalesOrderStatus, PurchaseOrderStatus
|
||||||
from InvenTree.status_codes import BuildStatus, StockStatus
|
from InvenTree.status_codes import BuildStatus, StockStatus
|
||||||
|
|
||||||
|
import InvenTree.status
|
||||||
|
|
||||||
from users.models import RuleSet
|
from users.models import RuleSet
|
||||||
|
|
||||||
|
|
||||||
|
def health_status(request):
|
||||||
|
|
||||||
|
return {
|
||||||
|
"system_healthy": InvenTree.status.check_system_health(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def status_codes(request):
|
def status_codes(request):
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -227,6 +227,7 @@ TEMPLATES = [
|
|||||||
'django.template.context_processors.i18n',
|
'django.template.context_processors.i18n',
|
||||||
'django.contrib.auth.context_processors.auth',
|
'django.contrib.auth.context_processors.auth',
|
||||||
'django.contrib.messages.context_processors.messages',
|
'django.contrib.messages.context_processors.messages',
|
||||||
|
'InvenTree.context.health_status',
|
||||||
'InvenTree.context.status_codes',
|
'InvenTree.context.status_codes',
|
||||||
'InvenTree.context.user_roles',
|
'InvenTree.context.user_roles',
|
||||||
],
|
],
|
||||||
|
39
InvenTree/InvenTree/status.py
Normal file
39
InvenTree/InvenTree/status.py
Normal file
@ -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
|
@ -792,7 +792,7 @@ class DatabaseStatsView(AjaxView):
|
|||||||
""" View for displaying database statistics """
|
""" View for displaying database statistics """
|
||||||
|
|
||||||
ajax_template_name = "stats.html"
|
ajax_template_name = "stats.html"
|
||||||
ajax_form_title = _("Database Statistics")
|
ajax_form_title = _("System Information")
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
|
||||||
|
@ -16,11 +16,6 @@
|
|||||||
<div>
|
<div>
|
||||||
<table class='table table-striped table-condensed'>
|
<table class='table table-striped table-condensed'>
|
||||||
<col width='25'>
|
<col width='25'>
|
||||||
<tr>
|
|
||||||
<td></td>
|
|
||||||
<td>{% trans "Instance Name" %}</td>
|
|
||||||
<td>{% inventree_instance_name %}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><span class='fas fa-hashtag'></span></td>
|
<td><span class='fas fa-hashtag'></span></td>
|
||||||
<td>{% trans "InvenTree Version" %}</td><td><a href="https://github.com/inventree/InvenTree/releases">{% inventree_version %}</a></td>
|
<td>{% trans "InvenTree Version" %}</td><td><a href="https://github.com/inventree/InvenTree/releases">{% inventree_version %}</a></td>
|
||||||
|
@ -52,7 +52,11 @@
|
|||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<li class='dropdown'>
|
<li class='dropdown'>
|
||||||
<a class='dropdown-toggle' data-toggle='dropdown' href="#"><span class="fas fa-user"></span> <b>{{ user.get_username }}</b></a>
|
<a class='dropdown-toggle' data-toggle='dropdown' href="#">
|
||||||
|
{% if not system_healthy %}
|
||||||
|
<span title='{% trans "InvenTree server issues detected" %}' class='fas fa-exclamation-triangle icon-red'></span>
|
||||||
|
{% endif %}
|
||||||
|
<span class="fas fa-user"></span> <b>{{ user.get_username }}</b></a>
|
||||||
<ul class='dropdown-menu'>
|
<ul class='dropdown-menu'>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
{% if user.is_staff %}
|
{% if user.is_staff %}
|
||||||
@ -65,8 +69,15 @@
|
|||||||
<li><a href="{% url 'login' %}"><span class="fas fa-sign-in-alt"></span> {% trans "Login" %}</a></li>
|
<li><a href="{% url 'login' %}"><span class="fas fa-sign-in-alt"></span> {% trans "Login" %}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<hr>
|
<hr>
|
||||||
|
<li id='launch-stats'><a href='#'>
|
||||||
|
{% if system_healthy %}
|
||||||
|
<span class='fas fa-server'>
|
||||||
|
{% else %}
|
||||||
|
<span class='fas fa-exclamation-triangle icon-red'>
|
||||||
|
{% endif %}
|
||||||
|
</span> {% trans "System Information" %}
|
||||||
|
</a></li>
|
||||||
<li id='launch-about'><a href='#'><span class="fas fa-info-circle"></span> {% trans "About InvenTree" %}</a></li>
|
<li id='launch-about'><a href='#'><span class="fas fa-info-circle"></span> {% trans "About InvenTree" %}</a></li>
|
||||||
<li id='launch-stats'><a href='#'><span class='fas fa-chart-pie'></span> {% trans "Statistics" %}</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -4,6 +4,33 @@
|
|||||||
|
|
||||||
<table class='table table-striped table-condensed'>
|
<table class='table table-striped table-condensed'>
|
||||||
<col width='25'>
|
<col width='25'>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="3"><b>{% trans "Server" %}</b></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><span class='fas fa-server'></span></td>
|
||||||
|
<td>{% trans "Instance Name" %}</td>
|
||||||
|
<td>{% inventree_instance_name %}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><span class='fas fa-exclamation-triangle'></span></td>
|
||||||
|
<td>{% trans "Server status" %}</td>
|
||||||
|
<td>
|
||||||
|
{% if system_healthy %}
|
||||||
|
<span class='label label-green'>{% trans "Healthy" %}</span>
|
||||||
|
{% else %}
|
||||||
|
<span class='label label-red'>{% trans "Issues detected" %}</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{% if not system_healthy %}
|
||||||
|
{% for issue in system_issues %}
|
||||||
|
<!-- TODO - Enumerate system issues here! -->
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan='3'><b>{% trans "Parts" %}</b></td>
|
<td colspan='3'><b>{% trans "Parts" %}</b></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user