Files
rdp-proxy/scripts/fabric/c18z106-audit-correlation-hints-smoke.ps1
T
2026-05-12 21:02:29 +03:00

108 lines
5.0 KiB
PowerShell

param(
[string]$ApiBaseUrl = "http://192.168.200.61:18121/api/v1",
[string]$ClusterID = "cfc0743d-d960-49fb-9de8-96e063d5e4aa",
[string]$ActorUserID = "f67d943f-5397-4b3a-a229-695fe67ad700",
[string]$ExpectedBackendImage = "rap-backend:fabric-service-channel-0.2.281-c18z109",
[string]$DockerSSH = "test-docker",
[string]$ResultPath = "artifacts\c18z106-audit-correlation-hints-smoke-result.json"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath
$runId = "c18z106-" + (Get-Date -Format "yyyyMMdd-HHmmss")
function Invoke-Api {
param([string]$Method, [string]$Path, [object]$Body = $null)
$params = @{ Method = $Method; Uri = "$ApiBaseUrl$Path"; TimeoutSec = 30 }
if ($null -ne $Body) {
$params.ContentType = "application/json"
$params.Body = ($Body | ConvertTo-Json -Depth 60)
}
return Invoke-RestMethod @params
}
function Get-PropertyValue {
param([object]$Item, [string]$Name, [object]$Default = $null)
if ($null -eq $Item) { return $Default }
$property = $Item.PSObject.Properties[$Name]
if ($null -eq $property) { return $Default }
return $property.Value
}
$checks = [ordered]@{}
$backendImage = (& ssh $DockerSSH "docker inspect rap_test_backend --format '{{.Config.Image}}'").Trim()
$checks.backend_expected_image_deployed = ($backendImage -eq $ExpectedBackendImage)
$health = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-health?actor_user_id=$ActorUserID&limit=50").rebuild_health
$breakdown = @($health.feedback_breakdowns | Where-Object {
(Get-PropertyValue -Item $_ -Name "feedback_source" -Default "") -ne "" -and
(Get-PropertyValue -Item $_ -Name "feedback_channel_id" -Default "") -ne "" -and
(Get-PropertyValue -Item $_ -Name "feedback_violation_status" -Default "") -ne ""
}) | Select-Object -First 1
$checks.rebuild_health_has_feedback_breakdown = ($null -ne $breakdown)
if ($null -eq $breakdown) {
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
throw "C18Z106 audit correlation hints smoke failed before audit: $($failed -join ', ')"
}
$feedbackSource = $breakdown.feedback_source
$feedbackChannelID = $breakdown.feedback_channel_id
$feedbackViolationStatus = $breakdown.feedback_violation_status
Invoke-Api -Method POST -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-incidents/investigations" -Body @{
actor_user_id = $ActorUserID
feedback_source = $feedbackSource
feedback_channel_id = $feedbackChannelID
feedback_violation_status = $feedbackViolationStatus
drilldown_source = "rebuild_health_feedback_breakdown"
reason = "synthetic c18z106 audit correlation hints"
} | Out-Null
$eventType = "fabric.service_channel_rebuild_feedback_breakdown.investigation_opened"
$auditEvents = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/audit?actor_user_id=$ActorUserID&limit=20&event_type=$([uri]::EscapeDataString($eventType))&correlation=fabric_diagnostics").audit_events
$event = @($auditEvents | Where-Object {
(Get-PropertyValue -Item $_.payload -Name "reason" -Default "") -eq "synthetic c18z106 audit correlation hints" -and
(Get-PropertyValue -Item $_.payload -Name "feedback_channel_id" -Default "") -eq $feedbackChannelID
}) | Select-Object -First 1
$hint = Get-PropertyValue -Item $event -Name "correlation_hints" -Default $null
$hintBreakdown = Get-PropertyValue -Item $hint -Name "feedback_breakdown" -Default $null
$checks.audit_event_has_correlation_hints = ($null -ne $hint)
$checks.correlation_status_is_breakdown_active = ((Get-PropertyValue -Item $hint -Name "current_diagnostic_status" -Default "") -eq "breakdown_active")
$checks.correlation_hint_points_to_breakdown = (
$null -ne $hintBreakdown -and
(Get-PropertyValue -Item $hintBreakdown -Name "feedback_channel_id" -Default "") -eq $feedbackChannelID -and
(Get-PropertyValue -Item $hintBreakdown -Name "feedback_violation_status" -Default "") -eq $feedbackViolationStatus
)
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
$result = [ordered]@{
schema_version = "c18z106.audit_correlation_hints_smoke.v1"
run_id = $runId
cluster_id = $ClusterID
feedback_channel_id = $feedbackChannelID
passed = ($failed.Count -eq 0)
checks = $checks
failed_checks = $failed
summary = [ordered]@{
backend_image = $backendImage
audit_event_id = if ($null -ne $event) { $event.id } else { $null }
hint_status = Get-PropertyValue -Item $hint -Name "current_diagnostic_status" -Default ""
}
}
$target = Join-Path $repoRoot $ResultPath
$result | ConvertTo-Json -Depth 60 | Set-Content -Path $target -Encoding UTF8
if ($failed.Count -gt 0) {
throw "C18Z106 audit correlation hints smoke failed: $($failed -join ', ')"
}
Write-Host "C18Z106 audit correlation hints smoke passed. Result: $target"
$result