classify_errors2.ps1 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Classify errors from api_errors_final.txt and save to file
  2. $lines = Get-Content 'd:\ylrz\saasadminui\api_errors_final.txt' -Encoding UTF8
  3. $err404 = [System.Collections.ArrayList]::new()
  4. $err500 = [System.Collections.ArrayList]::new()
  5. $errTimeout = [System.Collections.ArrayList]::new()
  6. $err403 = [System.Collections.ArrayList]::new()
  7. $errOther = [System.Collections.ArrayList]::new()
  8. foreach ($line in $lines) {
  9. if ($line -match '^404\|') { [void]$err404.Add($line) }
  10. elseif ($line -match '^500\|') { [void]$err500.Add($line) }
  11. elseif ($line -match '^0\|') { [void]$errTimeout.Add($line) }
  12. elseif ($line -match '^403\|') { [void]$err403.Add($line) }
  13. elseif ($line -match '^\d+\|') { [void]$errOther.Add($line) }
  14. }
  15. $out = [System.Collections.ArrayList]::new()
  16. [void]$out.Add("=== ERROR SUMMARY ===")
  17. [void]$out.Add("404 NOT FOUND: $($err404.Count)")
  18. [void]$out.Add("500 SERVER ERROR: $($err500.Count)")
  19. [void]$out.Add("0 TIMEOUT/CONNECTION: $($errTimeout.Count)")
  20. [void]$out.Add("403 FORBIDDEN: $($err403.Count)")
  21. [void]$out.Add("OTHER: $($errOther.Count)")
  22. [void]$out.Add("")
  23. # 404 prefix groups
  24. [void]$out.Add("=== 404 URL PREFIX GROUPS ===")
  25. $prefix404 = @{}
  26. foreach ($line in $err404) {
  27. if ($line -match '404\|(/[^/]+/[^/]+)') {
  28. $p = $matches[1]
  29. if (-not $prefix404.ContainsKey($p)) { $prefix404[$p] = 0 }
  30. $prefix404[$p]++
  31. } elseif ($line -match '404\|(/[^/]+)') {
  32. $p = $matches[1]
  33. if (-not $prefix404.ContainsKey($p)) { $prefix404[$p] = 0 }
  34. $prefix404[$p]++
  35. }
  36. }
  37. $prefix404.GetEnumerator() | Sort-Object Value -Descending | ForEach-Object { [void]$out.Add("$($_.Key): $($_.Value)") }
  38. # Timeout prefix groups
  39. [void]$out.Add("")
  40. [void]$out.Add("=== TIMEOUT URL PREFIX GROUPS ===")
  41. $prefixTimeout = @{}
  42. foreach ($line in $errTimeout) {
  43. if ($line -match '0\|([^/|]+)') {
  44. $p = '/' + $matches[1]
  45. if (-not $prefixTimeout.ContainsKey($p)) { $prefixTimeout[$p] = 0 }
  46. $prefixTimeout[$p]++
  47. }
  48. }
  49. $prefixTimeout.GetEnumerator() | Sort-Object Value -Descending | ForEach-Object { [void]$out.Add("$($_.Key): $($_.Value)") }
  50. # 500 error types
  51. [void]$out.Add("")
  52. [void]$out.Add("=== 500 ERROR TYPES ===")
  53. $err500Types = @{}
  54. foreach ($line in $err500) {
  55. if ($line -match "Request method 'GET' not supported") { $t = 'GET_NOT_SUPPORTED' }
  56. elseif ($line -match 'Failed to convert.*NumberFormatException') { $t = 'PATH_PARAM_CONFLICT' }
  57. elseif ($line -match 'Unknown column') { $t = 'SQL_COLUMN_MISSING' }
  58. elseif ($line -match 'Required request parameter') { $t = 'MISSING_PARAM' }
  59. elseif ($line -match 'bad SQL grammar') { $t = 'SQL_ERROR' }
  60. else { $t = 'OTHER' }
  61. if (-not $err500Types.ContainsKey($t)) { $err500Types[$t] = 0 }
  62. $err500Types[$t]++
  63. }
  64. $err500Types.GetEnumerator() | Sort-Object Value -Descending | ForEach-Object { [void]$out.Add("$($_.Key): $($_.Value)") }
  65. # All 404
  66. [void]$out.Add("")
  67. [void]$out.Add("=== ALL 404 ERRORS ===")
  68. $err404 | ForEach-Object { [void]$out.Add($_) }
  69. # All 500
  70. [void]$out.Add("")
  71. [void]$out.Add("=== ALL 500 ERRORS ===")
  72. $err500 | ForEach-Object { [void]$out.Add($_) }
  73. # All timeout
  74. [void]$out.Add("")
  75. [void]$out.Add("=== ALL TIMEOUT ERRORS ===")
  76. $errTimeout | ForEach-Object { [void]$out.Add($_) }
  77. # All 403
  78. [void]$out.Add("")
  79. [void]$out.Add("=== ALL 403 ERRORS ===")
  80. $err403 | ForEach-Object { [void]$out.Add($_) }
  81. $out | Out-File -FilePath 'd:\ylrz\saasadminui\error_analysis.txt' -Encoding UTF8
  82. Write-Host "Analysis saved to error_analysis.txt"
  83. Write-Host "404: $($err404.Count), 500: $($err500.Count), Timeout: $($errTimeout.Count), 403: $($err403.Count), Other: $($errOther.Count)"