From 605e4f9ffde30b08c704cbb85be7922ce936658d Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Tue, 24 Nov 2026 00:42:43 +0100 Subject: [PATCH] Show live database status and local service actions --- src/coulobre/hosting/health_views.py | 54 +++++++- src/coulobre/hosting/operator_tools.py | 115 ++++++++++-------- .../templates/hosting/database_monitor.html | 26 ++++ .../hosting/operator_operation_history.html | 14 +++ .../templates/hosting/operator_tools.html | 29 ----- .../templates/hosting/server_updates.html | 33 +++++ .../templates/hosting/service_health.html | 35 ++++-- .../hosting/test_operator_workspaces.py | 31 ++++- src/coulobre/hosting/test_service_health.py | 48 +++++++- src/coulobre/hosting/urls.py | 9 +- src/coulobre/hosting/workspaces.py | 8 +- src/coulobre/operator_node.py | 26 ++-- 12 files changed, 314 insertions(+), 114 deletions(-) create mode 100644 src/coulobre/hosting/templates/hosting/database_monitor.html create mode 100644 src/coulobre/hosting/templates/hosting/operator_operation_history.html delete mode 100644 src/coulobre/hosting/templates/hosting/operator_tools.html create mode 100644 src/coulobre/hosting/templates/hosting/server_updates.html diff --git a/src/coulobre/hosting/health_views.py b/src/coulobre/hosting/health_views.py index a7252ee..5328386 100644 --- a/src/coulobre/hosting/health_views.py +++ b/src/coulobre/hosting/health_views.py @@ -1,18 +1,28 @@ from datetime import timedelta +from pathlib import Path from django.conf import settings +from django.contrib import messages from django.contrib.auth.mixins import PermissionRequiredMixin +from django.core.exceptions import PermissionDenied +from django.http import HttpResponseBadRequest +from django.shortcuts import redirect from django.utils import timezone from django.utils.decorators import method_decorator from django.views.decorators.cache import never_cache from django.views.generic import TemplateView +from coulobre.operator_node import SERVICES as CONTROL_UNITS +from coulobre.operator_node import SOCKET, OperatorRequest from coulobre.service_health import HEALTH_DETAILS, SERVICES, HealthResult from .access import OperatorOnlyMixin -from .models import ServiceHealth +from .models import OperatorOperation, ServiceHealth +from .operator_tools import queue_operator_request STALE_AFTER = timedelta(minutes=5) +SERVICE_ACTIONS = ("reload", "restart") +CONTROL_TARGETS = {unit: target for target, unit in CONTROL_UNITS.items()} STATUS = { HealthResult.ACTIVE: ("Active", "ready"), HealthResult.INACTIVE: ("Unavailable", "suspended"), @@ -29,8 +39,37 @@ class ServiceHealthView( permission_required = "hosting.view_servicehealth" template_name = "hosting/service_health.html" + def can_control(self): + user = self.request.user + return user.is_superuser and user.is_verified() + + def post(self, request, *args, **kwargs): + if not self.can_control(): + raise PermissionDenied + action = request.POST.get("action", "") + target = request.POST.get("target", "") + if action not in SERVICE_ACTIONS or target not in { + CONTROL_TARGETS.get(SERVICES[service][1]) + for node in settings.SERVICE_HEALTH_TARGETS + if node.transport == "local" + for service in node.services + }: + return HttpResponseBadRequest("Choose a controlled local service.") + if not Path(SOCKET).is_socket(): + messages.error( + request, "The local operator worker is unavailable." + ) + else: + queue_operator_request( + request.user, OperatorRequest(action, target) + ) + messages.success(request, "Service operation queued.") + return redirect("panel:service_health") + def get_context_data(self, **kwargs): targets = settings.SERVICE_HEALTH_TARGETS + can_control = self.can_control() + controls_available = can_control and Path(SOCKET).is_socket() readings = { (reading.node, reading.service): reading for reading in ServiceHealth.objects.filter( @@ -48,17 +87,30 @@ class ServiceHealthView( readings.get((target.node, service)), cutoff, ) + | { + "control_target": CONTROL_TARGETS.get( + SERVICES[service][1] + ) + } for service in target.services ], ) for target in targets ], + controls_available=controls_available, + show_operation_history=can_control, + jobs=OperatorOperation.objects.filter( + action__in=SERVICE_ACTIONS, + ).order_by("-pk")[:20] + if can_control + else (), **kwargs, ) def service_row(service, reading, cutoff): row = { + "key": service, "name": SERVICES[service][0], "status": "Unknown", "style": "pending", diff --git a/src/coulobre/hosting/operator_tools.py b/src/coulobre/hosting/operator_tools.py index 78e5f47..c68510b 100644 --- a/src/coulobre/hosting/operator_tools.py +++ b/src/coulobre/hosting/operator_tools.py @@ -3,69 +3,61 @@ from pathlib import Path from django import forms from django.contrib import messages -from django.db import transaction +from django.db import DatabaseError, connection, transaction from django.shortcuts import redirect from django.utils import timezone +from django.utils.decorators import method_decorator +from django.views.decorators.cache import never_cache from django.views.generic import FormView, TemplateView -from coulobre.operator_node import SERVICES, SOCKET, OperatorRequest +from coulobre.operator_node import ( + DATABASE_COUNTERS_QUERY, + DATABASE_VERSION_QUERY, + SOCKET, + OperatorRequest, + database_report_from_rows, +) from .account_administration import OperatorAuthorization from .models import OperatorOperation from .tasks import run_operator_operation from .update_views import inspect_linked_nodes -TOOL_ACTIONS = { - "packages": ( - "Server package updates", - ("package-preview", "package-upgrade"), - ), - "services": ("System services", ("reload", "restart")), - "database": ("Database monitor", ("database-report",)), -} ACTION_LABELS = { "package-preview": "Review available updates", "package-upgrade": "Apply reviewed updates", - "reload": "Reload", - "restart": "Restart", - "database-report": "Collect MariaDB status", } -class OperatorToolForm(forms.Form): - action = forms.ChoiceField() - preview_id = forms.IntegerField(required=False, widget=forms.HiddenInput) - target = forms.ChoiceField( - required=False, - choices=[ - ("", "Select a service"), - *[(key, label) for key, label in SERVICES.items()], - ], +def queue_operator_request(user, spec, *, source=None): + job = OperatorOperation.objects.create( + actor=user, + action=spec.action, + target=spec.target, + plan=spec.plan, + source=source, ) + transaction.on_commit(lambda: run_operator_operation.delay(job.pk)) + + +class ServerUpdateForm(forms.Form): + action = forms.ChoiceField(choices=ACTION_LABELS.items()) + preview_id = forms.IntegerField(required=False, widget=forms.HiddenInput) confirm = forms.BooleanField( required=False, label="I reviewed the change and want to apply it" ) - def __init__(self, *args, actions, preview, **kwargs): + def __init__(self, *args, preview, **kwargs): super().__init__(*args, **kwargs) self.preview = preview self.initial["preview_id"] = preview.pk if preview else None - self.fields["action"].choices = [ - (action, ACTION_LABELS[action]) for action in actions - ] - if "reload" not in actions: - self.fields.pop("target") - if actions == ("database-report",): - self.fields.pop("confirm") def clean(self): data = super().clean() if self.errors: return data action = data["action"] - if action in {"reload", "restart", "package-upgrade"} and not data.get( - "confirm" - ): + if action == "package-upgrade" and not data.get("confirm"): self.add_error( "confirm", "Confirm this change before applying it." ) @@ -80,16 +72,15 @@ class OperatorToolForm(forms.Form): ) plan = self.preview.result.get("fingerprint", "") try: - self.spec = OperatorRequest(action, data.get("target", ""), plan) + self.spec = OperatorRequest(action, plan=plan) except ValueError as error: raise forms.ValidationError(str(error)) from error return data -class OperatorToolsView(OperatorAuthorization, FormView): - form_class = OperatorToolForm - template_name = "hosting/operator_tools.html" - page = "services" +class ServerUpdatesView(OperatorAuthorization, FormView): + form_class = ServerUpdateForm + template_name = "hosting/server_updates.html" def preview(self): return ( @@ -104,20 +95,14 @@ class OperatorToolsView(OperatorAuthorization, FormView): ) def get_form_kwargs(self): - return super().get_form_kwargs() | { - "actions": TOOL_ACTIONS[self.page][1], - "preview": self.preview() if self.page == "packages" else None, - } + return super().get_form_kwargs() | {"preview": self.preview()} def get_context_data(self, **kwargs): - title, actions = TOOL_ACTIONS[self.page] return super().get_context_data( - title=title, - page=self.page, available=Path(SOCKET).is_socket(), - jobs=OperatorOperation.objects.filter(action__in=actions).order_by( - "-pk" - )[:20], + jobs=OperatorOperation.objects.filter( + action__in=ACTION_LABELS + ).order_by("-pk")[:20], **kwargs, ) @@ -145,18 +130,40 @@ class OperatorToolsView(OperatorAuthorization, FormView): "package update.", ) return self.form_invalid(form) - job = OperatorOperation.objects.create( - actor=self.request.user, - action=spec.action, - target=spec.target, - plan=spec.plan, + queue_operator_request( + self.request.user, + spec, source=form.preview if spec.action == "package-upgrade" else None, ) - transaction.on_commit(lambda: run_operator_operation.delay(job.pk)) messages.success(self.request, "Host operation queued.") return redirect(self.request.path) +def current_database_report(): + if connection.vendor != "mysql": + return None + try: + with connection.cursor() as cursor: + cursor.execute(DATABASE_VERSION_QUERY) + version = cursor.fetchone() + cursor.execute(DATABASE_COUNTERS_QUERY) + return database_report_from_rows([version, *cursor.fetchall()]) + except (DatabaseError, ValueError): + return None + + +@method_decorator(never_cache, name="dispatch") +class DatabaseMonitorView(OperatorAuthorization, TemplateView): + template_name = "hosting/database_monitor.html" + + def get_context_data(self, **kwargs): + return super().get_context_data( + report=current_database_report(), + observed_at=timezone.now(), + **kwargs, + ) + + class ConnectedNodesView(OperatorAuthorization, TemplateView): template_name = "hosting/connected_nodes.html" diff --git a/src/coulobre/hosting/templates/hosting/database_monitor.html b/src/coulobre/hosting/templates/hosting/database_monitor.html new file mode 100644 index 0000000..8f1c06a --- /dev/null +++ b/src/coulobre/hosting/templates/hosting/database_monitor.html @@ -0,0 +1,26 @@ +{% extends "hosting/workspace_page.html" %} +{% block title %}Database monitor · Coulobre Panel{% endblock %} +{% block page_title %}Database monitor{% endblock %} +{% block page_actions %} + Refresh status +{% endblock %} +{% block page_content %} +
+
+

MariaDB status

+ {% if report %}{% endif %} +
+ {% if report %} +
+
Status
Active
+
Version
{{ report.database_version }}
+
Current connections
{{ report.counters.Threads_connected|default:"Unavailable" }}
+
Slow queries
{{ report.counters.Slow_queries|default:"Unavailable" }}
+
Uptime (seconds)
{{ report.counters.Uptime|default:"Unavailable" }}
+
Slow query logging
{{ report.slow_logging|yesno:"Enabled,Disabled" }}
+
+ {% else %} +

MariaDB measurements are unavailable on this installation.

+ {% endif %} +
+{% endblock %} diff --git a/src/coulobre/hosting/templates/hosting/operator_operation_history.html b/src/coulobre/hosting/templates/hosting/operator_operation_history.html new file mode 100644 index 0000000..118c97f --- /dev/null +++ b/src/coulobre/hosting/templates/hosting/operator_operation_history.html @@ -0,0 +1,14 @@ +
+

Operation history

+ {% for job in jobs %} +
+ {{ job.requested_at|date:"j M Y H:i" }} UTC · {{ job.action|capfirst }}{% if job.target %} {{ job.target }}{% endif %} · {{ job.state|capfirst }} + {% if job.actor %}

Requested by {{ job.actor }}

{% endif %} + {% if job.problem %}

{{ job.problem }}

{% endif %} + {% if job.action == 'package-preview' and job.result.fingerprint %} +

{{ job.result.count }} package{{ job.result.count|pluralize }} ready to update.

+
    {% for package in job.result.packages %}
  • {{ package }}
  • {% endfor %}
+ {% endif %} +
+ {% empty %}

No operations yet.

{% endfor %} +
diff --git a/src/coulobre/hosting/templates/hosting/operator_tools.html b/src/coulobre/hosting/templates/hosting/operator_tools.html deleted file mode 100644 index bcc2316..0000000 --- a/src/coulobre/hosting/templates/hosting/operator_tools.html +++ /dev/null @@ -1,29 +0,0 @@ -{% extends "hosting/base.html" %} -{% block title %}{{ title }} · Coulobre Panel{% endblock %} -{% block content %} -

{{ title }}

-
- {% if page == 'packages' %}Coulobre updates - {% elif page == 'services' %}Service health{% endif %} -
- {% for message in messages %}

{{ message }}

{% endfor %} -
- {% if available %}
{% csrf_token %}{{ form.as_div }}
- {% else %}

Enable the operator service on the host to run these operations.

{% endif %} -
-
-

Operation history

- {% for job in jobs %} -
{{ job.requested_at|date:"j M Y H:i" }} · {{ job.action }}{% if job.target %} · {{ job.target }}{% endif %} · {{ job.state|capfirst }} - {% if job.problem %}

{{ job.problem }}

{% endif %} - {% if job.action == 'package-preview' and job.result.fingerprint %} -

{{ job.result.count }} package{{ job.result.count|pluralize }} ready to update.

-
    {% for package in job.result.packages %}
  • {{ package }}
  • {% endfor %}
- {% elif job.action == 'database-report' and job.result.database_version %} -

MariaDB {{ job.result.database_version }} · Slow query logging {{ job.result.slow_logging|yesno:"enabled,disabled" }}

-
{% for key, value in job.result.counters.items %}
{{ key }}
{{ value }}
{% endfor %}
- {% endif %} -
- {% empty %}

No operations yet.

{% endfor %} -
-{% endblock %} diff --git a/src/coulobre/hosting/templates/hosting/server_updates.html b/src/coulobre/hosting/templates/hosting/server_updates.html new file mode 100644 index 0000000..720e483 --- /dev/null +++ b/src/coulobre/hosting/templates/hosting/server_updates.html @@ -0,0 +1,33 @@ +{% extends "hosting/update_workspace.html" %} +{% block title %}Server package updates · Coulobre Panel{% endblock %} +{% block page_content %} +
+ {% if available %} +
+ {% csrf_token %} + +
+ {{ form.non_field_errors }} + {{ form.action.errors }} + {% if form.preview.result.count %} +
+ {% csrf_token %} + {{ form.preview_id }} + {{ form.preview_id.errors }} +
    + {% for package in form.preview.result.packages %}
  • {{ package }}
  • {% endfor %} +
+
+ + {{ form.confirm.errors }} +
+ +
+ {% else %} + {% if form.preview %}

No packages are ready to update.

{% endif %} + {{ form.preview_id.errors }} + {% endif %} + {% else %}

Enable the operator service on the host to review server updates.

{% endif %} +
+ {% include "hosting/operator_operation_history.html" %} +{% endblock %} diff --git a/src/coulobre/hosting/templates/hosting/service_health.html b/src/coulobre/hosting/templates/hosting/service_health.html index 80c9b42..0f2b2f5 100644 --- a/src/coulobre/hosting/templates/hosting/service_health.html +++ b/src/coulobre/hosting/templates/hosting/service_health.html @@ -1,11 +1,12 @@ -{% extends "hosting/base.html" %} +{% extends "hosting/workspace_page.html" %} -{% block title %}Service health · Coulobre Panel{% endblock %} +{% block title %}System Services · Coulobre Panel{% endblock %} +{% block page_title %}System Services{% endblock %} -{% block content %} -
-

Service health

-
+{% block page_content %} + {% if show_operation_history and not controls_available %} +

Enable the local operator worker to reload or restart services.

+ {% endif %} {% for node, services in nodes %}
@@ -20,15 +21,28 @@ Status Last check (UTC) Details + {% if controls_available and node.transport == 'local' %}Actions{% endif %} {% for service in services %} {{ service.name }} - {{ service.status }} - {% if service.observed_at %}{% else %}—{% endif %} - {{ service.detail }} + {{ service.status }} + {% if service.observed_at %}{% else %}—{% endif %} + {{ service.detail }} + {% if controls_available and node.transport == 'local' %} + + {% if service.control_target %} +
+ {% csrf_token %} + + + +
+ {% else %}—{% endif %} + + {% endif %} {% endfor %} @@ -40,4 +54,7 @@

Set COULOBRE_SERVICE_HEALTH in /etc/coulobre/panel.env and enable coulobre-health.timer to collect service observations.

{% endfor %} + {% if show_operation_history %} + {% include "hosting/operator_operation_history.html" %} + {% endif %} {% endblock %} diff --git a/src/coulobre/hosting/test_operator_workspaces.py b/src/coulobre/hosting/test_operator_workspaces.py index 9f5a5ac..22d44c6 100644 --- a/src/coulobre/hosting/test_operator_workspaces.py +++ b/src/coulobre/hosting/test_operator_workspaces.py @@ -12,7 +12,7 @@ from django_otp.plugins.otp_totp.models import TOTPDevice from coulobre.mail_queue import MailQueueAction, change_queue_entry from coulobre.operator_node import OperatorRequest, main, packages -from .models import PanelTheme +from .models import OperatorOperation, PanelTheme class OperatorRequestTests(SimpleTestCase): @@ -117,3 +117,32 @@ class ThemePreviewTests(TestCase): ) self.assertRedirects(self.client.post(url, {"action": "install"}), url) self.assertEqual(PanelTheme.objects.get().name, "Test theme") + + +class DatabaseMonitorTests(TestCase): + def test_verified_operator_sees_database_status_without_queueing_a_job( + self, + ): + operator = get_user_model().objects.create_superuser("operator") + self.client.force_login(operator) + url = reverse("panel:database_monitor") + self.assertEqual(self.client.get(url).status_code, 403) + device = TOTPDevice.objects.create(user=operator, name="test") + session = self.client.session + session["otp_device_id"] = device.persistent_id + session.save() + report = { + "database_version": "11.8.6-MariaDB", + "slow_logging": True, + "counters": {"Threads_connected": "3", "Slow_queries": "0"}, + } + with patch( + "coulobre.hosting.operator_tools.current_database_report", + return_value=report, + ): + response = self.client.get(url) + self.assertContains(response, "11.8.6-MariaDB") + self.assertContains(response, "Current connections") + self.assertContains(response, "Enabled") + self.assertFalse(OperatorOperation.objects.exists()) + self.assertIn("no-store", response["Cache-Control"]) diff --git a/src/coulobre/hosting/test_service_health.py b/src/coulobre/hosting/test_service_health.py index 0b6cfd6..4e9d5ca 100644 --- a/src/coulobre/hosting/test_service_health.py +++ b/src/coulobre/hosting/test_service_health.py @@ -10,6 +10,7 @@ from django.core.management import call_command from django.test import SimpleTestCase, TestCase, override_settings from django.urls import reverse from django.utils import timezone +from django_otp.plugins.otp_totp.models import TOTPDevice from coulobre.service_health import ( HealthResult, @@ -20,7 +21,13 @@ from coulobre.service_health import ( main, ) -from .models import Customer, DnsZoneDefaults, Reseller, ServiceHealth +from .models import ( + Customer, + DnsZoneDefaults, + OperatorOperation, + Reseller, + ServiceHealth, +) TARGETS = ( HealthTarget("panel-01", "local", ("mariadb", "apache")), @@ -165,6 +172,45 @@ class ServiceHealthPanelTests(TestCase): self.client.force_login(user) self.assertEqual(self.client.get(url).status_code, status) + def test_only_verified_admins_can_queue_configured_local_service_actions( + self, + ): + url = reverse("panel:service_health") + restart = {"action": "restart", "target": "apache"} + self.client.force_login(self.operator) + self.assertEqual(self.client.post(url, restart).status_code, 403) + self.client.force_login(self.admin) + self.assertEqual(self.client.post(url, restart).status_code, 403) + + device = TOTPDevice.objects.create(user=self.admin, name="test") + session = self.client.session + session["otp_device_id"] = device.persistent_id + session.save() + with ( + patch( + "coulobre.hosting.health_views.Path.is_socket", + return_value=True, + ), + patch( + "coulobre.hosting.operator_tools.run_operator_operation.delay" + ) as delay, + ): + response = self.client.get(url) + self.assertContains(response, 'aria-label="Restart Apache"') + self.assertContains(response, 'aria-label="Reload Apache"') + self.assertNotContains(response, 'aria-label="Restart Postfix"') + remote = {"action": "restart", "target": "smtp"} + self.assertEqual(self.client.post(url, remote).status_code, 400) + self.assertFalse(OperatorOperation.objects.exists()) + with self.captureOnCommitCallbacks(execute=True): + self.assertRedirects(self.client.post(url, restart), url) + job = OperatorOperation.objects.get() + self.assertEqual( + (job.action, job.target, job.actor), + ("restart", "apache", self.admin), + ) + delay.assert_called_once_with(job.pk) + @override_settings( LOCAL_DNS_PUBLISHING=True, HOSTING_NAMESERVERS=("ns.example.net",), diff --git a/src/coulobre/hosting/urls.py b/src/coulobre/hosting/urls.py index ddca1f4..8233149 100644 --- a/src/coulobre/hosting/urls.py +++ b/src/coulobre/hosting/urls.py @@ -54,8 +54,9 @@ from .mail_queue_views import MailQueueIndex, MailQueueView, mail_queue_action from .operator_backups import OperatorBackupsView from .operator_tools import ( ConnectedNodesView, + DatabaseMonitorView, HttpDefaultsView, - OperatorToolsView, + ServerUpdatesView, ) from .panel_content import ( AnnouncementView, @@ -190,17 +191,17 @@ urlpatterns = [ ), path( "service-health/actions/", - OperatorToolsView.as_view(page="services"), + ServiceHealthView.as_view(), name="operator_service_actions", ), path( "updates/server-packages/", - OperatorToolsView.as_view(page="packages"), + ServerUpdatesView.as_view(), name="server_updates", ), path( "server/database/", - OperatorToolsView.as_view(page="database"), + DatabaseMonitorView.as_view(), name="database_monitor", ), path("themes/", ThemeManagementView.as_view(), name="theme_management"), diff --git a/src/coulobre/hosting/workspaces.py b/src/coulobre/hosting/workspaces.py index 122fb39..4d71a35 100644 --- a/src/coulobre/hosting/workspaces.py +++ b/src/coulobre/hosting/workspaces.py @@ -71,6 +71,7 @@ WORKSPACE_PARENT_ROUTES = { "operator_settings": ("operator_settings", ("general",)), "http_defaults": ("http_defaults", ("apache",)), "server_updates": ("updates", ()), + "operator_service_actions": ("service_health", ()), "mail_queue": ("mail_queue_index", ()), "reseller": ("resellers", ()), "reseller_edit": ("resellers", ()), @@ -412,12 +413,7 @@ def groups_for(request, *, customer, manager): ) if user.is_superuser: server.append(link("connected_nodes", "Connected Nodes")) - admin_tools.extend( - ( - link("operator_service_actions", "Service actions"), - link("database_monitor", "DB Monitor"), - ) - ) + admin_tools.append(link("database_monitor", "DB Monitor")) groups = [ ("Account Manager", accounts), ("Server Manager", server), diff --git a/src/coulobre/operator_node.py b/src/coulobre/operator_node.py index 3599ff9..5354d20 100644 --- a/src/coulobre/operator_node.py +++ b/src/coulobre/operator_node.py @@ -27,6 +27,11 @@ ACTIONS = ( "server-tls", ) APT = "/usr/bin/apt-get" +DATABASE_VERSION_QUERY = "SELECT @@version, @@slow_query_log" +DATABASE_COUNTERS_QUERY = ( + "SHOW GLOBAL STATUS WHERE " + "Variable_name IN ('Threads_connected','Slow_queries','Uptime')" +) @dataclass(frozen=True) @@ -142,26 +147,29 @@ def packages(request): def database_report(): - query = ( - "SELECT @@version, @@slow_query_log; SHOW GLOBAL STATUS WHERE " - "Variable_name IN ('Threads_connected','Slow_queries','Uptime');" - ) output = command( "/usr/bin/mariadb", "--batch", "--skip-column-names", "--protocol=socket", "--execute", - query, + f"{DATABASE_VERSION_QUERY}; {DATABASE_COUNTERS_QUERY};", ) - rows = [row.split("\t") for row in output.splitlines()] - if not rows or any(len(row) != 2 for row in rows): + return database_report_from_rows( + [row.split("\t") for row in output.splitlines()] + ) + + +def database_report_from_rows(rows): + if not rows or any(row is None or len(row) != 2 for row in rows): raise ValueError("MariaDB returned an invalid status report.") version, slow_log = rows[0] - counters = {key: value for key, value in rows[1:] if value.isdecimal()} + counters = { + key: str(value) for key, value in rows[1:] if str(value).isdecimal() + } return { "database_version": version[:80], - "slow_logging": slow_log == "1", + "slow_logging": str(slow_log).upper() in {"1", "ON"}, "counters": counters, }