Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1786ab6
Exercice 1.1 — Créer une arborescence de projet
NathanTesseyre May 28, 2026
01f0c2a
Exercice 1.2 — Manipuler les fichiers
NathanTesseyre May 28, 2026
6e73dc3
Exercice 2.1 — Analyser server.log
NathanTesseyre May 28, 2026
65158a0
Exercice 2.2 — Générer un rapport dans un fichier
NathanTesseyre May 28, 2026
11e00a7
Exercice 3.1 — Premier script avec variables
NathanTesseyre May 28, 2026
d67076e
Exercice 3.2 — Script avec conditions sur les logs
NathanTesseyre May 28, 2026
af8f478
Pour aller plus loin — Étape 3
NathanTesseyre May 28, 2026
c7cf1f8
Exercice 4.1 — Boucle sur les niveaux de log
NathanTesseyre May 28, 2026
c920c7b
Exercice 4.2 — Script avec fonctions
NathanTesseyre May 28, 2026
5881e36
Exercice 5.1 — Fonctions d'affichage coloré
NathanTesseyre May 28, 2026
16f0f43
Exercice 5.2 — Script de vérification de l'environnement
NathanTesseyre May 28, 2026
67e78ba
Exercice 5.3 — Assembler le script de setup complet
NathanTesseyre May 28, 2026
224637c
RE: Exercice 5.2 — Script de vérification de l'environnement
NathanTesseyre May 28, 2026
f70b862
RE: Exercice 5.3 — Assembler le script de setup complet & Pour aller …
NathanTesseyre May 28, 2026
205bf2a
Corrections retours ShellCheck
NathanTesseyre May 28, 2026
9d0c3d0
Corrections retours ShellCheck
NathanTesseyre May 28, 2026
6777fa6
Corrections retours ShellCheck
NathanTesseyre May 28, 2026
85f4bd0
Corrections retours ShellCheck
NathanTesseyre May 28, 2026
f5ea887
Bonus 1 — Créer et gérer des ressources avec Azure CLI
NathanTesseyre May 29, 2026
b75bfc2
Bonus 2 — Script Azure : créer un compte de stockage et uploader un f…
NathanTesseyre May 29, 2026
ed8000a
Bonus 3 — Azure Key Vault : gérer des secrets
NathanTesseyre May 29, 2026
3abb7e7
Create VM
NathanTesseyre May 29, 2026
a0b40f2
Add shebangs
NathanTesseyre May 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LOG=ressources/server.log
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ az account set --subscription "Nom ou ID de l'abonnement"

```bash
# Variables réutilisables
RESOURCE_GROUP="rg-nexacloud-tp"
RESOURCE_GROUP="ntesseyreRG"
LOCATION="francecentral"
STORAGE_ACCOUNT="stnexacloud$RANDOM" # Nom unique obligatoire

Expand Down Expand Up @@ -900,7 +900,7 @@ Créez `mon-projet/src/azure-storage.sh` :

set -e

RESOURCE_GROUP="rg-nexacloud-tp"
RESOURCE_GROUP="ntesseyreRG"
LOCATION="francecentral"
STORAGE_ACCOUNT="stnexacloud$RANDOM"
CONTAINER="logs"
Expand Down
23 changes: 23 additions & 0 deletions mon-projet/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Mon projet Bash

# 1. Combien de lignes contient server.log ?
wc -l server.log

# 2. Affichez uniquement les 5 premières lignes
head -n 5 server.log

# 3. Affichez uniquement les 3 dernières lignes
tail -n 3 server.log

# 4. Combien de lignes contiennent le mot ERROR ?
grep -c "ERROR" server.log

# 5. Affichez toutes les lignes WARNING
grep "WARNING" server.log

# 6. Affichez toutes les lignes CRITICAL
grep "CRITICAL" server.log

# 7. Combien d'erreurs ET de critiques y a-t-il au total ?
# (indice : grep -E "ERROR|CRITICAL")
grep -cE "ERROR|CRITICAL" server.log
Empty file added mon-projet/config/settings.txt
Empty file.
5 changes: 5 additions & 0 deletions mon-projet/erreurs.txt
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions mon-projet/logs/app.log
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions mon-projet/logs/app.log.bak
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions mon-projet/logs/rapport-20260528-101428.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
RAPPORT D'ANALYSE — 28/05/2026 10:14

--- 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
5 changes: 5 additions & 0 deletions mon-projet/rapport.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== RAPPORT DE LOGS ===
22 ../ressources/server.log
0
4
3
14 changes: 14 additions & 0 deletions mon-projet/src/analyse-niveaux.sh
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions mon-projet/src/app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/bash
26 changes: 26 additions & 0 deletions mon-projet/src/azure-create-vm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
RESOURCE_GROUP="ntesseyreRG"
VM_NAME="vm-nexacloud-tp"
VM_IMAGE="Ubuntu2204"
VM_SIZE="Standard_D2s_v3"

# Créer une VM avec clé SSH générée automatiquement
az vm create \
--resource-group "$RESOURCE_GROUP" \
--name "$VM_NAME" \
--image "$VM_IMAGE" \
--size "$VM_SIZE" \
--location "swedencentral" \
--admin-username "debian" \
--generate-ssh-keys \
--output json

# Récupérer l'IP publique
IP=$(az vm show \
--resource-group "$RESOURCE_GROUP" \
--name "$VM_NAME" \
--show-details \
--query "publicIps" \
--output tsv)

echo "IP de la VM : $IP"
28 changes: 28 additions & 0 deletions mon-projet/src/azure-key-vault.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
KEYVAULT_NAME="kv-nexacloud-$RANDOM"

# Créer le Key Vault
az keyvault create \
--name "$KEYVAULT_NAME" \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION"

# Ajouter un secret
az keyvault secret set \
--vault-name "$KEYVAULT_NAME" \
--name "db-password" \
--value "MonMotDePasse123!"

# 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)"

# Lister tous les secrets
az keyvault secret list \
--vault-name "$KEYVAULT_NAME" \
--output table
60 changes: 60 additions & 0 deletions mon-projet/src/azure-storage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
# azure-storage.sh — Crée un compte de stockage et uploade server.log

set -e

RESOURCE_GROUP="ntesseyreRG"
LOCATION="francecentral"
STORAGE_ACCOUNT="stnexacloud$RANDOM"
CONTAINER="logs"
FICHIER_LOCAL="ressources/server.log"
FICHIER_BLOB="server.log"

echo "=== Création du compte de stockage Azure ==="

# Créer le compte de stockage
az storage account create \
--name "$STORAGE_ACCOUNT" \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION" \
--sku Standard_LRS \
--kind StorageV2 \
--output none

echo "Compte créé : $STORAGE_ACCOUNT"

# Récupérer la clé de connexion
CLE=$(az storage account keys list \
--resource-group "$RESOURCE_GROUP" \
--account-name "$STORAGE_ACCOUNT" \
--query "[0].value" \
--output tsv)

# Créer un conteneur
az storage container create \
--name "$CONTAINER" \
--account-name "$STORAGE_ACCOUNT" \
--account-key "$CLE" \
--output none

echo "Conteneur créé : $CONTAINER"

# Uploader server.log
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"

# Lister les blobs du conteneur
echo ""
echo "=== Contenu du conteneur ==="
az storage blob list \
--container-name "$CONTAINER" \
--account-name "$STORAGE_ACCOUNT" \
--account-key "$CLE" \
--output table
57 changes: 57 additions & 0 deletions mon-projet/src/check-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/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
}

verifier_fichier() {
local nom_fichier="$1"
if [ -f "$nom_fichier" ]; then
ok "$nom_fichier existe"
else
warn "$nom_fichier 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"
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"

verifier_fichier "config.json"
verifier_fichier "ressources/server.log"

echo ""
echo "=== Vérification terminée ==="
echo ""
37 changes: 37 additions & 0 deletions mon-projet/src/check-logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# check-logs.sh — Vérifie l'état des logs et alerte si nécessaire

SEUIL_ERREURS=3

LOG_FILE="${1:-ressources/server.log}"

if [ -z "$1" ]; then
echo "Pas de fichier de log spécifié, utilisation du fichier $LOG_FILE"
fi

if [ -f "$LOG_FILE" ]; then
echo "Fichier $LOG_FILE trouvé"
else
echo "Fichier $LOG_FILE absent"
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
25 changes: 25 additions & 0 deletions mon-projet/src/couleurs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/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() doit afficher en jaune avec le préfixe [WARN]
warn() { echo -e "${JAUNE}[WARN]${RESET} $1"; }
# err() doit afficher en rouge avec le préfixe [ERR]
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"
Loading
Loading