52 lines
1.4 KiB
Bash
Executable File
52 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
ALERT_LOG="/var/log/wevads_alerts.log"
|
|
THRESHOLDS="/opt/wevads/config/alert_thresholds.json"
|
|
|
|
# Charger les seuils
|
|
[ -f "$THRESHOLDS" ] || cat > "$THRESHOLDS" << 'JSON'
|
|
{
|
|
"cpu_load": 4.0,
|
|
"memory_usage": 85,
|
|
"disk_usage": 90,
|
|
"response_time": 500,
|
|
"error_count": 10
|
|
}
|
|
JSON
|
|
|
|
check_thresholds() {
|
|
# Vérifier la charge CPU
|
|
LOAD=$(uptime | awk -F'load average:' '{print $2}' | awk '{print $1}' | tr ',' '.')
|
|
CPU_THRESHOLD=$(jq '.cpu_load' "$THRESHOLDS")
|
|
|
|
if (( $(echo "$LOAD > $CPU_THRESHOLD" | bc -l) )); then
|
|
echo "[$(date)] ⚠️ Alerte CPU: Load $LOAD > $CPU_THRESHOLD" >> "$ALERT_LOG"
|
|
return 1
|
|
fi
|
|
|
|
# Vérifier l'espace disque
|
|
DISK_USAGE=$(df -h / | awk 'NR==2 {print $5}' | tr -d '%')
|
|
DISK_THRESHOLD=$(jq '.disk_usage' "$THRESHOLDS")
|
|
|
|
if [ "$DISK_USAGE" -gt "$DISK_THRESHOLD" ]; then
|
|
echo "[$(date)] ⚠️ Alerte Disque: Usage $DISK_USAGE% > ${DISK_THRESHOLD}%" >> "$ALERT_LOG"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
# Exécuter les vérifications
|
|
if check_thresholds; then
|
|
echo "✅ Tous les seuils sont respectés"
|
|
else
|
|
echo "⚠️ Seuils dépassés - consulter $ALERT_LOG"
|
|
|
|
# Générer une alerte intelligente
|
|
ALERT_CONTEXT=$(tail -3 "$ALERT_LOG")
|
|
|
|
# Intégrer avec RAG si disponible
|
|
if [ -f "/opt/wevads/scripts/rag-processor.py" ]; then
|
|
python3 /opt/wevads/scripts/rag-processor.py "$ALERT_CONTEXT"
|
|
fi
|
|
fi
|