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/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/README.txt b/mon-projet/README.txt new file mode 100644 index 0000000..9ac27f9 --- /dev/null +++ b/mon-projet/README.txt @@ -0,0 +1 @@ +# Mon projet bash 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/rapport-20260528-112546.txt b/mon-projet/logs/rapport-20260528-112546.txt new file mode 100644 index 0000000..235b17b --- /dev/null +++ b/mon-projet/logs/rapport-20260528-112546.txt @@ -0,0 +1,16 @@ +RAPPORT D'ANALYSE — 28/05/2026 11:25 + +--- 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-112627.txt b/mon-projet/logs/rapport-20260528-112627.txt new file mode 100644 index 0000000..f9966c2 --- /dev/null +++ b/mon-projet/logs/rapport-20260528-112627.txt @@ -0,0 +1,16 @@ +RAPPORT D'ANALYSE — 28/05/2026 11:26 + +--- 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..ad62a57 --- /dev/null +++ b/mon-projet/src/app.sh @@ -0,0 +1,2 @@ +#!/bin/bash +# setup.sh — Prépare le projet NexaCloud en une commande \ 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..9972b48 --- /dev/null +++ b/mon-projet/src/check-env.sh @@ -0,0 +1,68 @@ +#!/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" +VIOLET="\033[0;35m" + +ok() { echo -e "${VERT} [OK]${RESET} $1"; } +warn() { echo -e "${JAUNE} [WARN]${RESET} $1"; } +err() { echo -e "${ROUGE} [ERR]${RESET} $1"; } +crit() { echo -e "${VIOLET} [CRIT]${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 "" + +verifier_commande "python3" "Python" +verifier_commande "node" +verifier_commande "npm" "gestionaire de paquets node" +verifier_commande "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" +CONFIG="config.json" +LOGS="ressources/server.log" + +if [ -f "$CONFIG" ]; then + ok "le fichier $CONFIG est bien présent, l'ami" +else + warn "attention" + err "ATTENTION !!" + crit "le fichier $CONFIG n'existe pas !!!!" +fi + +echo "" + +if [ -f "$LOGS" ]; then + ok "le fichier $LOGS est bien présent, l'ami" +else + warn "attention" + err "ATTENTION !!" + crit "le fichier $LOGS n'existe pas !!!!" +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..4787e11 --- /dev/null +++ b/mon-projet/src/check-logs.sh @@ -0,0 +1,38 @@ +#!/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 0 +fi + +if [ ! -f "$LOG_FILE" ]; then + echo "ERREUR : le fichier $LOG_FILE n'existe pas." + exit 1 +else + [ -f "$LOG_FILE" ] && echo "Fichier trouvé" || echo "Fichier absent" +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) !" +fi +if [ "$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..3eea77d --- /dev/null +++ b/mon-projet/src/couleurs.sh @@ -0,0 +1,23 @@ +#!/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" +VIOLET="\033[0;35m" +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"; } +crit() { echo -e "${VIOLET}[CRIT]${RESET} $1"; } + +# 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" +crit "LE SERVEUR A EXPLOSÉ !! AVEC DU FEU ET TOUT" \ 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..12efcfe --- /dev/null +++ b/mon-projet/src/rapport.sh @@ -0,0 +1,57 @@ +#!/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 "" + echo "--- $titre ---" + 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..cdb66bc --- /dev/null +++ b/rapport.txt @@ -0,0 +1,5 @@ +=== RAPPORT DE LOGS === +nombre total de lignes +nombre d'erreurs +nombre de warnings +nombre de critiques diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..b9f8031 --- /dev/null +++ b/setup.sh @@ -0,0 +1,129 @@ +#!/bin/bash +# setup.sh — Prépare le projet NexaCloud en une commande +# Don't warn about unreachable commands in this file +# shellcheck disable=SC2317 + +set -e + +JAUNE="\033[0;33m" +VERT="\033[0;32m" +ROUGE="\033[0;31m" +CYAN="\033[0;36m" +VIOLET="\033[0;35m" +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; } +crit() { echo -e "${VIOLET}[CRIT]${RESET} $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..." + +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é" + exit 1 + fi +} + +echo "" +echo "=== Vérification de l'environnement NexaCloud ===" +echo "" + +verifier_commande "python3" "Python" +verifier_commande "node" +verifier_commande "npm" "gestionaire de paquets node" +verifier_commande "git" + +echo "" + + +ok "Prérequis : Python3, Node.js, npm présents" + +# ── 2. Installation des dépendances Python ──────────────────────────── +info "Installation des dépendances Python..." + +REQUIREMENT=python-api/requirements.txt +if [ ! -f "$REQUIREMENT" ]; then + warn "Les requirement python n'existent pas" +else + pip install -r python-api/requirements.txt --quiet + ok +fi + +echo "" + + + +# ── 3. Installation des dépendances Node ───────────────────────────── +info "Installation des dépendances Node..." + +PACKAGE=python-api/requirements.txt +if [ ! -f "$PACKAGE" ]; then + warn "Le package node n'existe pas" +else + cd node-client && npm install --silent && cd .. + ok +fi + +echo "" + + + +# ── 4. Analyse des logs ─────────────────────────────────────────────── +info "Analyse des logs..." +LOG="ressources/server.log" + +[ -f "$LOG" ] && echo "Fichier log trouvé" || echo "Fichier log absent" +NB_ERR=$(grep -c "ERROR" "$LOG") +NB_CRIT=$(grep -c "CRITICAL" "$LOG") +ok "nombre d'erreurs: $NB_ERR \n nombre d'errurs critiques: $NB_CRIT" +if [ "$NB_CRIT" -gt 0 ]; then + echo "ALERTE CRITIQUE : $NB_CRIT incident(s) critique(s) détecté(s) !" + echo "incidents critiques sur les lignes :" + + COMPTEUR=0 + while [ "$COMPTEUR" -le "$NB_CRIT" ]; do + grep -n -m"$COMPTEUR" "CRITICAL" ressources/server.log | cut -f1 -d: | tail -n1 + COMPTEUR=$((COMPTEUR + 1)) + done +fi + + + +# ── 5. Message de fin (fourni) ──────────────────────────────────────── +echo "" +echo -e "${BOLD}${VERT}============================================${RESET}" +echo -e "${BOLD}${VERT} SLIP 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 "" + +# Créer un fichier .env pour stocker la configuration +echo "PORT=5001" > .env +echo "ENV=development" >> .env + +# Charger les variables du .env dans le script +# (grep ignore les lignes commentées, xargs les exporte) +export "$(grep -v '^#' .env | xargs)" +echo "Port configuré : $PORT" + +exit 0 \ No newline at end of file