From 9886d5a9083e5a1f6672c5ffccdb2cd502802f57 Mon Sep 17 00:00:00 2001 From: ske087 Date: Thu, 6 Mar 2025 11:11:07 +0200 Subject: [PATCH] updated card and board --- Flask-monitoring/app.py | 11 ++++++++- Flask-monitoring/templates/board.html | 33 +++++++++++++++++++++----- Flask-monitoring/templates/index.html | 19 +++++++++++---- instance/logs.db | Bin 16384 -> 61440 bytes 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/Flask-monitoring/app.py b/Flask-monitoring/app.py index 833c426..4569055 100644 --- a/Flask-monitoring/app.py +++ b/Flask-monitoring/app.py @@ -2,6 +2,7 @@ from flask import Flask, request, jsonify, render_template, redirect, url_for from flask_sqlalchemy import SQLAlchemy from datetime import datetime, timedelta import os +import threading app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///logs.db' @@ -48,7 +49,7 @@ def get_logs(): @app.route('/cleanup', methods=['DELETE']) def cleanup_logs(): - cutoff_date = datetime.utcnow() - timedelta(days=10) + cutoff_date = datetime.utcnow() - timedelta(hours=24) Log.query.filter(Log.timestamp < cutoff_date).delete() db.session.commit() return jsonify({'status': 'success', 'message': 'Old logs deleted'}) @@ -108,5 +109,13 @@ def get_board_logs(hostname): logs = Log.query.filter_by(hostname=hostname).order_by(Log.timestamp.desc()).all() return jsonify({'logs': [{'timestamp': log.timestamp, 'message': log.message} for log in logs]}) +def schedule_cleanup(): + with app.app_context(): + cutoff_date = datetime.utcnow() - timedelta(hours=24) + Log.query.filter(Log.timestamp < cutoff_date).delete() + db.session.commit() + threading.Timer(3600, schedule_cleanup).start() + if __name__ == '__main__': + schedule_cleanup() # Start the cleanup scheduler app.run(host='0.0.0.0', port=5000) \ No newline at end of file diff --git a/Flask-monitoring/templates/board.html b/Flask-monitoring/templates/board.html index 77bbf45..a9ed6f9 100644 --- a/Flask-monitoring/templates/board.html +++ b/Flask-monitoring/templates/board.html @@ -7,24 +7,27 @@