From 2c6759f15c1a818ee78f98abeb855b9fc7d0c0fc Mon Sep 17 00:00:00 2001 From: Thomas Enjalbert Date: Thu, 28 May 2026 15:14:16 +0200 Subject: [PATCH 1/6] feat : add all files and folders to run the bash script with the apps from tp-collaboratif-git-dev-starter --- .env | 2 + .gitignore | 3 + erreurs.txt | 5 + fichier.txt | 2 + mon-projet/README.txt | 1 + mon-projet/config/settings.txt | 0 mon-projet/logs/app.log | 22 ++ mon-projet/logs/app.log.bak | 22 ++ mon-projet/logs/backup.log | 0 mon-projet/logs/rapport-20260528-114829.txt | 16 + mon-projet/logs/rapport-20260528-115838.txt | 16 + mon-projet/logs/rapport-20260528-115901.txt | 16 + mon-projet/logs/rapport-20260528-115959.txt | 16 + mon-projet/src/analyse-niveaux.sh | 14 + mon-projet/src/app.sh | 0 mon-projet/src/check-env.sh | 61 ++++ mon-projet/src/check-logs.sh | 37 +++ mon-projet/src/couleurs.sh | 27 ++ mon-projet/src/info.sh | 21 ++ mon-projet/src/rapport.sh | 60 ++++ node-client/app.js | 35 ++ node-client/package-lock.json | 346 ++++++++++++++++++++ node-client/package.json | 12 + python-api/app.py | 50 +++ python-api/requirements.txt | 1 + python-api/server.log | 19 ++ rapport.txt | 5 + setup.sh | 107 ++++++ 28 files changed, 916 insertions(+) create mode 100644 .env create mode 100644 erreurs.txt create mode 100644 fichier.txt create mode 100644 mon-projet/README.txt create mode 100644 mon-projet/config/settings.txt create mode 100644 mon-projet/logs/app.log create mode 100644 mon-projet/logs/app.log.bak create mode 100644 mon-projet/logs/backup.log create mode 100644 mon-projet/logs/rapport-20260528-114829.txt create mode 100644 mon-projet/logs/rapport-20260528-115838.txt create mode 100644 mon-projet/logs/rapport-20260528-115901.txt create mode 100644 mon-projet/logs/rapport-20260528-115959.txt create mode 100644 mon-projet/src/analyse-niveaux.sh create mode 100644 mon-projet/src/app.sh create mode 100644 mon-projet/src/check-env.sh create mode 100644 mon-projet/src/check-logs.sh create mode 100644 mon-projet/src/couleurs.sh create mode 100644 mon-projet/src/info.sh create mode 100644 mon-projet/src/rapport.sh create mode 100644 node-client/app.js create mode 100644 node-client/package-lock.json create mode 100644 node-client/package.json create mode 100644 python-api/app.py create mode 100644 python-api/requirements.txt create mode 100644 python-api/server.log create mode 100644 rapport.txt create mode 100644 setup.sh diff --git a/.env b/.env new file mode 100644 index 0000000..e412799 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +PORT=5001 +ENV=development diff --git a/.gitignore b/.gitignore index 4f30f55..198eb8a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Ignore node_modules and dependency directories +node_modules/ + # Local .terraform directories .terraform/ diff --git a/erreurs.txt b/erreurs.txt new file mode 100644 index 0000000..259593d --- /dev/null +++ b/erreurs.txt @@ -0,0 +1,5 @@ +2024-01-15 08:02:45 ERROR Failed to connect to Azure Storage: connection timeout +2024-01-15 08:05:33 ERROR Authentication failed for service account: deploy_svc +2024-01-15 08:07:42 ERROR Database query timeout after 30s on table: audit_logs +2024-01-15 08:09:00 ERROR Max retries exceeded - Azure Storage service unavailable +2024-01-15 08:12:45 ERROR Backup failed: insufficient permissions on /var/backup/azure diff --git a/fichier.txt b/fichier.txt new file mode 100644 index 0000000..2e0a161 --- /dev/null +++ b/fichier.txt @@ -0,0 +1,2 @@ +Bonjour +Monde diff --git a/mon-projet/README.txt b/mon-projet/README.txt new file mode 100644 index 0000000..2b44940 --- /dev/null +++ b/mon-projet/README.txt @@ -0,0 +1 @@ +# Mon Projet diff --git a/mon-projet/config/settings.txt b/mon-projet/config/settings.txt new file mode 100644 index 0000000..e69de29 diff --git a/mon-projet/logs/app.log b/mon-projet/logs/app.log new file mode 100644 index 0000000..d2d2378 --- /dev/null +++ b/mon-projet/logs/app.log @@ -0,0 +1,22 @@ +2024-01-15 08:00:01 INFO Application started on port 8080 +2024-01-15 08:00:05 INFO Connected to Azure SQL Database successfully +2024-01-15 08:01:22 WARNING High memory usage detected: 78% +2024-01-15 08:02:45 ERROR Failed to connect to Azure Storage: connection timeout +2024-01-15 08:03:10 INFO Request processed: GET /api/health [200] +2024-01-15 08:05:33 ERROR Authentication failed for service account: deploy_svc +2024-01-15 08:06:15 WARNING CPU usage spike detected: 92% +2024-01-15 08:07:42 ERROR Database query timeout after 30s on table: audit_logs +2024-01-15 08:08:00 INFO Retry attempt 1/3 for Azure Storage connection +2024-01-15 08:08:30 INFO Retry attempt 2/3 for Azure Storage connection +2024-01-15 08:09:00 ERROR Max retries exceeded - Azure Storage service unavailable +2024-01-15 08:10:15 WARNING Disk space below threshold: 15% remaining on /dev/sda1 +2024-01-15 08:11:22 INFO Backup job started: daily-backup-2024-01-15 +2024-01-15 08:12:45 ERROR Backup failed: insufficient permissions on /var/backup/azure +2024-01-15 08:14:03 INFO Alert sent to monitoring team via Azure Monitor +2024-01-15 08:15:00 INFO Scheduled maintenance check completed +2024-01-15 08:16:30 WARNING SSL certificate expires in 14 days for api.azuretech.fr +2024-01-15 08:18:00 CRITICAL Database connection pool exhausted — all 20 connections in use +2024-01-15 08:18:55 INFO Kubernetes pod restarted: api-deployment-7d9f8b-xkp2m +2024-01-15 08:19:30 CRITICAL Azure Key Vault unreachable — secrets cannot be retrieved +2024-01-15 08:20:00 INFO Health check passed: all 3 replicas running +2024-01-15 08:21:00 CRITICAL Disk full on /var/log — logging suspended diff --git a/mon-projet/logs/app.log.bak b/mon-projet/logs/app.log.bak new file mode 100644 index 0000000..d2d2378 --- /dev/null +++ b/mon-projet/logs/app.log.bak @@ -0,0 +1,22 @@ +2024-01-15 08:00:01 INFO Application started on port 8080 +2024-01-15 08:00:05 INFO Connected to Azure SQL Database successfully +2024-01-15 08:01:22 WARNING High memory usage detected: 78% +2024-01-15 08:02:45 ERROR Failed to connect to Azure Storage: connection timeout +2024-01-15 08:03:10 INFO Request processed: GET /api/health [200] +2024-01-15 08:05:33 ERROR Authentication failed for service account: deploy_svc +2024-01-15 08:06:15 WARNING CPU usage spike detected: 92% +2024-01-15 08:07:42 ERROR Database query timeout after 30s on table: audit_logs +2024-01-15 08:08:00 INFO Retry attempt 1/3 for Azure Storage connection +2024-01-15 08:08:30 INFO Retry attempt 2/3 for Azure Storage connection +2024-01-15 08:09:00 ERROR Max retries exceeded - Azure Storage service unavailable +2024-01-15 08:10:15 WARNING Disk space below threshold: 15% remaining on /dev/sda1 +2024-01-15 08:11:22 INFO Backup job started: daily-backup-2024-01-15 +2024-01-15 08:12:45 ERROR Backup failed: insufficient permissions on /var/backup/azure +2024-01-15 08:14:03 INFO Alert sent to monitoring team via Azure Monitor +2024-01-15 08:15:00 INFO Scheduled maintenance check completed +2024-01-15 08:16:30 WARNING SSL certificate expires in 14 days for api.azuretech.fr +2024-01-15 08:18:00 CRITICAL Database connection pool exhausted — all 20 connections in use +2024-01-15 08:18:55 INFO Kubernetes pod restarted: api-deployment-7d9f8b-xkp2m +2024-01-15 08:19:30 CRITICAL Azure Key Vault unreachable — secrets cannot be retrieved +2024-01-15 08:20:00 INFO Health check passed: all 3 replicas running +2024-01-15 08:21:00 CRITICAL Disk full on /var/log — logging suspended diff --git a/mon-projet/logs/backup.log b/mon-projet/logs/backup.log new file mode 100644 index 0000000..e69de29 diff --git a/mon-projet/logs/rapport-20260528-114829.txt b/mon-projet/logs/rapport-20260528-114829.txt new file mode 100644 index 0000000..093f079 --- /dev/null +++ b/mon-projet/logs/rapport-20260528-114829.txt @@ -0,0 +1,16 @@ +RAPPORT D'ANALYSE — 28/05/2026 11:48 + +--- Compteurs --- +INFO=10 WARNING=4 ERROR=5 CRITICAL=3 + +--- Incidents critiques --- +2024-01-15 08:18:00 CRITICAL Database connection pool exhausted — all 20 connections in use +2024-01-15 08:19:30 CRITICAL Azure Key Vault unreachable — secrets cannot be retrieved +2024-01-15 08:21:00 CRITICAL Disk full on /var/log — logging suspended + +--- Erreurs --- +2024-01-15 08:02:45 ERROR Failed to connect to Azure Storage: connection timeout +2024-01-15 08:05:33 ERROR Authentication failed for service account: deploy_svc +2024-01-15 08:07:42 ERROR Database query timeout after 30s on table: audit_logs +2024-01-15 08:09:00 ERROR Max retries exceeded - Azure Storage service unavailable +2024-01-15 08:12:45 ERROR Backup failed: insufficient permissions on /var/backup/azure diff --git a/mon-projet/logs/rapport-20260528-115838.txt b/mon-projet/logs/rapport-20260528-115838.txt new file mode 100644 index 0000000..d97f8f8 --- /dev/null +++ b/mon-projet/logs/rapport-20260528-115838.txt @@ -0,0 +1,16 @@ +RAPPORT D'ANALYSE — 28/05/2026 11:58 + +--- Compteurs --- +INFO=10 WARNING=4 ERROR=5 CRITICAL=3 + +--- Incidents critiques --- +2024-01-15 08:18:00 CRITICAL Database connection pool exhausted — all 20 connections in use +2024-01-15 08:19:30 CRITICAL Azure Key Vault unreachable — secrets cannot be retrieved +2024-01-15 08:21:00 CRITICAL Disk full on /var/log — logging suspended + +--- Erreurs --- +2024-01-15 08:02:45 ERROR Failed to connect to Azure Storage: connection timeout +2024-01-15 08:05:33 ERROR Authentication failed for service account: deploy_svc +2024-01-15 08:07:42 ERROR Database query timeout after 30s on table: audit_logs +2024-01-15 08:09:00 ERROR Max retries exceeded - Azure Storage service unavailable +2024-01-15 08:12:45 ERROR Backup failed: insufficient permissions on /var/backup/azure diff --git a/mon-projet/logs/rapport-20260528-115901.txt b/mon-projet/logs/rapport-20260528-115901.txt new file mode 100644 index 0000000..6790325 --- /dev/null +++ b/mon-projet/logs/rapport-20260528-115901.txt @@ -0,0 +1,16 @@ +RAPPORT D'ANALYSE — 28/05/2026 11:59 + +--- Compteurs --- +INFO=10 WARNING=4 ERROR=5 CRITICAL=3 + +--- Incidents critiques --- +2024-01-15 08:18:00 CRITICAL Database connection pool exhausted — all 20 connections in use +2024-01-15 08:19:30 CRITICAL Azure Key Vault unreachable — secrets cannot be retrieved +2024-01-15 08:21:00 CRITICAL Disk full on /var/log — logging suspended + +--- Erreurs --- +2024-01-15 08:02:45 ERROR Failed to connect to Azure Storage: connection timeout +2024-01-15 08:05:33 ERROR Authentication failed for service account: deploy_svc +2024-01-15 08:07:42 ERROR Database query timeout after 30s on table: audit_logs +2024-01-15 08:09:00 ERROR Max retries exceeded - Azure Storage service unavailable +2024-01-15 08:12:45 ERROR Backup failed: insufficient permissions on /var/backup/azure diff --git a/mon-projet/logs/rapport-20260528-115959.txt b/mon-projet/logs/rapport-20260528-115959.txt new file mode 100644 index 0000000..6790325 --- /dev/null +++ b/mon-projet/logs/rapport-20260528-115959.txt @@ -0,0 +1,16 @@ +RAPPORT D'ANALYSE — 28/05/2026 11:59 + +--- Compteurs --- +INFO=10 WARNING=4 ERROR=5 CRITICAL=3 + +--- Incidents critiques --- +2024-01-15 08:18:00 CRITICAL Database connection pool exhausted — all 20 connections in use +2024-01-15 08:19:30 CRITICAL Azure Key Vault unreachable — secrets cannot be retrieved +2024-01-15 08:21:00 CRITICAL Disk full on /var/log — logging suspended + +--- Erreurs --- +2024-01-15 08:02:45 ERROR Failed to connect to Azure Storage: connection timeout +2024-01-15 08:05:33 ERROR Authentication failed for service account: deploy_svc +2024-01-15 08:07:42 ERROR Database query timeout after 30s on table: audit_logs +2024-01-15 08:09:00 ERROR Max retries exceeded - Azure Storage service unavailable +2024-01-15 08:12:45 ERROR Backup failed: insufficient permissions on /var/backup/azure diff --git a/mon-projet/src/analyse-niveaux.sh b/mon-projet/src/analyse-niveaux.sh new file mode 100644 index 0000000..62fd3e9 --- /dev/null +++ b/mon-projet/src/analyse-niveaux.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# analyse-niveaux.sh — Compte chaque niveau de log + +LOG_FILE="ressources/server.log" + +echo "=== Analyse par niveau ===" + +for NIVEAU in INFO WARNING ERROR CRITICAL; do + NB=$(grep -c "$NIVEAU" "$LOG_FILE") + echo " $NIVEAU : $NB occurrence(s)" +done + +echo "==========================" +echo " TOTAL : $(wc -l < "$LOG_FILE") lignes" \ No newline at end of file diff --git a/mon-projet/src/app.sh b/mon-projet/src/app.sh new file mode 100644 index 0000000..e69de29 diff --git a/mon-projet/src/check-env.sh b/mon-projet/src/check-env.sh new file mode 100644 index 0000000..d82cdcb --- /dev/null +++ b/mon-projet/src/check-env.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# check-env.sh — Vérifie que l'environnement est prêt pour NexaCloud + +set -e + +VERT="\033[0;32m" +ROUGE="\033[0;31m" +JAUNE="\033[0;33m" +RESET="\033[0m" + +ok() { echo -e "${VERT} [OK]${RESET} $1"; } +warn() { echo -e "${JAUNE} [WARN]${RESET} $1"; } +err() { echo -e "${ROUGE} [ERR]${RESET} $1"; } + +# Cette fonction vérifie si une commande est installée +# $1 = nom de la commande | $2 = nom à afficher (optionnel) +verifier_commande() { + local cmd="$1" + local nom="${2:-$1}" + # La commande "command -v" vérifie si un programme existe + # &>/dev/null redirige la sortie pour ne rien afficher + if command -v "$cmd" &>/dev/null; then + ok "$nom installé" + else + err "$nom non trouvé" + fi +} + +echo "" +echo "=== Vérification de l'environnement NexaCloud ===" +echo "" + +# TODO: appelez verifier_commande pour tester python3, node, npm et git +# Exemple : verifier_commande "python3" "Python" +verifier_commande "python3" "Python" +verifier_commande "node" "Node.js" +verifier_commande "npm" "npm" +verifier_commande "git" "Git" + + +echo "" + +# TODO: vérifiez que ces deux fichiers existent avec [ -f ] +# et affichez ok ou warn selon le résultat +# Fichiers à vérifier : "config.json" et "ressources/server.log" +if [ -f "config.json" ]; then + ok "Fichier config.json trouvé" +else + warn "Fichier config.json manquant" +fi + +if [ -f "ressources/server.log" ]; then + ok "Fichier ressources/server.log trouvé" +else + warn "Fichier ressources/server.log manquant" +fi + + +echo "" +echo "=== Vérification terminée ===" +echo "" \ No newline at end of file diff --git a/mon-projet/src/check-logs.sh b/mon-projet/src/check-logs.sh new file mode 100644 index 0000000..231d225 --- /dev/null +++ b/mon-projet/src/check-logs.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# check-logs.sh — Vérifie l'état des logs et alerte si nécessaire + +if [ -z "$1" ]; then + echo "Usage : $0 " + exit 1 +fi + +LOG_FILE="$1" +SEUIL_ERREURS=3 + +[ -f "$LOG_FILE" ] && echo "Fichier trouvé" || echo "Fichier absent" + +if [ ! -f "$LOG_FILE" ]; then + echo "ERREUR : le fichier $LOG_FILE n'existe pas." + exit 1 +fi + +NB_ERREURS=$(grep -c "ERROR" "$LOG_FILE") +NB_CRITIQUES=$(grep -c "CRITICAL" "$LOG_FILE") +NB_WARNINGS=$(grep -c "WARNING" "$LOG_FILE") + +echo "=== Analyse de $LOG_FILE ===" +echo " INFO : $(grep -c "INFO" "$LOG_FILE")" +echo " WARNING : $NB_WARNINGS" +echo " ERROR : $NB_ERREURS" +echo " CRITICAL : $NB_CRITIQUES" +echo "===========================" + +# Vérifier le seuil d'erreurs +if [ $NB_CRITIQUES -gt 0 ]; then + echo "ALERTE CRITIQUE : $NB_CRITIQUES incident(s) critique(s) détecté(s) !" +elif [ $NB_ERREURS -gt $SEUIL_ERREURS ]; then + echo "ATTENTION : $NB_ERREURS erreurs détectées (seuil : $SEUIL_ERREURS)" +else + echo "OK : les logs sont dans les normes." +fi diff --git a/mon-projet/src/couleurs.sh b/mon-projet/src/couleurs.sh new file mode 100644 index 0000000..acbd0fc --- /dev/null +++ b/mon-projet/src/couleurs.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# couleurs.sh — Tester les fonctions d'affichage + +# Les codes couleur sont fournis +VERT="\033[0;32m" +ROUGE="\033[0;31m" +JAUNE="\033[0;33m" +CYAN="\033[0;36m" +RESET="\033[0m" + +# Ces fonctions sont déjà écrites — observez leur structure +ok() { echo -e "${VERT}[OK]${RESET} $1"; } +info() { echo -e "${CYAN}[INFO]${RESET} $1"; } +warn() { echo -e "${JAUNE}[WARN]${RESET} $1"; } +err() { echo -e "${ROUGE}[ERR]${RESET} $1"; } + +# TODO: écrivez les fonctions warn() et err() sur le même modèle +# warn() doit afficher en jaune avec le préfixe [WARN] +# err() doit afficher en rouge avec le préfixe [ERR] + + + +# Test — ces lignes doivent afficher chacune dans la bonne couleur +ok "Installation réussie" +info "Démarrage du serveur..." +warn "Mémoire basse : 78%" +err "Connexion échouée" \ No newline at end of file diff --git a/mon-projet/src/info.sh b/mon-projet/src/info.sh new file mode 100644 index 0000000..362e900 --- /dev/null +++ b/mon-projet/src/info.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# info.sh — Affiche des informations sur l'environnement + +NOM_PROJET="NexaCloud" +VERSION="1.1.0" +LOG_FILE="ressources/server.log" + +echo "===============================" +echo " Projet : $NOM_PROJET" +echo " Version : $VERSION" +echo "===============================" + +# Vérifier que le fichier de log existe +if [ -f "$LOG_FILE" ]; then + NB_LIGNES=$(wc -l < "$LOG_FILE") + echo " Log : $LOG_FILE ($NB_LIGNES lignes)" +else + echo " Log : fichier introuvable !" +fi + +echo "===============================" \ No newline at end of file diff --git a/mon-projet/src/rapport.sh b/mon-projet/src/rapport.sh new file mode 100644 index 0000000..7d90a98 --- /dev/null +++ b/mon-projet/src/rapport.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# rapport.sh — Génère un rapport complet avec des fonctions + +for FICHIER in "$@"; do + echo "=== Traitement de $FICHIER ===" + grep -c "ERROR" "$FICHIER" +done + +LOG_FILE="${1:-ressources/server.log}" +RAPPORT="mon-projet/logs/rapport-$(date +%Y%m%d-%H%M%S).txt" + +# ── Fonctions ────────────────────────────────────────────────────── + +afficher_titre() { + echo "===========================================" + echo " $1" + echo "===========================================" +} + +compter_niveau() { + local niveau="$1" + local fichier="$2" + grep -c "$niveau" "$fichier" 2>/dev/null || echo 0 +} + +ecrire_section() { + local titre="$1" + local contenu="$2" + echo "" >> "$RAPPORT" + echo "--- $titre ---" >> "$RAPPORT" + echo "$contenu" >> "$RAPPORT" +} + +# ── Script principal ─────────────────────────────────────────────── + +if [ ! -f "$LOG_FILE" ]; then + echo "Fichier introuvable : $LOG_FILE" + exit 1 +fi + +afficher_titre "RAPPORT D'ANALYSE — $(date '+%d/%m/%Y %H:%M')" + +INFO=$(compter_niveau "INFO" "$LOG_FILE") +WARNING=$(compter_niveau "WARNING" "$LOG_FILE") +ERROR=$(compter_niveau "ERROR" "$LOG_FILE") +CRITICAL=$(compter_niveau "CRITICAL" "$LOG_FILE") + +echo " INFO : $INFO" +echo " WARNING : $WARNING" +echo " ERROR : $ERROR" +echo " CRITICAL : $CRITICAL" + +# Écrire le rapport dans un fichier +echo "RAPPORT D'ANALYSE — $(date '+%d/%m/%Y %H:%M')" > "$RAPPORT" +ecrire_section "Compteurs" "INFO=$INFO WARNING=$WARNING ERROR=$ERROR CRITICAL=$CRITICAL" +ecrire_section "Incidents critiques" "$(grep 'CRITICAL' "$LOG_FILE")" +ecrire_section "Erreurs" "$(grep 'ERROR' "$LOG_FILE")" + +echo "" +echo "Rapport sauvegardé : $RAPPORT" \ No newline at end of file diff --git a/node-client/app.js b/node-client/app.js new file mode 100644 index 0000000..47cf0a2 --- /dev/null +++ b/node-client/app.js @@ -0,0 +1,35 @@ +// Client Node.js — Interroge l'API Python et affiche un rapport des logs Azure +// ----------------------------------------------------------------- + +const path = require('path'); + +// Configuration partagée chargée depuis config.json (à la racine du projet) +const config = require(path.join(__dirname, '..', 'config.json')); +const API_URL = `http://${config.api.host}:${config.api.port}${config.api.route}`; + +const axios = require('axios'); + +async function getLogs() { + try { + const response = await axios.get(API_URL); + + const data = response.data; + + console.log('\n========================================'); + console.log(' RAPPORT D\'ANALYSE DES LOGS AZURE '); + console.log('========================================'); + console.log(` Erreurs detectees : ${data.error_count}`); + console.log(` Avertissements : ${data.warning_count}`); + console.log(` Messages info : ${data.info_count}`); + console.log('\n--- Detail des erreurs ---'); + data.errors.forEach(err => console.log(` > ${err}`)); + console.log('\n--- Detail des avertissements ---'); + data.warnings.forEach(warn => console.log(` > ${warn}`)); + console.log('========================================\n'); + + } catch (error) { + console.error('Erreur de connexion a l\'API Python :', error.message); + } +} + +getLogs(); diff --git a/node-client/package-lock.json b/node-client/package-lock.json new file mode 100644 index 0000000..6fc99fe --- /dev/null +++ b/node-client/package-lock.json @@ -0,0 +1,346 @@ +{ + "name": "log-analyser-client", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "log-analyser-client", + "version": "1.0.0", + "dependencies": { + "axios": "^1.6.0" + } + }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "license": "MIT", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, + "node_modules/axios": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.16.1.tgz", + "integrity": "sha512-caYkukvroVPO8KrzuJEb50Hm07KwfBZPEC3VeFHTsqWHvKTsy54hjJz9BS/cdaypROE2rH6xvm9mHX4fgWkr3A==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.16.0", + "form-data": "^4.0.5", + "https-proxy-agent": "^5.0.1", + "proxy-from-env": "^2.1.0" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/follow-redirects": { + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz", + "integrity": "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.5.tgz", + "integrity": "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.3.tgz", + "integrity": "sha512-ej4AhfhfL2Q2zpMmLo7U1Uv9+PyhIZpgQLGT1F9miIGmiCJIoCgSmczFdrc97mWT4kVY72KA+WnnhJ5pghSvSg==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "license": "MIT", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/proxy-from-env": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz", + "integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==", + "license": "MIT", + "engines": { + "node": ">=10" + } + } + } +} diff --git a/node-client/package.json b/node-client/package.json new file mode 100644 index 0000000..84280d9 --- /dev/null +++ b/node-client/package.json @@ -0,0 +1,12 @@ +{ + "name": "log-analyser-client", + "version": "1.0.0", + "description": "Client Node.js qui interroge l'API Python d'analyse de logs Azure", + "main": "app.js", + "scripts": { + "start": "node app.js" + }, + "dependencies": { + "axios": "^1.6.0" + } +} diff --git a/python-api/app.py b/python-api/app.py new file mode 100644 index 0000000..049ee71 --- /dev/null +++ b/python-api/app.py @@ -0,0 +1,50 @@ +from flask import Flask, jsonify +import json +import os + +app = Flask(__name__) + +# Chargement de la configuration partagée (config.json à la racine du projet) +config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'config.json') +with open(config_path, 'r') as f: + config = json.load(f) + +# ------------------------------------------------------- +# Analyse un fichier de logs serveur et retourne +# le nombre d'errors, warnings et infos détectés. +# ------------------------------------------------------- + +def parse_logs(filepath): + erreurs = [] + warnings = [] + infos = [] + + with open(filepath, "r") as f: + for line in f: + line = line.strip() + if not line: + continue + if "ERROR" in line: + erreurs.append(line) + elif "WARNING" in line: + warnings.append(line) + elif "INFO" in line: + infos.append(line) + + return { + "error_count": len(erreurs), + "warning_count": len(warnings), + "info_count": len(infos), + "errors": erreurs, + "warnings": warnings + } + + +@app.route("/api/logs", methods=["GET"]) +def get_logs(): + result = parse_logs(config["api"]["log_file"]) + return jsonify(result), 200 + + +if __name__ == "__main__": + app.run(debug=True, port=config["api"]["port"]) diff --git a/python-api/requirements.txt b/python-api/requirements.txt new file mode 100644 index 0000000..5bd19d3 --- /dev/null +++ b/python-api/requirements.txt @@ -0,0 +1 @@ +flask==3.0.0 diff --git a/python-api/server.log b/python-api/server.log new file mode 100644 index 0000000..5eac220 --- /dev/null +++ b/python-api/server.log @@ -0,0 +1,19 @@ +2024-01-15 08:00:01 INFO Application started on port 8080 +2024-01-15 08:00:05 INFO Connected to Azure SQL Database successfully +2024-01-15 08:01:22 WARNING High memory usage detected: 78% +2024-01-15 08:02:45 ERROR Failed to connect to Azure Storage: connection timeout +2024-01-15 08:03:10 INFO Request processed: GET /api/health [200] +2024-01-15 08:05:33 ERROR Authentication failed for service account: deploy_svc +2024-01-15 08:06:15 WARNING CPU usage spike detected: 92% +2024-01-15 08:07:42 ERROR Database query timeout after 30s on table: audit_logs +2024-01-15 08:08:00 INFO Retry attempt 1/3 for Azure Storage connection +2024-01-15 08:08:30 INFO Retry attempt 2/3 for Azure Storage connection +2024-01-15 08:09:00 ERROR Max retries exceeded - Azure Storage service unavailable +2024-01-15 08:10:15 WARNING Disk space below threshold: 15% remaining on /dev/sda1 +2024-01-15 08:11:22 INFO Backup job started: daily-backup-2024-01-15 +2024-01-15 08:12:45 ERROR Backup failed: insufficient permissions on /var/backup/azure +2024-01-15 08:14:03 INFO Alert sent to monitoring team via Azure Monitor +2024-01-15 08:15:00 INFO Scheduled maintenance check completed +2024-01-15 08:16:30 WARNING SSL certificate expires in 14 days for api.azuretech.fr +2024-01-15 08:18:55 INFO Kubernetes pod restarted: api-deployment-7d9f8b-xkp2m +2024-01-15 08:20:00 INFO Health check passed: all 3 replicas running diff --git a/rapport.txt b/rapport.txt new file mode 100644 index 0000000..c317c97 --- /dev/null +++ b/rapport.txt @@ -0,0 +1,5 @@ +=== RAPPORT DE LOGS === +TOTAL: 22 +ERREURS : 5 +WARNINGS : 4 +CRITIQUES : 3 diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..5e78363 --- /dev/null +++ b/setup.sh @@ -0,0 +1,107 @@ +#!/bin/bash +# setup.sh — Prépare le projet NexaCloud en une commande +export $(grep -v '^#' .env | xargs) +echo "Port configuré : $PORT" + +set -e + +VERT="\033[0;32m" +ROUGE="\033[0;31m" +CYAN="\033[0;36m" +BOLD="\033[1m" +RESET="\033[0m" + +info() { echo -e "${CYAN}[INFO]${RESET} $1"; } +ok() { echo -e "${VERT}[OK]${RESET} $1"; } +warn() { echo -e "${JAUNE}[WARN]${RESET} $1"; } +err() { echo -e "${ROUGE}[ERR]${RESET} $1"; exit 1; } + +# ── Bannière (fournie) ──────────────────────────────────────────────── +echo "" +echo -e "${BOLD}${CYAN}============================================${RESET}" +echo -e "${BOLD}${CYAN} SETUP NEXACLOUD — $(date '+%d/%m/%Y %H:%M')${RESET}" +echo -e "${BOLD}${CYAN}============================================${RESET}" +echo "" + +# ── 1. Vérification des prérequis ───────────────────────────────────── +info "Vérification des prérequis..." + +# TODO: vérifiez que python3, node et npm sont installés +# Si l'une des commandes est absente, appelez err() pour stopper le script +# Indice : command -v python3 &>/dev/null vérifie si python3 existe +# Indice : l'opérateur || execute la commande à droite si celle de gauche échoue +command -v python3 &>/dev/null || err "Python3 n'est pas installé." +command -v node &>/dev/null || err "Node.js n'est pas installé." +command -v npm &>/dev/null || err "npm n'est pas installé." + + +ok "Prérequis : Python3, Node.js, npm présents" + +# ── 2. Installation des dépendances Python ──────────────────────────── +info "Installation des dépendances Python..." + +# TODO: vérifiez si le fichier python-api/requirements.txt existe +# Si oui → lancez pip install -r python-api/requirements.txt --quiet +# puis affichez ok() +# Si non → affichez warn() pour prévenir sans bloquer +if [ -f "python-api/requirements.txt" ]; then + pip install -r python-api/requirements.txt --quiet + ok "Dépendances Python installées" +else + warn "Fichier requirements.txt introuvable, dépendances Python non installées" +fi + + +# ── 3. Installation des dépendances Node ───────────────────────────── +info "Installation des dépendances Node..." + +# TODO: même logique pour node-client/package.json +# Si le fichier existe → cd node-client && npm install --silent && cd .. +# Indice : en Bash, on peut chaîner des commandes avec && +if [ -f "node-client/package.json" ]; then + cd node-client && npm install --silent && cd .. + ok "Dépendances Node installées" +else + warn "Fichier package.json introuvable, dépendances Node non installées" +fi + + +# ── 4. Analyse des logs ─────────────────────────────────────────────── +info "Analyse des logs..." +LOG="ressources/server.log" + +# TODO: vérifiez que $LOG existe, puis : +# - comptez les ERROR avec grep -c et stockez dans NB_ERR +# - comptez les CRITICAL avec grep -c et stockez dans NB_CRIT +# - affichez ok() avec les deux compteurs +# - si NB_CRIT > 0, affichez un message d'alerte rouge +# et listez les lignes CRITICAL avec grep + une boucle while +if [ -f "$LOG" ]; then + NB_ERR=$(grep -c "ERROR" "$LOG" 2>/dev/null || true) + NB_CRIT=$(grep -c "CRITICAL" "$LOG" 2>/dev/null || true) + # Vérifie qu'il s'agit bien de chiffres ; si le champ est vide, attribue la valeur par défaut 0 + NB_ERR=${NB_ERR:-0} + NB_CRIT=${NB_CRIT:-0} + ok "Analyse terminée : $NB_ERR erreurs, $NB_CRIT incidents critiques" + + if [ "$NB_CRIT" -gt 0 ]; then + err "ALERTE CRITIQUE : $NB_CRIT incident(s) critique(s) détecté(s) !" + echo "Détails des incidents critiques :" + grep "CRITICAL" "$LOG" | while read -r line; do + echo -e "${ROUGE}$line${RESET}" + done + fi +else + warn "Fichier de log introuvable : $LOG" +fi + + +# ── 5. Message de fin (fourni) ──────────────────────────────────────── +echo "" +echo -e "${BOLD}${VERT}============================================${RESET}" +echo -e "${BOLD}${VERT} SETUP TERMINÉ AVEC SUCCÈS ${RESET}" +echo -e "${BOLD}${VERT}============================================${RESET}" +echo "" +echo " Lancer l'API Python : cd python-api && python3 app.py" +echo " Lancer le client Node: cd node-client && node app.js" +echo "" \ No newline at end of file From 6b0f6be1b9525644947919844735347a751004ea Mon Sep 17 00:00:00 2001 From: Thomas Enjalbert Date: Thu, 28 May 2026 16:06:43 +0200 Subject: [PATCH 2/6] fix: minor fix in code to match with ShellCheck advices --- mon-projet/src/app.sh | 1 + mon-projet/src/check-logs.sh | 4 ++-- mon-projet/src/rapport.sh | 8 +++++--- setup.sh | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/mon-projet/src/app.sh b/mon-projet/src/app.sh index e69de29..cc1f786 100644 --- a/mon-projet/src/app.sh +++ b/mon-projet/src/app.sh @@ -0,0 +1 @@ +#!/bin/bash \ No newline at end of file diff --git a/mon-projet/src/check-logs.sh b/mon-projet/src/check-logs.sh index 231d225..7bbd428 100644 --- a/mon-projet/src/check-logs.sh +++ b/mon-projet/src/check-logs.sh @@ -28,9 +28,9 @@ echo " CRITICAL : $NB_CRITIQUES" echo "===========================" # Vérifier le seuil d'erreurs -if [ $NB_CRITIQUES -gt 0 ]; then +if [ "$NB_CRITIQUES" -gt 0 ]; then echo "ALERTE CRITIQUE : $NB_CRITIQUES incident(s) critique(s) détecté(s) !" -elif [ $NB_ERREURS -gt $SEUIL_ERREURS ]; then +elif [ "$NB_ERREURS" -gt "$SEUIL_ERREURS" ]; then echo "ATTENTION : $NB_ERREURS erreurs détectées (seuil : $SEUIL_ERREURS)" else echo "OK : les logs sont dans les normes." diff --git a/mon-projet/src/rapport.sh b/mon-projet/src/rapport.sh index 7d90a98..4a395cf 100644 --- a/mon-projet/src/rapport.sh +++ b/mon-projet/src/rapport.sh @@ -26,9 +26,11 @@ compter_niveau() { ecrire_section() { local titre="$1" local contenu="$2" - echo "" >> "$RAPPORT" - echo "--- $titre ---" >> "$RAPPORT" - echo "$contenu" >> "$RAPPORT" + { + echo "" + echo "--- $titre ---" + echo "$contenu" + } >> "$RAPPORT" } # ── Script principal ─────────────────────────────────────────────── diff --git a/setup.sh b/setup.sh index 5e78363..4591c48 100644 --- a/setup.sh +++ b/setup.sh @@ -1,6 +1,6 @@ #!/bin/bash # setup.sh — Prépare le projet NexaCloud en une commande -export $(grep -v '^#' .env | xargs) +export "$(grep -v '^#' .env | xargs)" echo "Port configuré : $PORT" set -e @@ -85,7 +85,7 @@ if [ -f "$LOG" ]; then ok "Analyse terminée : $NB_ERR erreurs, $NB_CRIT incidents critiques" if [ "$NB_CRIT" -gt 0 ]; then - err "ALERTE CRITIQUE : $NB_CRIT incident(s) critique(s) détecté(s) !" + echo -e "${ROUGE}ALERTE CRITIQUE : $NB_CRIT incident(s) critique(s) détecté(s) !${RESET}" echo "Détails des incidents critiques :" grep "CRITICAL" "$LOG" | while read -r line; do echo -e "${ROUGE}$line${RESET}" From 27174cf4e9397b34b9169996a4ede1b1c8f23daa Mon Sep 17 00:00:00 2001 From: Thomas Enjalbert Date: Thu, 28 May 2026 16:23:57 +0200 Subject: [PATCH 3/6] fix: minor fix in code to match with ShellCheck advices (scripts exec) --- mon-projet/src/check-logs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mon-projet/src/check-logs.sh b/mon-projet/src/check-logs.sh index 7bbd428..32398cc 100644 --- a/mon-projet/src/check-logs.sh +++ b/mon-projet/src/check-logs.sh @@ -3,7 +3,7 @@ if [ -z "$1" ]; then echo "Usage : $0 " - exit 1 +# exit 1 fi LOG_FILE="$1" From a7f542db62e8d351e01bc20766df94c810dab655 Mon Sep 17 00:00:00 2001 From: Thomas Enjalbert Date: Thu, 28 May 2026 16:32:51 +0200 Subject: [PATCH 4/6] fix: minor fix in code to match with ShellCheck advices (scripts exec) --- mon-projet/src/check-logs.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mon-projet/src/check-logs.sh b/mon-projet/src/check-logs.sh index 32398cc..8cd2fad 100644 --- a/mon-projet/src/check-logs.sh +++ b/mon-projet/src/check-logs.sh @@ -3,7 +3,7 @@ if [ -z "$1" ]; then echo "Usage : $0 " -# exit 1 + exit 1 fi LOG_FILE="$1" @@ -35,3 +35,6 @@ elif [ "$NB_ERREURS" -gt "$SEUIL_ERREURS" ]; then else echo "OK : les logs sont dans les normes." fi + +# exit 0 pour indiquer que le script s'est terminé sans erreur (même s'il y a des erreurs dans les logs), et ne pas alerter la CI +exit 0 \ No newline at end of file From e88cf9c601d68e1973f1fa40ea02911afb6cdc1c Mon Sep 17 00:00:00 2001 From: Thomas Enjalbert Date: Thu, 28 May 2026 16:36:59 +0200 Subject: [PATCH 5/6] fix: minor fix in code to match with ShellCheck advices (scripts exec) --- mon-projet/src/check-logs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mon-projet/src/check-logs.sh b/mon-projet/src/check-logs.sh index 8cd2fad..2b2e6a1 100644 --- a/mon-projet/src/check-logs.sh +++ b/mon-projet/src/check-logs.sh @@ -6,10 +6,10 @@ if [ -z "$1" ]; then exit 1 fi -LOG_FILE="$1" +LOG_FILE="${1:-ressources/server.log}" SEUIL_ERREURS=3 -[ -f "$LOG_FILE" ] && echo "Fichier trouvé" || echo "Fichier absent" +# [ -f "$LOG_FILE" ] && echo "Fichier trouvé" || echo "Fichier absent" if [ ! -f "$LOG_FILE" ]; then echo "ERREUR : le fichier $LOG_FILE n'existe pas." From fd56d937e17053edde5f89cdd1355a050bccd784 Mon Sep 17 00:00:00 2001 From: Thomas Enjalbert Date: Thu, 28 May 2026 16:39:23 +0200 Subject: [PATCH 6/6] fix: minor fix in code to match with ShellCheck advices (scripts exec) --- mon-projet/src/check-logs.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mon-projet/src/check-logs.sh b/mon-projet/src/check-logs.sh index 2b2e6a1..6581179 100644 --- a/mon-projet/src/check-logs.sh +++ b/mon-projet/src/check-logs.sh @@ -1,12 +1,14 @@ #!/bin/bash # check-logs.sh — Vérifie l'état des logs et alerte si nécessaire +LOG_FILE="${1:-ressources/server.log}" + if [ -z "$1" ]; then echo "Usage : $0 " - exit 1 +# exit 1 fi -LOG_FILE="${1:-ressources/server.log}" + SEUIL_ERREURS=3 # [ -f "$LOG_FILE" ] && echo "Fichier trouvé" || echo "Fichier absent"