Updating Files
هذا الالتزام موجود في:
@@ -1,26 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#!/usr/bin/bash
|
||||
LOG_FILE="fruit_api.log"
|
||||
# ALERT_URL="https://gahymah.systems.com"
|
||||
|
||||
if [[ ! -f "$LOG_FILE" ]]; then
|
||||
echo "❌ Log file $LOG_FILE not found!"
|
||||
exit 1
|
||||
fi
|
||||
tail -Fn0 "$LOG_FILE" | while read line; do
|
||||
if echo "$line" | grep -qiE "STATUS:(4[0-9]{2}|5[0-9]{2})|failed|timeout|error|exception"; then
|
||||
echo "🚨 Error detected: $line"
|
||||
|
||||
echo "📊 Fruit API Logs Report (last 2 hours) - $(date)"
|
||||
echo "--------------------------------------------------"
|
||||
IP=$(hostname -I | awk '{print $1}')
|
||||
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2"%"}')
|
||||
RAM=$(free -m | awk '/Mem:/ {print $4"MB"}')
|
||||
DISK=$(df -h / | awk 'NR==2 {print $4}')
|
||||
|
||||
# Get timestamps from last 2 hours
|
||||
time_filter=$(date --date='2 hours ago' +"%Y-%m-%d %H")
|
||||
payload=$(cat <<EOF
|
||||
{
|
||||
"error": "$line",
|
||||
"timestamp": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
|
||||
"message": "Error detected in Fruit API logs",
|
||||
"server_metrics": {
|
||||
"ip": "$IP",
|
||||
"cpu_usage": "$CPU",
|
||||
"ram_available": "$RAM",
|
||||
"disk_space": "$DISK"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
echo "$payload"
|
||||
|
||||
# Show all logs from last 2 hours
|
||||
echo "🔹 Raw logs (last 2 hours):"
|
||||
grep "$time_filter" "$LOG_FILE"
|
||||
|
||||
echo "--------------------------------------------------"
|
||||
echo "🔹 Status Codes Summary:"
|
||||
grep "$time_filter" "$LOG_FILE" | grep "RESPONSE" | awk '{print $NF}' | sort | uniq -c | sort -nr
|
||||
|
||||
echo "--------------------------------------------------"
|
||||
echo "🔹 Users & IPs:"
|
||||
grep "$time_filter" "$LOG_FILE" | grep "REQUEST" | awk '{for(i=1;i<=NF;i++){if($i ~ /^ip=/){print $i}}}' | sort | uniq -c | sort -nr
|
||||
curl -s -X POST -H "Content-Type: application/json" -d "$payload" "$ALERT_URL"
|
||||
fi
|
||||
done
|
||||
|
المرجع في مشكلة جديدة
حظر مستخدم