Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions mon-projet/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Mon projet Bash

# 1. Combien de lignes contient server.log ?


# 2. Affichez uniquement les 5 premières lignes


# 3. Affichez uniquement les 3 dernières lignes

# 4. Combien de lignes contiennent le mot ERROR ?


# 5. Affichez toutes les lignes WARNING


# 6. Affichez toutes les lignes CRITICAL


# 7. Combien d'erreurs ET de critiques y a-t-il au total ?
# (indice : grep -E "ERROR|CRITICAL")


# 1 liner for these commands

echo -e "=== LOGS REPORTS ===\n
Number of lines : $(wc -l < server.log)\n
Errors : $(grep -c 'ERROR' server.log)\n
Warnings : $(grep -c 'WARNING' server.log)\n
Critical : $(grep -c 'CRITICAL' server.log)" > rapport.txt

&&

echo -e "=== ERROR LINES ===\n
$(grep 'ERROR' server.log)" > error.txt
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
Empty file added mon-projet/rapport.txt
Empty file.
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 — Count every level of the 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="asigurRG"
VM_NAME="ubuntuservmc"
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="adri-keyvault-$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 "Root1234@"

# 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="asigurRG"
LOCATION="francecentral"
STORAGE_ACCOUNT="adri-keyvault-$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
50 changes: 50 additions & 0 deletions mon-projet/src/check-env.sh
Original file line number Diff line number Diff line change
@@ -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"; }

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

verifier_commande "python3" "Python"
echo ""

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 — Verify state and if there an error

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
19 changes: 19 additions & 0 deletions mon-projet/src/couleurs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# couleurs.sh — Test function output

# Colors
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"
21 changes: 21 additions & 0 deletions mon-projet/src/info.sh
Original file line number Diff line number Diff line change
@@ -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 "==============================="

# check if the log exist
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 "==============================="
57 changes: 57 additions & 0 deletions mon-projet/src/rapport.sh
Original file line number Diff line number Diff line change
@@ -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"

# write the audit in a file
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"
Loading
Loading