1
0
Fork 0

Introduce embedded HTTP server for HAProxy monitoring dashboard

- Added a Python-based HTTP server to serve `dashboard.html` at `/` or `/dashboard.html` paths.
- Updated HAProxy configuration to integrate backend for the dashboard.
- Enhanced handling of index paths with conditional redirects to the dashboard page.
- Modified tests and updated expected outputs to reflect these changes.
This commit is contained in:
Joao Gilberto Magalhaes 2026-02-22 19:42:51 -05:00
parent 67cfcf3aff
commit 7e3134155a
16 changed files with 153 additions and 70 deletions

View file

@ -6,13 +6,12 @@ This module provides session-wide and function-level fixtures for testing.
import os
import shutil
import tempfile
import pytest
# Create a session-wide temporary directory for all tests
# Use a different prefix to avoid conflicts with cleanup plugin (which looks for "easyhaproxy_*")
_test_session_dir = tempfile.mkdtemp(prefix="pytest_easyhaproxy_")
# Fixed temporary directory for all tests — predictable so expected fixtures can reference it
_test_session_dir = "/tmp/easyhaproxy_test"
os.makedirs(_test_session_dir, exist_ok=True)
os.environ["EASYHAPROXY_BASE_PATH"] = _test_session_dir

View file

@ -42,8 +42,14 @@ frontend dashboard
mode http
acl is_index path /
acl is_index path /index.html
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
http-request return status 404
acl is_dashboard path /dashboard.html
http-request set-path /dashboard.html if is_index
http-request return status 404 if !is_dashboard
default_backend srv_dashboard
backend srv_dashboard
mode http
server Local 127.0.0.1:9190
frontend http_in_443
bind *:443 ssl crt /etc/easyhaproxy/certs/certbot/ alpn h2,http/1.1 crt /etc/easyhaproxy/certs/haproxy/ alpn h2,http/1.1

View file

@ -50,8 +50,14 @@ frontend dashboard
mode http
acl is_index path /
acl is_index path /index.html
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
http-request return status 404
acl is_dashboard path /dashboard.html
http-request set-path /dashboard.html if is_index
http-request return status 404 if !is_dashboard
default_backend srv_dashboard
backend srv_dashboard
mode http
server Local 127.0.0.1:9190
frontend http_in_80
bind *:80

View file

@ -50,8 +50,14 @@ frontend dashboard
mode http
acl is_index path /
acl is_index path /index.html
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
http-request return status 404
acl is_dashboard path /dashboard.html
http-request set-path /dashboard.html if is_index
http-request return status 404 if !is_dashboard
default_backend srv_dashboard
backend srv_dashboard
mode http
server Local 127.0.0.1:9190
frontend http_in_19901
bind *:19901

View file

@ -40,8 +40,14 @@ frontend dashboard
mode http
acl is_index path /
acl is_index path /index.html
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
http-request return status 404
acl is_dashboard path /dashboard.html
http-request set-path /dashboard.html if is_index
http-request return status 404 if !is_dashboard
default_backend srv_dashboard
backend srv_dashboard
mode http
server Local 127.0.0.1:9190
backend certbot_backend
mode http

View file

@ -57,8 +57,14 @@ frontend dashboard
mode http
acl is_index path /
acl is_index path /index.html
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
http-request return status 404
acl is_dashboard path /dashboard.html
http-request set-path /dashboard.html if is_index
http-request return status 404 if !is_dashboard
default_backend srv_dashboard
backend srv_dashboard
mode http
server Local 127.0.0.1:9190
frontend http_in_80
bind *:80

View file

@ -50,8 +50,14 @@ frontend dashboard
mode http
acl is_index path /
acl is_index path /index.html
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
http-request return status 404
acl is_dashboard path /dashboard.html
http-request set-path /dashboard.html if is_index
http-request return status 404 if !is_dashboard
default_backend srv_dashboard
backend srv_dashboard
mode http
server Local 127.0.0.1:9190
frontend http_in_443
bind *:443 ssl crt /etc/easyhaproxy/certs/certbot/ alpn h2,http/1.1 crt /etc/easyhaproxy/certs/haproxy/ alpn h2,http/1.1

View file

@ -948,7 +948,7 @@ class TestFastcgiPlugin:
assert plugin.name == "fastcgi"
assert plugin.enabled is True
assert plugin.document_root == f"{Consts.base_path}/www"
assert plugin.document_root == "/var/www/html"
assert plugin.index_file == "index.php"
assert plugin.path_info is True
assert plugin.custom_params == {}
@ -970,7 +970,7 @@ class TestFastcgiPlugin:
"""Test plugin generates correct HAProxy config"""
plugin = FastcgiPlugin()
plugin.configure({
"document_root": f"{Consts.base_path}/www",
"document_root": "/var/www/html",
"index_file": "index.php"
})
@ -992,9 +992,9 @@ class TestFastcgiPlugin:
assert len(result.global_configs) == 1
fcgi_app_def = result.global_configs[0]
assert "fcgi-app fcgi_phpapp_local" in fcgi_app_def
assert f"docroot {Consts.base_path}/www" in fcgi_app_def
assert "docroot /var/www/html" in fcgi_app_def
assert "index index.php" in fcgi_app_def
assert result.metadata["document_root"] == f"{Consts.base_path}/www"
assert result.metadata["document_root"] == "/var/www/html"
assert result.metadata["index_file"] == "index.php"
def test_fastcgi_plugin_custom_params(self):