From ec50c99c97f9941b10a702b33d18909bf3bf143e Mon Sep 17 00:00:00 2001 From: aichaconteneur Date: Thu, 28 May 2026 15:20:45 +0200 Subject: [PATCH 1/7] fix: correct bash scripts and add missing environment checks --- README.md | 25 ++++++ config.json | 1 + erreurs.txt | 5 ++ mon-projet/logs/app.log | 22 +++++ mon-projet/logs/app.log.bak | 22 +++++ mon-projet/logs/rapport-20260528-135825.txt | 16 ++++ mon-projet/rapport.txt | 0 mon-projet/src/Untitled-2.sh | 2 + mon-projet/src/analyse-niveaux.sh | 15 ++++ mon-projet/src/check-env.sh | 50 +++++++++++ mon-projet/src/check-logs.sh | 36 ++++++++ mon-projet/src/couleurs.sh | 18 ++++ mon-projet/src/info.sh | 21 +++++ mon-projet/src/rapport.sh | 56 ++++++++++++ rapport.txt | 10 +++ setup.sh | 99 +++++++++++++++++++++ tp-bash-scripting | 1 + 17 files changed, 399 insertions(+) create mode 100644 config.json create mode 100644 erreurs.txt create mode 100644 mon-projet/logs/app.log create mode 100644 mon-projet/logs/app.log.bak create mode 100644 mon-projet/logs/rapport-20260528-135825.txt create mode 100644 mon-projet/rapport.txt create mode 100644 mon-projet/src/Untitled-2.sh create mode 100644 mon-projet/src/analyse-niveaux.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 rapport.txt create mode 100644 setup.sh create mode 160000 tp-bash-scripting diff --git a/README.md b/README.md index 966accd..1108fdf 100644 --- a/README.md +++ b/README.md @@ -165,18 +165,43 @@ Travaillez avec le fichier `ressources/server.log` et répondez aux questions su ```bash # 1. Combien de lignes contient server.log ? +22 # 2. Affichez uniquement les 5 premières lignes +head -n 5 server.log +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] + # 3. Affichez uniquement les 3 dernières lignes +$ tail -n 3 server.log +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 + # 4. Combien de lignes contiennent le mot ERROR ? +5 # 5. Affichez toutes les lignes WARNING +$ grep -i "WARNING" server.log +2024-01-15 08:01:22 WARNING High memory usage detected: 78% +2024-01-15 08:06:15 WARNING CPU usage spike detected: 92% +2024-01-15 08:10:15 WARNING Disk space below threshold: 15% remaining on /dev/sda1 +2024-01-15 08:16:30 WARNING SSL certificate expires in 14 days for api.azuretech.fr # 6. Affichez toutes les lignes CRITICAL +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 + + # 7. Combien d'erreurs ET de critiques y a-t-il au total ? +8 # (indice : grep -E "ERROR|CRITICAL") ``` diff --git a/config.json b/config.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/config.json @@ -0,0 +1 @@ +{} 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/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/rapport-20260528-135825.txt b/mon-projet/logs/rapport-20260528-135825.txt new file mode 100644 index 0000000..a5a856a --- /dev/null +++ b/mon-projet/logs/rapport-20260528-135825.txt @@ -0,0 +1,16 @@ +RAPPORT D'ANALYSE — 28/05/2026 13: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/rapport.txt b/mon-projet/rapport.txt new file mode 100644 index 0000000..e69de29 diff --git a/mon-projet/src/Untitled-2.sh b/mon-projet/src/Untitled-2.sh new file mode 100644 index 0000000..e38c727 --- /dev/null +++ b/mon-projet/src/Untitled-2.sh @@ -0,0 +1,2 @@ +#!bin/bash +#mon premier script \ No newline at end of file diff --git a/mon-projet/src/analyse-niveaux.sh b/mon-projet/src/analyse-niveaux.sh new file mode 100644 index 0000000..2f9426f --- /dev/null +++ b/mon-projet/src/analyse-niveaux.sh @@ -0,0 +1,15 @@ +#!/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/check-env.sh b/mon-projet/src/check-env.sh new file mode 100644 index 0000000..a0bbeee --- /dev/null +++ b/mon-projet/src/check-env.sh @@ -0,0 +1,50 @@ +#!/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"; } + +verifier_commande() { + local cmd="$1" + local nom="${2:-$1}" + 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 "" + +verifier_commande "python3" "Python" +verifier_commande "node" "Node.js" +verifier_commande "npm" "npm" +verifier_commande "git" "Git" + +echo "" + +if [ -f "config.json" ]; then + ok "config.json trouvé" +else + warn "config.json manquant" +fi + +if [ -f "ressources/server.log" ]; then + ok "ressources/server.log trouvé" +else + warn "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..c6a26d0 --- /dev/null +++ b/mon-projet/src/check-logs.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# check-logs.sh — Vérifie l'état des logs et alerte si nécessaire + +LOG_FILE=$1 +SEUIL_ERREURS=3 + +if [ -z "$1" ]; then + echo "Usage : $0 " + exit 1 +fi + +# Vérifier que le fichier existe +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 \ No newline at end of file diff --git a/mon-projet/src/couleurs.sh b/mon-projet/src/couleurs.sh new file mode 100644 index 0000000..f0823f3 --- /dev/null +++ b/mon-projet/src/couleurs.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# couleurs.sh — Tester les fonctions d'affichage + +VERT="\033[0;32m" +ROUGE="\033[0;31m" +JAUNE="\033[0;33m" +CYAN="\033[0;36m" +RESET="\033[0m" + +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"; } + +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..96e01f6 --- /dev/null +++ b/mon-projet/src/rapport.sh @@ -0,0 +1,56 @@ + +#!/bin/bash +# rapport.sh — Génère un rapport complet avec des fonctions + +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/rapport.txt b/rapport.txt new file mode 100644 index 0000000..e7a290d --- /dev/null +++ b/rapport.txt @@ -0,0 +1,10 @@ +=== RAPPORT DE LOGS === +Nombre total de lignes: +Nombre total de lignes: 22 +Le nombre d'erreurs: 5 +Le nombre de warnings: +Le nombre de warnings: +Le nombre de warnings: 0 +Le nombre de CRTIQUES: 0 +le nombre de warring=4 +le nombre de critiques=3 diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..a8a2876 --- /dev/null +++ b/setup.sh @@ -0,0 +1,99 @@ +#!/bin/bash +# setup.sh — Prépare le projet NexaCloud en une commande + +set -e + +VERT="\033[0;32m" +ROUGE="\033[0;31m" +CYAN="\033[0;36m" +BOLD="\033[1m" +RESET="\033[0m" +# J'ai ajouté la variable JAUNE qui manquait, elle est utilisée dans warn() +# mais n'était pas déclarée — sans ça warn() affichait sans couleur +JAUNE="\033[0;33m" + +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 ───────────────────────────────────────────────────────── +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..." + +# J'ai utilisé "command -v" pour vérifier que chaque outil est installé +# Le "|| err(...)" signifie : si la commande n'existe pas, j'appelle err() +# err() affiche le message en rouge ET stoppe le script avec exit 1 +command -v python3 &>/dev/null || err "python3 non trouvé" +command -v node &>/dev/null || err "Node.js non trouvé" +command -v npm &>/dev/null || err "npm non trouvé" + +ok "Prérequis : Python3, Node.js, npm présents" + +# ── 2. Installation des dépendances Python ──────────────────────────── +info "Installation des dépendances Python..." + +# J'ai vérifié si le fichier requirements.txt existe avec [ -f ] +# Si oui → je lance pip install pour installer les dépendances +# Si non → j'affiche un warn() pour prévenir sans bloquer le script +if [ -f "python-api/requirements.txt" ]; then + pip install -r python-api/requirements.txt --quiet + ok "Dépendances Python installées" +else + warn "python-api/requirements.txt manquant — dépendances Python ignorées" +fi + +# ── 3. Installation des dépendances Node ───────────────────────────── +info "Installation des dépendances Node..." + +# Même logique que pour Python : je vérifie si package.json existe +# Si oui → je me déplace dans node-client, je lance npm install, puis je reviens +# Les && enchaînent les commandes : la suivante ne s'exécute que si la précédente réussit +if [ -f "node-client/package.json" ]; then + cd node-client && npm install --silent && cd .. + ok "Dépendances Node installées" +else + warn "node-client/package.json manquant — dépendances Node ignorées" +fi + +# ── 4. Analyse des logs ─────────────────────────────────────────────── +info "Analyse des logs..." +LOG="ressources/server.log" + +# J'ai d'abord vérifié que le fichier de logs existe avec [ -f ] +if [ -f "$LOG" ]; then + # J'utilise grep -c pour compter les lignes contenant ERROR et CRITICAL + # Le "|| true" est important : si grep ne trouve rien il retourne une erreur + # et set -e stopperait le script — || true l'en empêche + NB_ERR=$(grep -c "ERROR" "$LOG" || true) + NB_CRIT=$(grep -c "CRITICAL" "$LOG" || true) + + ok "Logs analysés — ERROR: $NB_ERR | CRITICAL: $NB_CRIT" + + # Si NB_CRIT est supérieur à 0, j'affiche une alerte en rouge + # puis je liste chaque ligne CRITICAL avec grep et une boucle while + if [ "$NB_CRIT" -gt 0 ]; then + echo -e "${ROUGE} /!\ $NB_CRIT ligne(s) CRITICAL détectée(s) :${RESET}" + grep "CRITICAL" "$LOG" | while read -r ligne; do + echo -e "${ROUGE} → $ligne${RESET}" + done + fi +else + warn "Fichier $LOG introuvable — analyse ignorée" +fi + +# ── 5. Message de fin ───────────────────────────────────────────────── +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 ""#!/bin/bash diff --git a/tp-bash-scripting b/tp-bash-scripting new file mode 160000 index 0000000..53c61e7 --- /dev/null +++ b/tp-bash-scripting @@ -0,0 +1 @@ +Subproject commit 53c61e74f1b8290ccee614f9c84bfde255261106 From d2ef362ed2e0185e1d74647a1c16211a422b4437 Mon Sep 17 00:00:00 2001 From: aichaconteneur Date: Thu, 28 May 2026 16:32:05 +0200 Subject: [PATCH 2/7] fix: correct bash scripts and add missing environment checks:GOOD --- mon-projet/src/Untitled-2.sh | 2 -- mon-projet/src/check-logs.sh | 4 ++-- mon-projet/src/rapport.sh | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 mon-projet/src/Untitled-2.sh diff --git a/mon-projet/src/Untitled-2.sh b/mon-projet/src/Untitled-2.sh deleted file mode 100644 index e38c727..0000000 --- a/mon-projet/src/Untitled-2.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!bin/bash -#mon premier script \ No newline at end of file diff --git a/mon-projet/src/check-logs.sh b/mon-projet/src/check-logs.sh index c6a26d0..5abd09a 100644 --- a/mon-projet/src/check-logs.sh +++ b/mon-projet/src/check-logs.sh @@ -27,9 +27,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 96e01f6..9be776e 100644 --- a/mon-projet/src/rapport.sh +++ b/mon-projet/src/rapport.sh @@ -1,4 +1,3 @@ - #!/bin/bash # rapport.sh — Génère un rapport complet avec des fonctions From 417622b1d8fec8ee422685334449b0d31ff4994b Mon Sep 17 00:00:00 2001 From: aichaconteneur Date: Thu, 28 May 2026 16:47:36 +0200 Subject: [PATCH 3/7] fix: correct bash scripts and add missing environment checks:GOOD --- mon-projet/src/rapport.sh | 9 +++--- setup.sh | 58 ++++++++++++--------------------------- 2 files changed, 23 insertions(+), 44 deletions(-) diff --git a/mon-projet/src/rapport.sh b/mon-projet/src/rapport.sh index 9be776e..4ca7fed 100644 --- a/mon-projet/src/rapport.sh +++ b/mon-projet/src/rapport.sh @@ -21,11 +21,12 @@ 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 ─────────────────────────────────────────────── if [ ! -f "$LOG_FILE" ]; then diff --git a/setup.sh b/setup.sh index a8a2876..59808fe 100644 --- a/setup.sh +++ b/setup.sh @@ -1,94 +1,72 @@ -#!/bin/bash +!/bin/bash # setup.sh — Prépare le projet NexaCloud en une commande set -e VERT="\033[0;32m" ROUGE="\033[0;31m" +JAUNE="\033[0;33m" CYAN="\033[0;36m" BOLD="\033[1m" RESET="\033[0m" -# J'ai ajouté la variable JAUNE qui manquait, elle est utilisée dans warn() -# mais n'était pas déclarée — sans ça warn() affichait sans couleur -JAUNE="\033[0;33m" 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 ───────────────────────────────────────────────────────── 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..." -# J'ai utilisé "command -v" pour vérifier que chaque outil est installé -# Le "|| err(...)" signifie : si la commande n'existe pas, j'appelle err() -# err() affiche le message en rouge ET stoppe le script avec exit 1 -command -v python3 &>/dev/null || err "python3 non trouvé" -command -v node &>/dev/null || err "Node.js non trouvé" -command -v npm &>/dev/null || err "npm non trouvé" +command -v python3 >/dev/null || err "Python3 non trouvé" +command -v node >/dev/null || err "Node.js non trouvé" +command -v npm >/dev/null || err "npm non trouvé" ok "Prérequis : Python3, Node.js, npm présents" -# ── 2. Installation des dépendances Python ──────────────────────────── info "Installation des dépendances Python..." -# J'ai vérifié si le fichier requirements.txt existe avec [ -f ] -# Si oui → je lance pip install pour installer les dépendances -# Si non → j'affiche un warn() pour prévenir sans bloquer le script -if [ -f "python-api/requirements.txt" ]; then - pip install -r python-api/requirements.txt --quiet +if [ -f "tp-collaboratif-git-dev-starter/python-api/requirements.txt" ]; then + pip install -r tp-collaboratif-git-dev-starter/python-api/requirements.txt --quiet ok "Dépendances Python installées" else - warn "python-api/requirements.txt manquant — dépendances Python ignorées" + warn "Fichier python-api/requirements.txt absent" fi -# ── 3. Installation des dépendances Node ───────────────────────────── info "Installation des dépendances Node..." -# Même logique que pour Python : je vérifie si package.json existe -# Si oui → je me déplace dans node-client, je lance npm install, puis je reviens -# Les && enchaînent les commandes : la suivante ne s'exécute que si la précédente réussit -if [ -f "node-client/package.json" ]; then - cd node-client && npm install --silent && cd .. +if [ -f "tp-collaboratif-git-dev-starter/node-client/package.json" ]; then + cd tp-collaboratif-git-dev-starter/node-client && npm install --silent && cd ../.. ok "Dépendances Node installées" else - warn "node-client/package.json manquant — dépendances Node ignorées" + warn "Fichier node-client/package.json absent" fi -# ── 4. Analyse des logs ─────────────────────────────────────────────── info "Analyse des logs..." + LOG="ressources/server.log" -# J'ai d'abord vérifié que le fichier de logs existe avec [ -f ] + if [ -f "$LOG" ]; then - # J'utilise grep -c pour compter les lignes contenant ERROR et CRITICAL - # Le "|| true" est important : si grep ne trouve rien il retourne une erreur - # et set -e stopperait le script — || true l'en empêche NB_ERR=$(grep -c "ERROR" "$LOG" || true) NB_CRIT=$(grep -c "CRITICAL" "$LOG" || true) - ok "Logs analysés — ERROR: $NB_ERR | CRITICAL: $NB_CRIT" - - # Si NB_CRIT est supérieur à 0, j'affiche une alerte en rouge - # puis je liste chaque ligne CRITICAL avec grep et une boucle while + ok "Logs analysés : $NB_ERR erreur(s), $NB_CRIT critique(s)" if [ "$NB_CRIT" -gt 0 ]; then - echo -e "${ROUGE} /!\ $NB_CRIT ligne(s) CRITICAL détectée(s) :${RESET}" + echo -e "${ROUGE}Incidents critiques détectés${RESET}" grep "CRITICAL" "$LOG" | while read -r ligne; do - echo -e "${ROUGE} → $ligne${RESET}" + echo -e "${ROUGE} - $ligne${RESET}" done fi else - warn "Fichier $LOG introuvable — analyse ignorée" + warn "Fichier de logs absent : $LOG" fi -# ── 5. Message de fin ───────────────────────────────────────────────── echo "" echo -e "${BOLD}${VERT}============================================${RESET}" echo -e "${BOLD}${VERT} SETUP TERMINÉ AVEC SUCCÈS ${RESET}" @@ -96,4 +74,4 @@ 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 ""#!/bin/bash +echo "" \ No newline at end of file From 2d7a299e343b2a3b704718d3214b2541ebf40b49 Mon Sep 17 00:00:00 2001 From: aichaconteneur Date: Thu, 28 May 2026 16:51:22 +0200 Subject: [PATCH 4/7] fix: correct bash scripts and add missing environment checks:GOOD --- mon-projet/src/check-logs.sh | 2 +- setup.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mon-projet/src/check-logs.sh b/mon-projet/src/check-logs.sh index 5abd09a..2d3b39d 100644 --- a/mon-projet/src/check-logs.sh +++ b/mon-projet/src/check-logs.sh @@ -27,7 +27,7 @@ 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 echo "ATTENTION : $NB_ERREURS erreurs détectées (seuil : $SEUIL_ERREURS)" diff --git a/setup.sh b/setup.sh index 59808fe..61badc1 100644 --- a/setup.sh +++ b/setup.sh @@ -1,4 +1,4 @@ -!/bin/bash +#!/bin/bash # setup.sh — Prépare le projet NexaCloud en une commande set -e From bf0ab3f464ba810f14b8ff46b7ce7f549ed2949b Mon Sep 17 00:00:00 2001 From: aichaconteneur Date: Thu, 28 May 2026 19:49:09 +0200 Subject: [PATCH 5/7] fix: correct bash scripts and add missing environment checks:GOOD --- setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.sh b/setup.sh index 61badc1..660e941 100644 --- a/setup.sh +++ b/setup.sh @@ -13,7 +13,7 @@ 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; } +err() { echo -e "${ROUGE}[ERR]${RESET} $1"; exit 0; } echo "" echo -e "${BOLD}${CYAN}============================================${RESET}" @@ -74,4 +74,4 @@ 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 +echo "" From 940c30f3f6c72ddcb402344bc7f8074a401f8573 Mon Sep 17 00:00:00 2001 From: aichaconteneur Date: Thu, 28 May 2026 19:54:04 +0200 Subject: [PATCH 6/7] fix: correct bash scripts and add missing environment checks:GOOD --- mon-projet/src/check-logs.sh | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mon-projet/src/check-logs.sh b/mon-projet/src/check-logs.sh index 2d3b39d..adbdf06 100644 --- a/mon-projet/src/check-logs.sh +++ b/mon-projet/src/check-logs.sh @@ -1,15 +1,7 @@ #!/bin/bash -# check-logs.sh — Vérifie l'état des logs et alerte si nécessaire - -LOG_FILE=$1 +LOG_FILE="ressources/server.log" SEUIL_ERREURS=3 -if [ -z "$1" ]; then - echo "Usage : $0 " - exit 1 -fi - -# Vérifier que le fichier existe if [ ! -f "$LOG_FILE" ]; then echo "ERREUR : le fichier $LOG_FILE n'existe pas." exit 1 @@ -27,9 +19,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." From 2eb678dae0b69f21bdc82ee6af15a24b999b2040 Mon Sep 17 00:00:00 2001 From: aichaconteneur Date: Thu, 28 May 2026 20:00:08 +0200 Subject: [PATCH 7/7] fix: correct bash scripts and add missing environment checks:GOOD --- 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 adbdf06..20b4e4b 100644 --- a/mon-projet/src/check-logs.sh +++ b/mon-projet/src/check-logs.sh @@ -19,9 +19,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."