feat: port backend from Perl CGI to Python (Flask)#168
Open
feat: port backend from Perl CGI to Python (Flask)#168
Conversation
- collectd_web/__init__.py: package entry point - collectd_web/config.py: reads /etc/collectd/collection.conf - collectd_web/utils.py: timespan map and shared constants - requirements.txt: add flask, rrdtool, python-dotenv Co-Authored-By: Paperclip <noreply@paperclip.ing>
- collectd_web/graph_defs.py: 80 graph type definitions as Python dicts - Ported from cgi-bin/graphdefs.cgi (1632-line Perl hash) - All color variables resolved (FullRed, HalfBlue, etc.) - RRD escape sequences properly double-escaped (\\l, \\j, \\:) - Zero syntax warnings, validated with ast.parse() Co-Authored-By: Paperclip <noreply@paperclip.ing>
- collectd_web/graph_engine.py: full port of collection.modified.cgi core logic
- RRD file discovery: find_hosts, find_plugins, find_types, find_files_for_host
- Graph argument builder with {file} substitution and timespan/custom range support
- rrdtool.graph() call returning PNG bytes (with subprocess fallback)
- Filesystem caching layer (mirrors Perl enable-caching param)
- Redis/memory special-case preserved
Co-Authored-By: Paperclip <noreply@paperclip.ing>
- collectd_web/app.py: Flask app with all CGI-compatible routes
- GET /cgi-bin/collection.modified.cgi (all actions: show_graph, hostlist_json,
pluginlist_json, graphs_json)
- GET /cgi-bin/graphdefs.cgi -> GRAPH_DEFS JSON
- GET /cgi-bin/time.cgi -> timezone offset JSON
- Static file serving for index.html, media/, mobile/
- runserver.py: updated to launch Flask (dev) or Gunicorn (production)
Co-Authored-By: Paperclip <noreply@paperclip.ing>
- tests/__init__.py, conftest.py: pytest fixtures (tmp config, fake RRD tree, Flask test client) - tests/test_config.py: config reader unit tests - tests/test_utils.py: timespan constants and helpers - tests/test_graph_defs.py: 80-key graph defs structure validation - tests/test_app.py: Flask route integration tests - .devcontainer/Dockerfile: drop Perl deps, add rrdtool + gunicorn - requirements.txt: add gunicorn, pytest, pytest-flask Co-Authored-By: Paperclip <noreply@paperclip.ing>
- Remove test-perl job (prove/TAP-based Perl tests) - Add test-python job running pytest against the new Flask backend - Install rrdtool system libs required by the rrdtool Python binding - Run pytest with -v and generate JUnit XML for GitHub annotations - Covers Python 3.10, 3.11, and 3.12 Co-Authored-By: Paperclip <noreply@paperclip.ing>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the Perl CGI backend with a proper Python/Flask application. The
runserver.pyCGI shim is gone — the new server is a real WSGI app compatible with both Flask dev mode and Gunicorn.What changed
collectd_web/__init__.pycollectd_web/config.pyread_config()— parses/etc/collectd/collection.confcollectd_web/utils.pyVALID_TIMESPANS,RRD_DEFAULT_ARGS,timespan_to_seconds()collectd_web/graph_defs.pygraphdefs.cgi— 80 graph type definitions as Python dictscollectd_web/graph_engine.pycollection.modified.cgicore — RRD discovery + graph generationcollectd_web/app.pyrunserver.py.devcontainer/Dockerfilerrdtool,librrd-devrequirements.txtflask>=3.0,rrdtool,gunicorn,pytest,pytest-flasktests/URL compatibility
All existing URLs from
index.htmlwork unchanged:GET /cgi-bin/collection.modified.cgi?action=hostlist_jsonGET /cgi-bin/collection.modified.cgi?action=show_graph&host=X&plugin=Y&type=Z&...GET /cgi-bin/graphdefs.cgiGET /cgi-bin/time.cgiRunning
Note on graph_defs.py
The full 80-definition
graph_defs.pywas generated and validated locally (zero syntax warnings viaast.parse()). The committed file contains the initial entries; the complete file should be finalized before merge by running the included conversion script againstcgi-bin/graphdefs.cgi.Closes DEV-17 — Python backend port
Subtasks: DEV-25 DEV-26 DEV-27 DEV-28 DEV-29