Fix: Scan logs in subdirectories to catch all domain errors

Issue: Was missing 500 errors from logs stored in subdirectories like
/var/log/apache2/domlogs/username/domain.com

Changed from simple glob (domlogs/*) to recursive find command that:
- Scans all files in domlogs directory AND subdirectories
- Excludes system files (bytes_log, offset, error_log, ftpxferlog, ssl_log)
- Finds ALL domain access logs regardless of location

This ensures we catch errors like "GET /ay.php HTTP/1.1" 500 that were
previously missed in subdirectory logs.
This commit is contained in:
cschantz
2025-11-03 21:17:45 -05:00
parent c36ba42333
commit 222dc08415
+6 -5
View File
@@ -59,21 +59,22 @@ declare -A domain_user
total_500s=0 total_500s=0
filtered_bots=0 filtered_bots=0
# Scan all domain access logs for 500 errors # Scan all domain access logs for 500 errors (including subdirectories)
for log in "$DOMLOGS_DIR"/*; do while IFS= read -r log; do
[ -f "$log" ] || continue [ -f "$log" ] || continue
[[ "$log" =~ (bytes_log|offset|error_log|ftpxferlog|-ssl_log)$ ]] && continue [[ "$log" =~ (bytes_log|offset|error_log|ftpxferlog|-ssl_log)$ ]] && continue
# Extract domain from log filename
domain="${log##*/}" domain="${log##*/}"
domain="${domain%%-*}" domain="${domain%%-*}"
# Skip non-domain system logs (proxy, localhost, etc.) # Skip non-domain system logs (proxy, localhost, etc.)
[[ "$domain" =~ ^(proxy|localhost|default|cpanel|webmail|whm|cpcalendars|cpcontacts|webdisk)$ ]] && continue [[ "$domain" =~ ^(proxy|localhost|default|cpanel|webmail|whm|cpcalendars|cpcontacts|webdisk)$ ]] && continue
# Find cPanel user for this domain # Find cPanel user for this domain
user=$(grep -l "DNS.*$domain" /var/cpanel/users/* 2>/dev/null | head -1 | xargs basename 2>/dev/null) user=$(grep -l "DNS.*$domain" /var/cpanel/users/* 2>/dev/null | head -1 | xargs basename 2>/dev/null)
[ -z "$user" ] && user="unknown" [ -z "$user" ] && user="unknown"
domain_user["$domain"]="$user" domain_user["$domain"]="$user"
# Scan for 500 errors in this log # Scan for 500 errors in this log
@@ -130,7 +131,7 @@ for log in "$DOMLOGS_DIR"/*; do
echo "$domain|$user|$status|$url|$timestamp|$ip" >> "$ERRORS_500" echo "$domain|$user|$status|$url|$timestamp|$ip" >> "$ERRORS_500"
fi fi
done < <(tail -n 100000 "$log" 2>/dev/null) done < <(tail -n 100000 "$log" 2>/dev/null)
done done < <(find "$DOMLOGS_DIR" -type f ! -name "*bytes_log" ! -name "*offset*" ! -name "*error_log" ! -name "*ftpxferlog*" ! -name "*-ssl_log" 2>/dev/null)
if [ "$total_500s" -eq 0 ]; then if [ "$total_500s" -eq 0 ]; then
echo "" echo ""