fix: treat HTTP 201/409/202 as SAC success in WebException path (1.2.10-SAC)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+1
-1
@@ -80,7 +80,7 @@ $script:MonitorLoopInitialized = $false
|
|||||||
# строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах).
|
# строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах).
|
||||||
# Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только
|
# Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только
|
||||||
# исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1).
|
# исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1).
|
||||||
$ScriptVersion = "1.2.9-SAC"
|
$ScriptVersion = "1.2.10-SAC"
|
||||||
|
|
||||||
# Логи (все под InstallRoot)
|
# Логи (все под InstallRoot)
|
||||||
$LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log"
|
$LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log"
|
||||||
|
|||||||
+27
-5
@@ -4,9 +4,29 @@
|
|||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Dot-source после login_monitor.settings.ps1 и функции Write-Log.
|
Dot-source после login_monitor.settings.ps1 и функции Write-Log.
|
||||||
Ожидает: $UseSAC, $SacUrl, $SacApiKey, $ScriptVersion, $script:InstallRoot.
|
Ожидает: $UseSAC, $SacUrl, $SacApiKey, $ScriptVersion, $script:InstallRoot.
|
||||||
Release: 1.2.9-SAC (UTF-8 ingest, title/summary limits, no spool on HTTP 422).
|
Release: 1.2.10-SAC (treat HTTP 201/409/202 as success when Invoke-WebRequest throws).
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
function Test-SacIngestAcceptedStatus {
|
||||||
|
param([int]$StatusCode)
|
||||||
|
return ($StatusCode -in 201, 409, 202)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Complete-SacIngestSuccess {
|
||||||
|
param(
|
||||||
|
[string]$EventId,
|
||||||
|
[string]$EventType,
|
||||||
|
[int]$StatusCode
|
||||||
|
)
|
||||||
|
Remove-SacSpoolFile -EventId $EventId
|
||||||
|
Reset-SacFailCount
|
||||||
|
if ($StatusCode -eq 409) {
|
||||||
|
Write-SacLog "SAC: duplicate OK (HTTP 409) event_id=$EventId type=$EventType"
|
||||||
|
} else {
|
||||||
|
Write-SacLog "SAC: accepted event_id=$EventId type=$EventType (HTTP $StatusCode)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Get-SacUtf8Bytes {
|
function Get-SacUtf8Bytes {
|
||||||
param([Parameter(Mandatory = $true)][string]$Text)
|
param([Parameter(Mandatory = $true)][string]$Text)
|
||||||
return (New-Object System.Text.UTF8Encoding $false).GetBytes($Text)
|
return (New-Object System.Text.UTF8Encoding $false).GetBytes($Text)
|
||||||
@@ -276,10 +296,8 @@ function Invoke-SacPostPayload {
|
|||||||
}
|
}
|
||||||
$bodyBytes = Get-SacUtf8Bytes -Text $JsonBody
|
$bodyBytes = Get-SacUtf8Bytes -Text $JsonBody
|
||||||
$resp = Invoke-WebRequest -Uri $ingest -Method Post -Headers $headers -Body $bodyBytes -UseBasicParsing -TimeoutSec $timeout
|
$resp = Invoke-WebRequest -Uri $ingest -Method Post -Headers $headers -Body $bodyBytes -UseBasicParsing -TimeoutSec $timeout
|
||||||
if ($resp.StatusCode -in 201, 409, 202) {
|
if (Test-SacIngestAcceptedStatus -StatusCode $resp.StatusCode) {
|
||||||
Remove-SacSpoolFile -EventId $eventId
|
Complete-SacIngestSuccess -EventId $eventId -EventType $eventType -StatusCode $resp.StatusCode
|
||||||
Reset-SacFailCount
|
|
||||||
Write-SacLog "SAC: accepted event_id=$eventId type=$eventType"
|
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
$body = if ($resp.Content) { $resp.Content } else { '' }
|
$body = if ($resp.Content) { $resp.Content } else { '' }
|
||||||
@@ -299,6 +317,10 @@ function Invoke-SacPostPayload {
|
|||||||
if ($_.Exception.Response) {
|
if ($_.Exception.Response) {
|
||||||
$code = [int]$_.Exception.Response.StatusCode
|
$code = [int]$_.Exception.Response.StatusCode
|
||||||
}
|
}
|
||||||
|
if (Test-SacIngestAcceptedStatus -StatusCode $code) {
|
||||||
|
Complete-SacIngestSuccess -EventId $eventId -EventType $eventType -StatusCode $code
|
||||||
|
return $true
|
||||||
|
}
|
||||||
if ($code -eq 422) {
|
if ($code -eq 422) {
|
||||||
$spoolOnFailure = $false
|
$spoolOnFailure = $false
|
||||||
Write-SacLog "WARN: SAC POST HTTP 422 validation (not spooled) type=$eventType event_id=$eventId"
|
Write-SacLog "WARN: SAC POST HTTP 422 validation (not spooled) type=$eventType event_id=$eventId"
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
1.2.9-SAC
|
1.2.10-SAC
|
||||||
|
|||||||
Reference in New Issue
Block a user