diff --git a/Login_Monitor.ps1 b/Login_Monitor.ps1 index 0ddda15..553e53d 100644 --- a/Login_Monitor.ps1 +++ b/Login_Monitor.ps1 @@ -80,7 +80,7 @@ $script:MonitorLoopInitialized = $false # строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах). # Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только # исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1). -$ScriptVersion = "1.2.9-SAC" +$ScriptVersion = "1.2.10-SAC" # Логи (все под InstallRoot) $LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log" diff --git a/Sac-Client.ps1 b/Sac-Client.ps1 index a7c3b73..077cf2e 100644 --- a/Sac-Client.ps1 +++ b/Sac-Client.ps1 @@ -4,9 +4,29 @@ .DESCRIPTION Dot-source после login_monitor.settings.ps1 и функции Write-Log. Ожидает: $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 { param([Parameter(Mandatory = $true)][string]$Text) return (New-Object System.Text.UTF8Encoding $false).GetBytes($Text) @@ -276,10 +296,8 @@ function Invoke-SacPostPayload { } $bodyBytes = Get-SacUtf8Bytes -Text $JsonBody $resp = Invoke-WebRequest -Uri $ingest -Method Post -Headers $headers -Body $bodyBytes -UseBasicParsing -TimeoutSec $timeout - if ($resp.StatusCode -in 201, 409, 202) { - Remove-SacSpoolFile -EventId $eventId - Reset-SacFailCount - Write-SacLog "SAC: accepted event_id=$eventId type=$eventType" + if (Test-SacIngestAcceptedStatus -StatusCode $resp.StatusCode) { + Complete-SacIngestSuccess -EventId $eventId -EventType $eventType -StatusCode $resp.StatusCode return $true } $body = if ($resp.Content) { $resp.Content } else { '' } @@ -299,6 +317,10 @@ function Invoke-SacPostPayload { if ($_.Exception.Response) { $code = [int]$_.Exception.Response.StatusCode } + if (Test-SacIngestAcceptedStatus -StatusCode $code) { + Complete-SacIngestSuccess -EventId $eventId -EventType $eventType -StatusCode $code + return $true + } if ($code -eq 422) { $spoolOnFailure = $false Write-SacLog "WARN: SAC POST HTTP 422 validation (not spooled) type=$eventType event_id=$eventId" diff --git a/version.txt b/version.txt index cc1c037..e59e349 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.2.9-SAC +1.2.10-SAC