diff --git a/.gitignore b/.gitignore index 4f30f55..976e474 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,6 @@ terraform.rc # Optional: ignore plan files saved before destroying Terraform configuration # Uncomment the line below if you want to ignore planout files. -# planout \ No newline at end of file +# planout + +.env \ No newline at end of file diff --git a/mon-projet/README.txt b/mon-projet/README.txt new file mode 100644 index 0000000..f7fb7de --- /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-150040.txt b/mon-projet/logs/rapport-20260528-150040.txt new file mode 100644 index 0000000..1865ded --- /dev/null +++ b/mon-projet/logs/rapport-20260528-150040.txt @@ -0,0 +1,16 @@ +RAPPORT D'ANALYSE — 28/05/2026 15:00 + +--- 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/rapports/error.txt b/mon-projet/rapports/error.txt new file mode 100644 index 0000000..5aac72f --- /dev/null +++ b/mon-projet/rapports/error.txt @@ -0,0 +1,7 @@ +=== ERROR LINES === + +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/rapports/rapport.txt b/mon-projet/rapports/rapport.txt new file mode 100644 index 0000000..3bc1264 --- /dev/null +++ b/mon-projet/rapports/rapport.txt @@ -0,0 +1,9 @@ +=== LOGS REPORTS === + +Number of lines : 22 + +Errors : 5 + +Warnings : 4 + +Critical : 3 diff --git a/mon-projet/src/analyse-niveaux.sh b/mon-projet/src/analyse-niveaux.sh new file mode 100644 index 0000000..77e30d0 --- /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" diff --git a/mon-projet/src/app.sh b/mon-projet/src/app.sh new file mode 100644 index 0000000..a9bf588 --- /dev/null +++ b/mon-projet/src/app.sh @@ -0,0 +1 @@ +#!/bin/bash diff --git a/mon-projet/src/azure-keyvault.sh b/mon-projet/src/azure-keyvault.sh new file mode 100644 index 0000000..d8ff0d4 --- /dev/null +++ b/mon-projet/src/azure-keyvault.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# Source le fichier environnement +source "$(dirname "$0")/.env" + +function createKeyVault(){ +set -e +# Créer le Key Vault +az keyvault create \ + --name "$KEYVAULT_NAME" \ + --resource-group "$RESOURCE_GROUP" \ + --location "$LOCATION" +} + +function AddSecretKey(){ +# Ajouter un secret +az keyvault secret set \ + --vault-name "$KEYVAULT_NAME" \ + --name "db-password" \ + --value "$DBPassword" +} + +function CatchSecret(){ +# Récupérer un secret dans un script +SECRET=$(az keyvault secret show \ + --vault-name "$KEYVAULT_NAME" \ + --name "db-password" \ + --query "value" \ + --output tsv) + echo "Secret récupéré (longueur : ${#SECRET} caractères)" +} + +function ListSecret(){ +# Lister tous les secrets +az keyvault secret list \ + --vault-name "$KEYVAULT_NAME" \ + --output table +} + +function main(){ + createKeyVault + AddSecretKey + CatchSecret + ListSecret +} + +main \ No newline at end of file diff --git a/mon-projet/src/azure-storage.sh b/mon-projet/src/azure-storage.sh new file mode 100644 index 0000000..f17b94a --- /dev/null +++ b/mon-projet/src/azure-storage.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# Ce script permet de créer un compte de stockage et uploade server.log + +set -e + +RESOURCE_GROUP="mpetitRG" +LOCATION="francecentral" +STORAGE_ACCOUNT="mpstorageaccount$RANDOM" +CONTAINER="logs" +FICHIER_LOCAL="ressources/server.log" +FICHIER_BLOB="server.log" + +create_storage_account() { + echo "=== Creation du compte de stockage Azure ===" + az storage account create \ + --name "$STORAGE_ACCOUNT" \ + --resource-group "$RESOURCE_GROUP" \ + --location "$LOCATION" \ + --sku Standard_LRS \ + --kind StorageV2 \ + --output none + echo "Compte cree : $STORAGE_ACCOUNT" +} + +get_storage_key() { + az storage account keys list \ + --resource-group "$RESOURCE_GROUP" \ + --account-name "$STORAGE_ACCOUNT" \ + --query "[0].value" \ + --output tsv +} + +create_container() { + local cle="$1" + az storage container create \ + --name "$CONTAINER" \ + --account-name "$STORAGE_ACCOUNT" \ + --account-key "$cle" \ + --output none + echo "Conteneur créé : $CONTAINER" +} + +upload_blob() { + local cle="$1" + az storage blob upload \ + --container-name "$CONTAINER" \ + --file "$FICHIER_LOCAL" \ + --name "$FICHIER_BLOB" \ + --account-name "$STORAGE_ACCOUNT" \ + --account-key "$cle" \ + --output none + echo "Fichier uploadé : $FICHIER_BLOB" +} + +list_blobs() { + local cle="$1" + echo "" + echo "=== Contenu du conteneur ===" + az storage blob list \ + --container-name "$CONTAINER" \ + --account-name "$STORAGE_ACCOUNT" \ + --account-key "$cle" \ + --output table +} + +main() { + create_storage_account + CLE=$(get_storage_key) + create_container "$CLE" + upload_blob "$CLE" + list_blobs "$CLE" +} + +main diff --git a/mon-projet/src/azure-vm.sh b/mon-projet/src/azure-vm.sh new file mode 100644 index 0000000..98ba9db --- /dev/null +++ b/mon-projet/src/azure-vm.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +# Génère un nom de VM unique en ajoutant un nombre aléatoire +VM_NAME="mpetitvm$RANDOM" +VM_IMAGE="Ubuntu2204" +ADMIN_USER="mpetit" +SSH_DIR="$(dirname "$0")/SSH-Keys/${VM_NAME}" +# Chemin vers la clé SSH : sans extension = clé privée, avec .pub = clé publique +SSH_KEY_PATH="${SSH_DIR}/${VM_NAME}" + +# Source le fichier environnement +source "$(dirname "$0")/.env" + +function selectSmallestVMSize(){ + # Filtre les tailles sans restrictions, extrait nom et vCPUs, trie numériquement, prend la plus petite + SMALLESTVM=$(az vm list-skus \ + --location "$LOCATION" \ + --resource-type "virtualMachines" \ + --query "[?length(restrictions)==\`0\`].{name:name, cpus:capabilities[?name=='vCPUs'].value|[0]}" \ + --output tsv \ + | sort -t$'\t' -k2 -n \ + | head -1 \ + | cut -f1) + + # Si SMALLESTVM est vide, utilise Standard_B1s comme valeur par défaut + echo "Taille sélectionnée : ${SMALLESTVM:-Standard_B1s}" +} + +function generateSSHKey(){ + # Crée le dossier SSH-Keys// si inexistant (-p évite l'erreur s'il existe déjà) + mkdir -p "$SSH_DIR" + chmod 600 "$SSH_DIR" + # Génère une paire de clés RSA 4096 bits, sans passphrase (-N ""), en mode silencieux (-q) + ssh-keygen -t rsa -b 4096 -f "$SSH_KEY_PATH" -N "" -q + # SSH refuse les clés avec des permissions trop ouvertes : 600 = lecture/écriture propriétaire uniquement + chmod 600 "$SSH_KEY_PATH" + echo "Clé SSH générée : $SSH_KEY_PATH" +} + +function saveVMEnv(){ + # Heredoc : écrit le bloc jusqu'à EOF dans le fichier .env, les variables sont évaluées immédiatement + cat > "${SSH_DIR}/.env" << EOF +VM_NAME="$VM_NAME" +RESOURCE_GROUP="$RESOURCE_GROUP" +IP="$IP" +ADMIN_USER="$ADMIN_USER" +SSH_KEY_PATH="$SSH_KEY_PATH" +EOF + echo "Infos VM sauvegardées dans ${SSH_DIR}/.env" +} + +function vmCreate(){ + # Fournit la clé publique (.pub) à Azure pour qu'elle soit installée sur la VM à la création + az vm create \ + --resource-group "$RESOURCE_GROUP" \ + --name "$VM_NAME" \ + --image "$VM_IMAGE" \ + --size "$SMALLESTVM" \ + --admin-username "$ADMIN_USER" \ + --ssh-key-value "${SSH_KEY_PATH}.pub" \ + --output json +} + +function catchVMPublicIP(){ + # --show-details charge les infos réseau, --query extrait uniquement l'IP publique du JSON + # tr -d '\r' supprime les retours chariot (\r) que l'Azure CLI ajoute sous WSL + IP=$(az vm show \ + --resource-group "$RESOURCE_GROUP" \ + --name "$VM_NAME" \ + --show-details \ + --query "publicIps" \ + --output tsv | tr -d '\r') + + echo "IP de la VM : $IP" +} + +function connectVM(){ + # -i indique à SSH quelle clé privée utiliser pour s'authentifier + ssh -i "$SSH_KEY_PATH" "$ADMIN_USER@$IP" +} + +function main(){ + selectSmallestVMSize + generateSSHKey + vmCreate + catchVMPublicIP + saveVMEnv + connectVM +} + +main diff --git a/mon-projet/src/check-env.sh b/mon-projet/src/check-env.sh new file mode 100644 index 0000000..43e5ee8 --- /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 "" + +# Appele verifier_commande pour tester python3, node, npm et git +for cmd in python3 node npm git; do + verifier_commande "$cmd" +done + + +echo "" + +# Vérifie que ces deux fichiers existent avec [ -f ] + +for fichier in "config.json" "ressources/server.log"; do + if [ -f "$fichier" ]; then + ok "Fichier $fichier trouvé" + else + warn "Fichier $fichier introuvable" + fi +done + + +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..362765f --- /dev/null +++ b/mon-projet/src/check-logs.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# check-logs.sh — Vérifie l'état des logs et alerte si nécessaire + +SEUIL_ERREURS=3 + +function check_logs() { + local log_file="$1" + + 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 "===========================" + + 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 +} + +main() { + local log_file="${1:-ressources/server.log}" + check_logs "$log_file" +} + +main "$@" \ 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..2705333 --- /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" +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"; } + +# TODO: écrivez les fonctions warn() et err() sur le même modèle +warn() { echo -e "${JAUNE}[WARN]${RESET} $1"; } +err() { echo -e "${ROUGE}[ERR]${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" diff --git a/mon-projet/src/info.sh b/mon-projet/src/info.sh new file mode 100644 index 0000000..69c1a07 --- /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 "===============================" diff --git a/mon-projet/src/rapport.sh b/mon-projet/src/rapport.sh new file mode 100644 index 0000000..750dc10 --- /dev/null +++ b/mon-projet/src/rapport.sh @@ -0,0 +1,53 @@ +#!/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/script_rapport.sh b/script_rapport.sh new file mode 100644 index 0000000..8470eb0 --- /dev/null +++ b/script_rapport.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Put the absolut path of the server log file in this variable +SERVER_LOG_PATH="ressources/server.log" + +function rapport_list_generator(){ +echo -e "=== LOGS REPORTS ===\n +Number of lines : $(wc -l < $SERVER_LOG_PATH)\n +Errors : $(grep -c 'ERROR' $SERVER_LOG_PATH)\n +Warnings : $(grep -c 'WARNING' $SERVER_LOG_PATH)\n +Critical : $(grep -c 'CRITICAL' $SERVER_LOG_PATH)" > rapport.txt + +echo -e "=== ERROR LINES ===\n +$(grep 'ERROR' $SERVER_LOG_PATH)" > error.txt + +} + +function main(){ + +rapport_list_generator + +echo "Rapport generated successfully. Check rapport.txt and error.txt for details." +} + +main \ No newline at end of file diff --git a/server-log.md b/server-log.md new file mode 100644 index 0000000..86650cd --- /dev/null +++ b/server-log.md @@ -0,0 +1,81 @@ +# 1. Combien de lignes contient server.log ? + +```bash +wc -l ressources/server.log +``` + +``` +22 +``` + +# 2. Affichez uniquement les 5 premières lignes + +```bash +head -n 5 ressources/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 + +```bash +tail -n 3 ressources/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 ? + +```bash +grep -c "ERROR" ressources/server.log +``` + +``` +5 +``` + +# 5. Affichez toutes les lignes WARNING + +```bash +grep "WARNING" ressources/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 + +```bash +grep "CRITICAL" ressources/server.log +``` + +``` +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 ? + +```bash +grep -c "ERROR" ressources/server.log && grep -c "CRITICAL" ressources/server.log +``` + +``` +5 +3 +``` diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..cce8f9e --- /dev/null +++ b/setup.sh @@ -0,0 +1,81 @@ +#!/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" + +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..." + +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..." + +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 introuvable — étape ignorée" +fi + +# ── 3. Installation des dépendances Node ───────────────────────────── +info "Installation des dépendances Node..." + +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 introuvable — étape ignorée" +fi + +# ── 4. Analyse des logs ─────────────────────────────────────────────── +info "Analyse des logs..." +LOG="ressources/server.log" + +if [ ! -f "$LOG" ]; then + warn "Fichier de log introuvable : $LOG" +else + NB_ERR=$(grep -c "ERROR" "$LOG") + NB_CRIT=$(grep -c "CRITICAL" "$LOG") + ok "Logs analysés — ERROR: $NB_ERR CRITICAL: $NB_CRIT" + + if [ "$NB_CRIT" -gt 0 ]; then + echo -e "${ROUGE} ALERTE : $NB_CRIT incident(s) critique(s) détecté(s) :${RESET}" + grep "CRITICAL" "$LOG" | while read -r ligne; do + echo " $ligne" + done + fi +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 ""