fix : correctif du script
This commit is contained in:
@@ -1,22 +1,21 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
limit=70
|
limit=70
|
||||||
# Mettre le lien de votre webhook Discord dans un .env
|
|
||||||
WEBHOOK_URL=$(grep -E '^WEBHOOK_URL=' .env | cut -d '=' -f2-)
|
WEBHOOK_URL=$(grep -E '^WEBHOOK_URL=' .env | cut -d '=' -f2-)
|
||||||
|
|
||||||
# Récupérer l'utilisation du disque en pourcentage
|
read -r total_bytes used_bytes avail_bytes usage <<<"$(df -B1 / | awk 'NR==2 {gsub(/%/,"",$5); print $2, $3, $4, $5}')"
|
||||||
usage=$(df -h / | awk 'NR==2 {gsub(/%/,"",$5); print $5}')
|
|
||||||
# Calculer l'espace libre en pourcentage
|
|
||||||
free=$((100 - usage))
|
free=$((100 - usage))
|
||||||
|
used_gb=$(awk -v b="$used_bytes" 'BEGIN {printf "%.2f", b/1024/1024/1024}')
|
||||||
|
total_gb=$(awk -v b="$total_bytes" 'BEGIN {printf "%.2f", b/1024/1024/1024}')
|
||||||
|
avail_gb=$(awk -v b="$avail_bytes" 'BEGIN {printf "%.2f", b/1024/1024/1024}')
|
||||||
|
|
||||||
# Si l'utilisation dépasse la limite, envoyer une alerte sur Discord
|
|
||||||
if [ "$usage" -ge "$limit" ]; then
|
if [ "$usage" -ge "$limit" ]; then
|
||||||
msgLimit="@here\n**CHECK STOCKAGE :red_circle:**\nLimite autorisé : ${limit}% \nUtilisation actuelle: ${usage}%\nEspace restant: ${free}%\nHeure: $(date)"
|
msgLimit="@here\n**CHECK STOCKAGE :red_circle:**\nLimite autorisé : ${limit}%\nUtilisation actuelle: ${usage}%\nEspace restant: ${free}%\nUtilise / total: ${used_gb} GB / ${total_gb} GB\nDisponible: ${avail_gb} GB\nHeure: $(date)"
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
-H "Content-Type: application/json; charset=utf-8" \
|
-H "Content-Type: application/json; charset=utf-8" \
|
||||||
-d "{\"content\":\"$msgLimit\"}" \
|
-d "{\"content\":\"$msgLimit\"}" \
|
||||||
"$WEBHOOK_URL"
|
"$WEBHOOK_URL"
|
||||||
# Log de l'alerte
|
|
||||||
echo "ALERTE >> ${usage}% d'utilisation, check fait le $(date)"
|
|
||||||
echo "------------------------------------------------------------"
|
|
||||||
fi
|
fi
|
||||||
|
echo "Espace disponible : ${avail_gb} GB"
|
||||||
|
echo "Espace utilise / espace total : ${used_gb} GB / ${total_gb} GB"
|
||||||
|
echo "Name: ${HOSTNAME}"
|
||||||
Reference in New Issue
Block a user