From 35cb6808ebcd1228e3deac70fdbd6a10c0652fb2 Mon Sep 17 00:00:00 2001 From: sky Date: Fri, 12 Sep 2025 22:37:25 +0200 Subject: [PATCH 01/21] heatcheck --- Dockerfile | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index e40c22d..5b37227 100755 --- a/Dockerfile +++ b/Dockerfile @@ -7,21 +7,20 @@ ENV LANG=fr_FR.UTF-8 ENV LC_ALL=fr_FR.UTF-8 RUN apt-get update && apt-get install -y --no-install-recommends \ - apt-utils \ locales \ python3 \ python3-pip \ - python3-venv \ - wget \ - && wget https://repo.zabbix.com/zabbix/7.4/release/debian/pool/main/z/zabbix-release/zabbix-release_latest_7.4+debian12_all.deb \ - && dpkg -i zabbix-release_latest_7.4+debian12_all.deb \ - && apt-get update \ - && apt-get install -y --no-install-recommends zabbix-agent2 \ - && sed -i 's/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen \ - && locale-gen \ - && rm -rf /var/lib/apt/lists/* \ - && rm zabbix-release_latest_7.4+debian12_all.deb + python3-venv + +RUN wget https://repo.zabbix.com/zabbix/7.4/release/debian/pool/main/z/zabbix-release/zabbix-release_latest_7.4+debian13_all.deb; \ + dpkg -i zabbix-release*; \ + apt-get update; \ + apt-get install -y --no-install-recommends zabbix-agent2; \ + sed -i 's/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen; \ + locale-gen; \ + rm -rf /var/lib/apt/lists/* *.deb + COPY requirements.txt . COPY run-web.py . COPY ./database ./database @@ -36,4 +35,6 @@ RUN python3 -m venv /app/venv && \ /app/venv/bin/pip install --no-cache-dir -r requirements.txt && \ chmod +x /start.sh -CMD ["/start.sh"] \ No newline at end of file +HEALTHCHECK --interval=5m --timeout=1m --start-period=2m CMD /app/venv/bin/python /app/healthcheck.py --show-success --config-dir /app/config/ --hook-dir /app/config/healthcheck/ + +CMD ["/start.sh"] From 906af642ffd3dcb14a91a97f6a60c1dda8a4251e Mon Sep 17 00:00:00 2001 From: sky Date: Fri, 12 Sep 2025 22:38:20 +0200 Subject: [PATCH 02/21] unless-stopped --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index cd5b762..55f155a 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ services: mamiehenriette: container_name: MamieHenriette # Nom du conteneur image: ghcr.io/skylanix/mamiehenriette:latest # Image hébergée sur GitHub Container Registry - restart: "no" # N'autorise pas le redémarrage automatique + restart: unless-stopped # Redémarre automatiquement sauf si arrêté manuellement # build: . # Build du conteneur à partir d'un Dockerfile local (décommentez si nécessaire) # image: mamiehenriette # Build du conteneur à partir d'un Dockerfile local (décommentez si nécessaire) From 52f9950685f942ce0fc1d4c23221e203509d7d84 Mon Sep 17 00:00:00 2001 From: sky Date: Sat, 13 Sep 2025 00:26:02 +0200 Subject: [PATCH 03/21] ajout healthcheck.py --- Dockerfile | 3 ++- healthcheck.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 healthcheck.py diff --git a/Dockerfile b/Dockerfile index 5b37227..3f77c79 100755 --- a/Dockerfile +++ b/Dockerfile @@ -30,11 +30,12 @@ COPY ./webapp ./webapp COPY ./twitchbot ./twitchbot COPY zabbix_agent2.conf /etc/zabbix/zabbix_agent2.conf COPY start.sh /start.sh +COPY healthcheck.py . RUN python3 -m venv /app/venv && \ /app/venv/bin/pip install --no-cache-dir -r requirements.txt && \ chmod +x /start.sh -HEALTHCHECK --interval=5m --timeout=1m --start-period=2m CMD /app/venv/bin/python /app/healthcheck.py --show-success --config-dir /app/config/ --hook-dir /app/config/healthcheck/ +HEALTHCHECK --interval=30s --timeout=10s --start-period=2m CMD /app/venv/bin/python /app/healthcheck.py CMD ["/start.sh"] diff --git a/healthcheck.py b/healthcheck.py new file mode 100755 index 0000000..5ffd15b --- /dev/null +++ b/healthcheck.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import subprocess +import sys +import os + +def check_process(): + """Vérifie si le processus Python principal est en cours d'exécution""" + try: + # Vérifier si le processus run-web.py est actif + result = subprocess.run( + ["pgrep", "-f", "run-web.py"], + capture_output=True, + text=True + ) + return result.returncode == 0 + except Exception: + return False + +def main(): + if check_process(): + sys.exit(0) # Succès + else: + sys.exit(1) # Échec + +if __name__ == "__main__": + main() \ No newline at end of file From 5481904136ffc61cd1f1551084eaec9fb2a3b582 Mon Sep 17 00:00:00 2001 From: sky Date: Sat, 13 Sep 2025 16:04:22 +0200 Subject: [PATCH 04/21] =?UTF-8?q?ajout=20de=20sqlite-web=20-=20Interface?= =?UTF-8?q?=20web=20pour=20l'=C3=A9dition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 55f155a..c98e3fc 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,3 +39,13 @@ services: # WATCHTOWER_NOTIFICATIONS: shoutrrr # Service de notification utilisé pour Discord (décommentez si nécessaire) volumes: - /var/run/docker.sock:/var/run/docker.sock # Monte le socket Docker pour permettre à Watchtower de surveiller les conteneurs + +# sqlite-web: # Interface web pour visualiser et éditer la base de données SQLite +# image: ghcr.io/coleifer/sqlite-web:latest # Image officielle sqlite-web +# container_name: sqlite_web # Nom du conteneur +# ports: +# - "5001:8080" # Accès web via localhost:8080 +# volumes: +# - ./instance/database.db:/data/database.db # Monte la base de données locale dans le conteneur +# environment: +# - SQLITE_DATABASE=/data/database.db # Chemin vers la base de données dans le conteneur From 9b11a42d11e8d89317e4728f4c97afe13820b344 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 02:28:53 +0200 Subject: [PATCH 05/21] [pgrep, python] --- healthcheck.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/healthcheck.py b/healthcheck.py index 5ffd15b..16ae63d 100755 --- a/healthcheck.py +++ b/healthcheck.py @@ -7,9 +7,9 @@ import os def check_process(): """Vérifie si le processus Python principal est en cours d'exécution""" try: - # Vérifier si le processus run-web.py est actif + # Vérifier si un processus python est actif result = subprocess.run( - ["pgrep", "-f", "run-web.py"], + ["pgrep", "python"], capture_output=True, text=True ) From 3cd3decca1e21059ea50404d9f539aadc5529816 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 02:38:35 +0200 Subject: [PATCH 06/21] =?UTF-8?q?healthcheck=20mis=20dans=20le=20Dockerfil?= =?UTF-8?q?e=20=C3=A0=20la=20place=20d'un=20scripte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 ++-- healthcheck.py | 27 --------------------------- 2 files changed, 2 insertions(+), 29 deletions(-) delete mode 100755 healthcheck.py diff --git a/Dockerfile b/Dockerfile index 3f77c79..5acb543 100755 --- a/Dockerfile +++ b/Dockerfile @@ -30,12 +30,12 @@ COPY ./webapp ./webapp COPY ./twitchbot ./twitchbot COPY zabbix_agent2.conf /etc/zabbix/zabbix_agent2.conf COPY start.sh /start.sh -COPY healthcheck.py . RUN python3 -m venv /app/venv && \ /app/venv/bin/pip install --no-cache-dir -r requirements.txt && \ chmod +x /start.sh -HEALTHCHECK --interval=30s --timeout=10s --start-period=2m CMD /app/venv/bin/python /app/healthcheck.py +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD pgrep python > /dev/null || exit 1 CMD ["/start.sh"] diff --git a/healthcheck.py b/healthcheck.py deleted file mode 100755 index 16ae63d..0000000 --- a/healthcheck.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 - -import subprocess -import sys -import os - -def check_process(): - """Vérifie si le processus Python principal est en cours d'exécution""" - try: - # Vérifier si un processus python est actif - result = subprocess.run( - ["pgrep", "python"], - capture_output=True, - text=True - ) - return result.returncode == 0 - except Exception: - return False - -def main(): - if check_process(): - sys.exit(0) # Succès - else: - sys.exit(1) # Échec - -if __name__ == "__main__": - main() \ No newline at end of file From d83c88230371d39b337ab275ae7efe5bf4143fef Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 02:44:57 +0200 Subject: [PATCH 07/21] ajout de pgrep dans le Dockerfile --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5acb543..83c680d 100755 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ locales \ python3 \ python3-pip \ - python3-venv + python3-venv \ + procps RUN wget https://repo.zabbix.com/zabbix/7.4/release/debian/pool/main/z/zabbix-release/zabbix-release_latest_7.4+debian13_all.deb; \ dpkg -i zabbix-release*; \ From 3435a480e0bcc353b8e5165178224b148a5ce315 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 03:22:11 +0200 Subject: [PATCH 08/21] =?UTF-8?q?Refactorer=20Docker=20et=20mettre=20?= =?UTF-8?q?=C3=A0=20jour=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 17 +++++----- README.md | 78 +++++++++++++++++++++++++++++----------------- docker-compose.yml | 5 +-- start.sh | 19 +---------- 4 files changed, 58 insertions(+), 61 deletions(-) diff --git a/Dockerfile b/Dockerfile index 83c680d..b6b010c 100755 --- a/Dockerfile +++ b/Dockerfile @@ -12,15 +12,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ python3 \ python3-pip \ python3-venv \ - procps + procps \ + apache2-utils -RUN wget https://repo.zabbix.com/zabbix/7.4/release/debian/pool/main/z/zabbix-release/zabbix-release_latest_7.4+debian13_all.deb; \ - dpkg -i zabbix-release*; \ - apt-get update; \ - apt-get install -y --no-install-recommends zabbix-agent2; \ - sed -i 's/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen; \ +RUN sed -i 's/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen; \ locale-gen; \ - rm -rf /var/lib/apt/lists/* *.deb + rm -rf /var/lib/apt/lists/* COPY requirements.txt . COPY run-web.py . @@ -29,14 +26,14 @@ COPY ./discordbot ./discordbot COPY ./protondb ./protondb COPY ./webapp ./webapp COPY ./twitchbot ./twitchbot -COPY zabbix_agent2.conf /etc/zabbix/zabbix_agent2.conf COPY start.sh /start.sh RUN python3 -m venv /app/venv && \ /app/venv/bin/pip install --no-cache-dir -r requirements.txt && \ - chmod +x /start.sh + chmod +x /start.sh && \ + mkdir -p /app/logs HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD pgrep python > /dev/null || exit 1 + CMD pgrep python > /dev/null && ! (find /app/logs -name "app.log.*" -exec tail -n 20 {} \; 2>/dev/null | grep -E "ERROR|CRITICAL|Exception") || exit 1 CMD ["/start.sh"] diff --git a/README.md b/README.md index 82aa1a4..48e240b 100755 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ - [Twitch](#twitch) - [YouTube Live](#youtube-live-en-développement) - [Interface d'administration](#interface-dadministration) - - [Surveillance](#surveillance) - [Installation](#installation) - [Prérequis](#prérequis) - [Création du bot Discord](#création-du-bot-discord) - [Démarrage rapide](#démarrage-rapide) + - [Volumes persistants](#volumes-persistants) - [Commandes Docker utiles](#commandes-docker-utiles) - [Mise à jour](#mise-à-jour) - [Architecture du projet](#architecture-du-projet) @@ -24,6 +24,7 @@ - [Spécifications techniques](#spécifications-techniques) - [Base de données (SQLite)](#base-de-données-sqlite) - [Architecture multi-thread](#architecture-multi-thread) + - [Monitoring et logging](#monitoring-et-logging) - [Dépendances principales](#dépendances-principales) - [Développement](#développement) - [Installation locale](#installation-locale) @@ -42,7 +43,6 @@ Mamie Henriette est un bot intelligent open-source développé spécifiquement p - Gestion multi-plateformes (Discord opérationnel, Twitch intégré, YouTube Live en développement) - Système de notifications automatiques - Base de données intégrée pour la persistance -- Surveillance optionnelle avec Zabbix *(non testée)* ## Fonctionnalités @@ -55,6 +55,11 @@ Mamie Henriette est un bot intelligent open-source développé spécifiquement p ### Twitch - **Chat bot** : Commandes et interactions automatiques +- **Alertes Live** : Surveillance automatique des streamers (vérification toutes les 5 minutes) + - Support jusqu'à 100 chaînes simultanément + - Notifications Discord avec aperçu du stream + - Gestion via interface d'administration + - Détection automatique des débuts/fins de stream ### YouTube Live *(en développement)* - **Chat bot** : Modération et commandes @@ -67,9 +72,6 @@ Mamie Henriette est un bot intelligent open-source développé spécifiquement p - **Commandes** : Édition des commandes personnalisées - **Modération** : Outils de gestion communautaire -### Surveillance -- **Zabbix Agent 2** : Monitoring avancé *(non testé)* -- **Métriques** : Santé du bot et uptime ## Installation @@ -129,6 +131,10 @@ docker compose up --build -d > docker compose restart MamieHenriette > ``` +### Volumes persistants +- `./instance/` : Base de données SQLite et configuration +- `./logs/` : Logs applicatifs rotatifs (50MB max par fichier) + ### Commandes Docker utiles ```bash @@ -190,9 +196,10 @@ python run-web.py | Section | Fonction | |---------|----------| | **Configurations** | Tokens Discord/Twitch, paramètres généraux et configuration ProtonDB | -| **Humeurs** | Gestion des statuts Discord | -| **Commandes** | Commandes personnalisées multi-plateformes | -| **Messages** | Messages automatiques et notifications | +| **Humeurs** | Gestion des statuts Discord rotatifs | +| **Commandes** | Commandes personnalisées multi-plateformes (Discord/Twitch) | +| **Alertes Live** | Configuration surveillance streamers Twitch avec notifications Discord | +| **Messages** | Messages automatiques et notifications périodiques | | **Modération** | Outils de gestion communautaire | ### Structure des modules @@ -204,18 +211,22 @@ python run-web.py │ └── schema.sql # Structure initiale │ ├── discordbot/ # Module Discord -│ └── __init__.py # Bot et handlers +│ ├── __init__.py # Bot et handlers principaux +│ └── humblebundle.py # Surveillance Humble Bundle │ ├── twitchbot/ # Module Twitch -│ └── __init__.py # Bot Twitch et handlers +│ ├── __init__.py # Bot Twitch et handlers +│ └── live_alert.py # Surveillance des streams live │ ├── protondb/ # Module ProtonDB │ └── __init__.py # API Algolia et recherche compatibilité │ └── webapp/ # Interface d'administration - ├── static/ # Assets statiques - ├── templates/ # Vues HTML - └── *.py # Contrôleurs par section + ├── static/ # Assets statiques (CSS, JS, images) + ├── templates/ # Vues HTML Jinja2 + ├── live_alert.py # Gestion des alertes Twitch + ├── twitch_auth.py # Authentification Twitch OAuth + └── *.py # Autres contrôleurs par section ``` ### Composants principaux @@ -230,28 +241,37 @@ python run-web.py ## Spécifications techniques ### Base de données (SQLite) -- **Configuration** : Paramètres et tokens -- **Humeur** : Statuts Discord rotatifs -- **Commande** : Commandes personnalisées Discord/Twitch +- **Configuration** : Paramètres et tokens des plateformes +- **Humeur** : Statuts Discord rotatifs avec gestion automatique +- **Commande** : Commandes personnalisées multi-plateformes (Discord/Twitch) +- **LiveAlert** : Configuration surveillance streamers Twitch (nom, canal Discord, statut) - **GameAlias** : Alias pour améliorer les recherches ProtonDB -- **GameBundle** : Historique Humble Bundle -- **Message** : Messages périodiques *(structure définie, non implémenté)* +- **GameBundle** : Historique et notifications Humble Bundle +- **Message** : Messages automatiques périodiques (implémenté) ### Architecture multi-thread -- **Thread 1** : Interface web Flask (port 5000) -- **Thread 2** : Bot Discord et tâches automatisées -- **Thread 3** : Bot Twitch et gestion du chat +- **Thread 1** : Interface web Flask (port 5000) avec logging rotatif +- **Thread 2** : Bot Discord et tâches automatisées (humeurs, Humble Bundle) +- **Thread 3** : Bot Twitch et surveillance live streams (vérification 5min) + +### Monitoring et logging +- **Healthcheck Docker** : Surveillance processus Python + détection erreurs logs +- **Logs rotatifs** : Fichiers limités à 50MB avec rotation automatique +- **Persistance** : Logs sauvegardés sur l'hôte dans `./logs/` ### Dépendances principales ``` -discord.py>=2.3.2 # API Discord -flask>=2.3.2 # Interface web -flask-sqlalchemy>=3.0.3 # ORM SQLAlchemy -requests>=2.32.4 # Client HTTP -waitress>=3.0.2 # Serveur WSGI -algoliasearch>=4 # API ProtonDB/SteamDB -twitchAPI>=4.5.0 # API Twitch -python-dotenv==1.0.0 # Variables d'environnement +discord.py==2.3.2 # API Discord avec support async +flask>=2.3.2 # Interface web et API REST +flask-sqlalchemy>=3.0.3 # ORM SQLAlchemy pour base de données +flask[async] # Extensions async pour Flask +requests>=2.32.4 # Client HTTP pour APIs externes +waitress>=3.0.2 # Serveur WSGI de production +algoliasearch>=4,<5 # API ProtonDB via Algolia +twitchAPI>=4.5.0 # API Twitch pour streams et chat +python-dotenv==1.0.0 # Gestion variables d'environnement +aiohttp>=3.7.4,<4 # Client HTTP async (requis par discord.py) +audioop-lts # Compatibilité audio Python 3.13+ ``` ## Développement diff --git a/docker-compose.yml b/docker-compose.yml index c98e3fc..ecea7ab 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,15 +9,12 @@ services: environment: TZ: Europe/Paris # Fuseau horaire - ENABLE_ZABBIX: false # Surveillance désactivée - ZABBIX_SERVER: zabbix-server.example.com - ZABBIX_HOSTNAME: mamiehenriette volumes: - ./instance:/app/instance # Base de données et configuration persistante + - ./logs:/app/logs # Logs de l'application ports: - 5000:5000 # Interface web sur http://localhost:5000 -# - "10050:10050" # Port Zabbix (décommentez si nécessaire) watchtower: # Permet de mettre à jours automatiquement image: containrrr/watchtower:latest diff --git a/start.sh b/start.sh index b6cc32c..addc44c 100644 --- a/start.sh +++ b/start.sh @@ -1,21 +1,4 @@ #!/bin/sh -# Script de démarrage conditionnel pour Zabbix et le bot Discord - -# Vérifier si Zabbix est activé -if [ "$ENABLE_ZABBIX" = "true" ]; then - echo "Zabbix activé - Configuration de l'agent..." - - # Remplacer les variables dans la config Zabbix - sed -i "s/Server=.*/Server=$ZABBIX_SERVER/" /etc/zabbix/zabbix_agent2.conf - sed -i "s/ServerActive=.*/ServerActive=$ZABBIX_SERVER:10051/" /etc/zabbix/zabbix_agent2.conf - sed -i "s/Hostname=.*/Hostname=$ZABBIX_HOSTNAME/" /etc/zabbix/zabbix_agent2.conf - - zabbix_agent2 -f & - echo "Zabbix Agent démarré" -else - echo "Zabbix désactivé" -fi - echo "Démarrage du bot Discord..." -exec /app/venv/bin/python run-web.py \ No newline at end of file +exec /app/venv/bin/python run-web.py 2>&1 | rotatelogs /app/logs/app.log.%Y%m%d-%H%M%S 50M \ No newline at end of file From 1ad8d28bd1f3b6fac12b66a9bb5853f4c018c343 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 03:27:22 +0200 Subject: [PATCH 09/21] corrige bug log qui ne s'affiche pas dans la console --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index addc44c..6b18e42 100644 --- a/start.sh +++ b/start.sh @@ -1,4 +1,4 @@ #!/bin/sh echo "Démarrage du bot Discord..." -exec /app/venv/bin/python run-web.py 2>&1 | rotatelogs /app/logs/app.log.%Y%m%d-%H%M%S 50M \ No newline at end of file +exec /app/venv/bin/python run-web.py 2>&1 | tee >(rotatelogs /app/logs/app.log.%Y%m%d-%H%M%S 50M) \ No newline at end of file From daecbe1b18de6591adc5fe68e794acfe459e3f2e Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 03:30:50 +0200 Subject: [PATCH 10/21] =?UTF-8?q?Rajoute=20bash=20pour=20corrig=C3=A9=20sy?= =?UTF-8?q?ntax=20en=20sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 ++- start.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b6b010c..96bfa3e 100755 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ python3-pip \ python3-venv \ procps \ - apache2-utils + apache2-utils \ + bash RUN sed -i 's/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen; \ locale-gen; \ diff --git a/start.sh b/start.sh index 6b18e42..aeb05f3 100644 --- a/start.sh +++ b/start.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash echo "Démarrage du bot Discord..." exec /app/venv/bin/python run-web.py 2>&1 | tee >(rotatelogs /app/logs/app.log.%Y%m%d-%H%M%S 50M) \ No newline at end of file From b55c779d43bb13cbf021dfbc007b5d201e3dd1aa Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 03:48:21 +0200 Subject: [PATCH 11/21] Ajoute date et heure dans log --- start.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/start.sh b/start.sh index aeb05f3..d66e5c0 100644 --- a/start.sh +++ b/start.sh @@ -1,4 +1,6 @@ #!/bin/bash echo "Démarrage du bot Discord..." -exec /app/venv/bin/python run-web.py 2>&1 | tee >(rotatelogs /app/logs/app.log.%Y%m%d-%H%M%S 50M) \ No newline at end of file +exec /app/venv/bin/python run-web.py 2>&1 | while IFS= read -r line; do + echo "$(date '+%Y-%m-%d %H:%M:%S%z') $line" | tee -a /app/logs/$(hostname).log # RFC 3339 / ISO 8601 +done \ No newline at end of file From 6a897c4403622135326df855834479bbb09907ab Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 05:09:58 +0200 Subject: [PATCH 12/21] =?UTF-8?q?Ajout=20d=C3=A9tection=20erreur=20SQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- zabbix_agent2.conf | 27 --------------------------- 2 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 zabbix_agent2.conf diff --git a/Dockerfile b/Dockerfile index 96bfa3e..4423851 100755 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,6 @@ RUN python3 -m venv /app/venv && \ mkdir -p /app/logs HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD pgrep python > /dev/null && ! (find /app/logs -name "app.log.*" -exec tail -n 20 {} \; 2>/dev/null | grep -E "ERROR|CRITICAL|Exception") || exit 1 + CMD pgrep python > /dev/null && ! (tail -n 20 /app/logs/$(hostname).log 2>/dev/null | grep -E "ERROR|CRITICAL|Exception|sqlite3\.OperationalError") || exit 1 CMD ["/start.sh"] diff --git a/zabbix_agent2.conf b/zabbix_agent2.conf deleted file mode 100644 index 4b6cfbe..0000000 --- a/zabbix_agent2.conf +++ /dev/null @@ -1,27 +0,0 @@ -# Configuration Zabbix Agent 2 pour Mamie Henrriette Bot - -# Serveur Zabbix -Server=zabbix-server.example.com -ServerActive=zabbix-server.example.com:10051 - -# Configuration de l'agent -Hostname=MamieHenriette -ListenPort=10050 -ListenIP=0.0.0.0 - -# Logs -LogType=console -LogLevel=3 -DebugLevel=3 - -# Timeout -Timeout=30 - -# Métriques personnalisées pour le bot Discord -UserParameter=discord.bot.status,python3 /app/bot_status.py -UserParameter=discord.bot.uptime,cat /proc/uptime | awk '{print $1}' -UserParameter=discord.bot.memory,ps -o pid,vsz,rss,comm -p $(pgrep -f bot.py) | tail -1 | awk '{print $3}' - -# Surveillance des logs -UserParameter=discord.bot.errors,grep -c "ERROR" /var/log/discord-bot.log 2>/dev/null || echo 0 -UserParameter=discord.bot.warnings,grep -c "WARNING" /var/log/discord-bot.log 2>/dev/null || echo 0 \ No newline at end of file From 815d085204e107b1906a0f05871d17d1f5fa05a3 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 05:19:16 +0200 Subject: [PATCH 13/21] =?UTF-8?q?Corrige=20d=C3=A9tection=20pattern=20grep?= =?UTF-8?q?=20-E=20ERROR:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4423851..99f4e13 100755 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,6 @@ RUN python3 -m venv /app/venv && \ mkdir -p /app/logs HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD pgrep python > /dev/null && ! (tail -n 20 /app/logs/$(hostname).log 2>/dev/null | grep -E "ERROR|CRITICAL|Exception|sqlite3\.OperationalError") || exit 1 + CMD pgrep python > /dev/null && ! (tail -n 20 /app/logs/$(hostname).log 2>/dev/null | grep -E "ERROR:|CRITICAL:|Exception") || exit 1 CMD ["/start.sh"] From 83b553b5583042c00a89f03352ef1020794caa37 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 05:25:05 +0200 Subject: [PATCH 14/21] =?UTF-8?q?Corrige=20erreur=20d=C3=A9tection=20ERROR?= =?UTF-8?q?=20CRITICAL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 99f4e13..e82c743 100755 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,6 @@ RUN python3 -m venv /app/venv && \ mkdir -p /app/logs HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD pgrep python > /dev/null && ! (tail -n 20 /app/logs/$(hostname).log 2>/dev/null | grep -E "ERROR:|CRITICAL:|Exception") || exit 1 + CMD pgrep python > /dev/null && ! (tail -n 20 $(ls -t /app/logs/*.log 2>/dev/null | head -1) 2>/dev/null | grep -E "ERROR:|CRITICAL:|Exception") || exit 1 CMD ["/start.sh"] From 97e7a7316f339993bc08eb2a902924947746ee9c Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 05:30:12 +0200 Subject: [PATCH 15/21] =?UTF-8?q?Corrige=20erreur=20d=C3=A9tection=20ERROR?= =?UTF-8?q?=20CRITICAL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e82c743..85212af 100755 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,6 @@ RUN python3 -m venv /app/venv && \ mkdir -p /app/logs HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD pgrep python > /dev/null && ! (tail -n 20 $(ls -t /app/logs/*.log 2>/dev/null | head -1) 2>/dev/null | grep -E "ERROR:|CRITICAL:|Exception") || exit 1 + CMD pgrep python > /dev/null && ! (ps aux | grep '[r]un-web.py' | grep -q python) && exit 1 || exit 0 CMD ["/start.sh"] From 2b5e82edaba026d2ccd362da573664ac44520f4b Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 05:41:29 +0200 Subject: [PATCH 16/21] =?UTF-8?q?Corrige=20erreur=20d=C3=A9tection=20ERROR?= =?UTF-8?q?=20CRITICAL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 85212af..75fa392 100755 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,6 @@ RUN python3 -m venv /app/venv && \ mkdir -p /app/logs HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD pgrep python > /dev/null && ! (ps aux | grep '[r]un-web.py' | grep -q python) && exit 1 || exit 0 + CMD pgrep python > /dev/null && ! (tail -n 20 /app/logs/$(hostname).log 2>/dev/null | grep -iE "(ERROR|CRITICAL|Exception|sqlite3\.OperationalError)") || exit 1 CMD ["/start.sh"] From b99c80def4b4735d0d760466f17acf4bfce50f20 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 05:48:22 +0200 Subject: [PATCH 17/21] =?UTF-8?q?Corrige=20erreur=20d=C3=A9tection=20ERROR?= =?UTF-8?q?=20CRITICAL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 75fa392..4b34484 100755 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,6 @@ RUN python3 -m venv /app/venv && \ mkdir -p /app/logs HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD pgrep python > /dev/null && ! (tail -n 20 /app/logs/$(hostname).log 2>/dev/null | grep -iE "(ERROR|CRITICAL|Exception|sqlite3\.OperationalError)") || exit 1 + CMD pgrep python > /dev/null && ! (tail -n 1000 /app/logs/*.log 2>/dev/null | grep -iE "(ERROR|CRITICAL|Exception|sqlite3\.OperationalError)") || exit 1 CMD ["/start.sh"] From 5954ea9401a73905666f4f8a9aea25d7208a8f81 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 05:59:39 +0200 Subject: [PATCH 18/21] =?UTF-8?q?date=20heure=20pour=20le=20fichiers=20log?= =?UTF-8?q?=20et=20max=20retry=20corrig=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- start.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4b34484..bc3ab9c 100755 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,6 @@ RUN python3 -m venv /app/venv && \ mkdir -p /app/logs HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD pgrep python > /dev/null && ! (tail -n 1000 /app/logs/*.log 2>/dev/null | grep -iE "(ERROR|CRITICAL|Exception|sqlite3\.OperationalError)") || exit 1 + CMD pgrep python > /dev/null && ! (tail -n 1000 $(ls -t /app/logs/*.log 2>/dev/null | head -1) 2>/dev/null | grep -iE "(ERROR|CRITICAL|Exception|sqlite3\.OperationalError)") || (echo "Healthcheck échoué, arrêt du conteneur" && kill 1) CMD ["/start.sh"] diff --git a/start.sh b/start.sh index d66e5c0..3f83efa 100644 --- a/start.sh +++ b/start.sh @@ -1,6 +1,7 @@ #!/bin/bash echo "Démarrage du bot Discord..." +LOG_FILE="/app/logs/$(date '+%Y%m%d_%H%M%S').log" exec /app/venv/bin/python run-web.py 2>&1 | while IFS= read -r line; do - echo "$(date '+%Y-%m-%d %H:%M:%S%z') $line" | tee -a /app/logs/$(hostname).log # RFC 3339 / ISO 8601 + echo "$(date '+%Y-%m-%d %H:%M:%S%z') $line" | tee -a "$LOG_FILE" # RFC 3339 / ISO 8601 done \ No newline at end of file From e0d639c195ac36b97d63882cc38ad19ac6a8162a Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 06:05:22 +0200 Subject: [PATCH 19/21] =?UTF-8?q?pkill=20-KILL=20-f=20python=20pour=20arre?= =?UTF-8?q?ter=20le=20conteneurs=20apr=C3=A8s=203=20=C3=A9ssais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bc3ab9c..5c4b2ff 100755 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,6 @@ RUN python3 -m venv /app/venv && \ mkdir -p /app/logs HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD pgrep python > /dev/null && ! (tail -n 1000 $(ls -t /app/logs/*.log 2>/dev/null | head -1) 2>/dev/null | grep -iE "(ERROR|CRITICAL|Exception|sqlite3\.OperationalError)") || (echo "Healthcheck échoué, arrêt du conteneur" && kill 1) + CMD pgrep python > /dev/null && ! (tail -n 1000 $(ls -t /app/logs/*.log 2>/dev/null | head -1) 2>/dev/null | grep -iE "(ERROR|CRITICAL|Exception|sqlite3\.OperationalError)") || (echo "Healthcheck échoué, arrêt du conteneur" && pkill -TERM -f python && sleep 2 && pkill -KILL -f python) CMD ["/start.sh"] From 7d53c0c37b1d79c324baed02ee00e747f04ab85f Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 06:11:38 +0200 Subject: [PATCH 20/21] =?UTF-8?q?Le=20conteneur=20restera=20en=20vie=20mai?= =?UTF-8?q?s=20sera=20clairement=20identifi=C3=A9=20comme=20d=C3=A9faillan?= =?UTF-8?q?t.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5c4b2ff..7465a47 100755 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,6 @@ RUN python3 -m venv /app/venv && \ mkdir -p /app/logs HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD pgrep python > /dev/null && ! (tail -n 1000 $(ls -t /app/logs/*.log 2>/dev/null | head -1) 2>/dev/null | grep -iE "(ERROR|CRITICAL|Exception|sqlite3\.OperationalError)") || (echo "Healthcheck échoué, arrêt du conteneur" && pkill -TERM -f python && sleep 2 && pkill -KILL -f python) + CMD pgrep python > /dev/null && ! (tail -n 1000 $(ls -t /app/logs/*.log 2>/dev/null | head -1) 2>/dev/null | grep -iE "(ERROR|CRITICAL|Exception|sqlite3\.OperationalError)") CMD ["/start.sh"] From d5a137aefd0b0b87b73c05e3a48f36d6a6b87102 Mon Sep 17 00:00:00 2001 From: sky Date: Mon, 15 Sep 2025 19:00:42 +0200 Subject: [PATCH 21/21] Retire erreur commande qui ne fonctionne pas --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 48e240b..a26c22d 100755 --- a/README.md +++ b/README.md @@ -137,11 +137,6 @@ docker compose up --build -d ### Commandes Docker utiles -```bash -# Logs en temps réel -docker compose logs -f MamieHenriette -``` - ```bash # Logs d'un conteneur en cours d'exécution docker logs -f MamieHenriette