From 58205be555f3863f5fb1a8eaded84503a80d641c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Mon, 3 Nov 2025 10:32:38 +0100 Subject: [PATCH] new options --- app.py | 24 +++++++++++++++++++++--- static/js/logs.js | 2 ++ templates/index.html | 10 +++++++++- templates/logs.html | 44 +++++++++++++++++++++++++++++++++++++++----- 4 files changed, 71 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index feac89d..3538ed0 100644 --- a/app.py +++ b/app.py @@ -100,11 +100,29 @@ def display_haproxy_stats(): parsed_stats = parse_haproxy_stats(haproxy_stats) return render_template('statistics.html', stats=parsed_stats) + @app.route('/logs') -def display_logs(): +@requires_auth +def display_haproxy_logs(): log_file_path = '/var/log/haproxy.log' - parsed_entries = parse_log_file(log_file_path) - return render_template('logs.html', entries=parsed_entries) + + if not os.path.exists(log_file_path): + return render_template('logs.html', + logs=[], + error_message=f"Log file not found: {log_file_path}") + + try: + logs = parse_log_file(log_file_path) + if not logs: + return render_template('logs.html', + logs=[], + error_message="Log file is empty or unreadable") + return render_template('logs.html', logs=logs) + except Exception as e: + return render_template('logs.html', + logs=[], + error_message=f"Error parsing logs: {str(e)}") + @app.route('/home') def home(): diff --git a/static/js/logs.js b/static/js/logs.js index 23045ec..15619f6 100644 --- a/static/js/logs.js +++ b/static/js/logs.js @@ -6,6 +6,8 @@ document.addEventListener('DOMContentLoaded', function() { const resetBtn = document.getElementById('reset_filters'); const logsTable = document.getElementById('logs_table'); + if (!logsTable) return; // Exit if no logs + const allRows = Array.from(document.querySelectorAll('.log-row')); // Filter function diff --git a/templates/index.html b/templates/index.html index 6fdd959..41454d2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,7 +4,15 @@ {% block title %}HAProxy • Configuration{% endblock %} -{% block breadcrumb %}Configuration{% endblock %} +{% block breadcrumb %} + +{% endblock %} + {% block content %} diff --git a/templates/logs.html b/templates/logs.html index 8c1b1f2..3ffb1dc 100644 --- a/templates/logs.html +++ b/templates/logs.html @@ -4,17 +4,34 @@ {% block title %}HAProxy • Logs{% endblock %} -{% block breadcrumb %}Logs{% endblock %} +{% block breadcrumb %} + +{% endblock %} {% block content %}
-
+
HAProxy Access Logs
- {% if logs %} + + {% if error_message %} + + {% endif %} + + + {% if logs and logs|length > 0 %}
@@ -161,9 +178,25 @@
- {% else %} + {% elif logs %} +
- No log entries found. + No log entries match your filters. +
+ {% else %} + + {% endif %} @@ -171,4 +204,5 @@
+ {% endblock %}