diff --git a/app/visualiseur_logs.py b/app/visualiseur_logs.py new file mode 100644 index 0000000..e65aaf4 --- /dev/null +++ b/app/visualiseur_logs.py @@ -0,0 +1,53 @@ +import streamlit as st +import os +import platform + +# 🟢 CECI DOIT ÊTRE LA PREMIÈRE COMMANDE STREAMLIT ! +st.set_page_config(page_title="Visualiseur de Logs", layout="wide") + +# 🔧 Détection du bon dossier selon l'OS +if platform.system() == "Windows": + LOG_DIR = "C:/Users/miche/PycharmProjects/Gestion_sondes/Logs" +else: + LOG_DIR = "/home/debian/Gestion_sondes/Logs" + +# Titre +st.title("🧾 Visualiseur de fichiers logs") + +# Liste des fichiers .log ou similaires +try: + fichiers = sorted( + [f for f in os.listdir(LOG_DIR) if ".log" in f], + key=lambda x: os.path.getmtime(os.path.join(LOG_DIR, x)), + reverse=True + ) +except FileNotFoundError: + st.error(f"📁 Dossier introuvable : {LOG_DIR}") + st.stop() + +if not fichiers: + st.warning("Aucun fichier log trouvé dans le dossier.") + st.stop() + +# Choix du fichier +choix = st.selectbox("📂 Sélectionnez un fichier log :", fichiers) +log_path = os.path.join(LOG_DIR, choix) + +# Options d'affichage +col1, col2 = st.columns([1, 1]) +with col1: + filtre_erreurs = st.checkbox("🔍 Afficher uniquement les erreurs", value=False) +with col2: + nb_lignes = st.slider("📏 Nombre de lignes à afficher", 10, 5000, 300) + +# Lecture du fichier +with open(log_path, "r", encoding="utf-8", errors="ignore") as f: + lignes = f.readlines() + +if filtre_erreurs: + mots_cles = ["ERROR", "❌", "Traceback", "failed", "exception"] + lignes = [l for l in lignes if any(m in l.lower() for m in mots_cles)] + +# Affichage +dernieres = lignes[-nb_lignes:] +st.text_area("📄 Contenu du fichier log :", "".join(dernieres), height=600) diff --git a/scripts/backup_mysql.sh b/scripts/backup_mysql.sh index 7c91ecb..2db3701 100644 --- a/scripts/backup_mysql.sh +++ b/scripts/backup_mysql.sh @@ -3,6 +3,9 @@ # Variables DATE=$(date +'%Y-%m-%d_%H-%M') BACKUP_DIR="/home/debian/backup" +LOG_DIR="/home/debian/Gestion_sondes/Logs" +LOG_FILE="$LOG_DIR/backup_$DATE.log" +exec > "$LOG_FILE" 2>&1 BACKUP_FILE="$BACKUP_DIR/mysql_backup_$DATE.sql" NAS_HOST="mon-nas" # défini dans /home/debian/.ssh/config MYSQL_USER="root"