Skip to content

Commit

Permalink
Merge pull request #66 from akunzai/sort-req-count
Browse files Browse the repository at this point in the history
Sort the failed HTTP request by request times
  • Loading branch information
akunzai authored Jan 20, 2023
2 parents 1043769 + be514e7 commit 8969b60
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ git pull
Sample output

````markdown
# Windows Secure Auditor: 0.12.4
# Windows Secure Auditor: 0.12.5

## System Information

Expand Down Expand Up @@ -121,7 +121,7 @@ Poll Interval: 6 (64s)
- Status code: 500
- `/api/search?q=test`: 1 Times
- Status code: 404
- `/favicon.ico`: 2 Time
- `/favicon.ico`: 2 Times
- `/robots.txt`: 1 Times

## Default Account
Expand Down
2 changes: 1 addition & 1 deletion README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ git pull
範例輸出

````markdown
# Windows Secure Auditor: 0.12.4
# Windows Secure Auditor: 0.12.5

## 系統資訊

Expand Down
2 changes: 1 addition & 1 deletion SecureAuditor.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# RootModule = ''

# Version number of this module.
ModuleVersion = '0.12.4'
ModuleVersion = '0.12.5'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
12 changes: 3 additions & 9 deletions rules/IIS/FailedHttpRequests.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Test($config) {
$verbose = $null -ne $PSCmdlet -and $PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Verbose") -and $PSCmdlet.MyInvocation.BoundParameters["Verbose"] -eq $true
foreach ($logFile in $logFiles) {
Write-Verbose "Parsing: $($logFile) ..." -Verbose:$verbose
$logs = Get-Content $logFile | Select-Object -skip 3 | Foreach-Object { $_ -replace '#Fields: ', '' } | ConvertFrom-Csv -Delimiter ' ' `
$logs = Get-Content $logFile | Select-Object -Skip 3 | Foreach-Object { $_ -replace '#Fields: ', '' } | ConvertFrom-Csv -Delimiter ' ' `
| Where-Object { $_.date -ne 'date' -and $_.'sc-status' -gt '399' } `
| Where-Object { $fromDate -lt [datetime]::Parse($_.date, [System.Globalization.CultureInfo]::InvariantCulture, [System.Globalization.DateTimeStyles]::AdjustToUniversal).Add([timespan]::Parse($_.time, [System.Globalization.CultureInfo]::InvariantCulture)) } `
| Group-Object -Property sc-status, cs-uri-stem, cs-uri-query
Expand All @@ -59,14 +59,8 @@ function Test($config) {
$maxRecords = [int]$config.FailedHttpRequests.MaxRecords
foreach ($status in $failedRequestsForStatus.Keys | Sort-Object -Descending) {
Write-Output "- $($i18n.StatusCode): $($status)"
$count = 0
foreach ($uri in $failedRequestsForStatus[$status].Keys) {
if ($count -ge $maxRecords) {
break
}
$times = $failedRequestsForStatus[$status][$uri]
Write-Output " - ``$($uri)``: $($times) $($i18n.Times)"
$count += 1
foreach ($item in $failedRequestsForStatus[$status].GetEnumerator() | Sort-Object -Property Value -Descending | Select-Object -First $maxRecords) {
Write-Output " - ``$($item.Key)``: $($item.Value) $($i18n.Times)"
}
}
}
Expand Down

0 comments on commit 8969b60

Please sign in to comment.