diff --git a/modules/website/500-error-tracker.sh b/modules/website/500-error-tracker.sh index 2dd1a94..26bbde2 100755 --- a/modules/website/500-error-tracker.sh +++ b/modules/website/500-error-tracker.sh @@ -743,28 +743,60 @@ echo " SPECIFIC DIAGNOSTICS (per URL/file)" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" -# Show detailed diagnostics grouped by cause - deduplicate by domain+url+issue +# Show detailed diagnostics grouped by cause and issue pattern if [ -f "$DETAILED_DIAGNOSIS" ] && [ -s "$DETAILED_DIAGNOSIS" ]; then for cause_type in PHP_MEMORY_EXHAUSTED PERMISSION_ERROR HTACCESS_ERROR PHP_FATAL_ERROR PHP_SYNTAX_ERROR MISSING_PHP_FUNCTION DATABASE_CONNECTION FILE_NOT_FOUND PHP_HANDLER_ERROR WP_DEBUG_ERROR DOCROOT_MISSING; do - # Get unique diagnostics (deduplicate identical domain+issue combinations) - unique_diags=$(grep "^${cause_type}|" "$DETAILED_DIAGNOSIS" 2>/dev/null | cut -d'|' -f2 | sort -u) - cause_count=$(echo "$unique_diags" | grep -c "^" 2>/dev/null || echo "0") - if [ "$cause_count" -gt 0 ] && [ -n "$unique_diags" ]; then + cause_count=$(grep -c "^${cause_type}|" "$DETAILED_DIAGNOSIS" 2>/dev/null || echo "0") + + if [ "$cause_count" -gt 0 ]; then cause_display=$(echo "$cause_type" | tr '_' ' ') - echo -e "${RED}${BOLD}$cause_display ($cause_count unique issues)${NC}" + echo -e "${RED}${BOLD}$cause_display ($cause_count occurrences)${NC}" echo "" - echo "$unique_diags" | head -20 | while read -r diag_line; do - [ -z "$diag_line" ] && continue - echo -e " ${YELLOW}•${NC} $diag_line" + # Group by unique error pattern (not domain) + declare -A issue_domains + + while IFS='|' read -r ctype full_diag; do + # Extract just the error part (after domain/) + issue_pattern=$(echo "$full_diag" | sed 's/^[^ ]* - //') + domain_part=$(echo "$full_diag" | grep -oP '^[^/]+') + + # Group domains with same issue + if [ -z "${issue_domains[$issue_pattern]}" ]; then + issue_domains[$issue_pattern]="$domain_part" + else + # Count how many domains (limit to first 5) + count=$(echo "${issue_domains[$issue_pattern]}" | tr ',' '\n' | wc -l) + if [ "$count" -lt 5 ]; then + issue_domains[$issue_pattern]="${issue_domains[$issue_pattern]},$domain_part" + elif [ "$count" -eq 5 ]; then + issue_domains[$issue_pattern]="${issue_domains[$issue_pattern]},..." + fi + fi + done < <(grep "^${cause_type}|" "$DETAILED_DIAGNOSIS" 2>/dev/null) + + # Display grouped issues + shown=0 + for pattern in "${!issue_domains[@]}"; do + [ $shown -ge 10 ] && break + ((shown++)) + + domains="${issue_domains[$pattern]}" + domain_count=$(echo "$domains" | tr ',' '\n' | grep -v '^\.\.\.$' | wc -l) + + echo -e " ${YELLOW}Issue:${NC} $pattern" + echo -e " ${DIM}Affected ($domain_count):${NC} ${domains//,/, }" + echo "" done - if [ "$cause_count" -gt 20 ]; then - remaining=$((cause_count - 20)) - echo -e " ${DIM}... and $remaining more${NC}" + if [ "${#issue_domains[@]}" -gt 10 ]; then + remaining=$((${#issue_domains[@]} - 10)) + echo -e " ${DIM}... and $remaining more issue patterns${NC}" + echo "" fi - echo "" + + unset issue_domains fi done else