From c97ffe2cbddd74a76535fef7cd90c5f2451d624c Mon Sep 17 00:00:00 2001 From: igor04091968 Date: Sat, 2 May 2026 23:42:14 +0300 Subject: [PATCH] Fix: ensure file collector robustness (HttpClient, TLS 1.2, English logs) --- ansible/deploy_aw_windows.yml | 36 +++++++++++++-------------- windows/file-operations-collector.ps1 | 27 ++++++++++++++------ 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/ansible/deploy_aw_windows.yml b/ansible/deploy_aw_windows.yml index 6c7cca2..300c7cf 100644 --- a/ansible/deploy_aw_windows.yml +++ b/ansible/deploy_aw_windows.yml @@ -233,21 +233,21 @@ mode: "0755" delegate_to: localhost -# - name: Стянуть отчёт валидации с эндпоинта -# ansible.windows.win_fetch: -# src: "{{ aw_windows_validation_remote_path }}" -# dest: "{{ aw_windows_validation_local_dir }}/{{ inventory_hostname }}-aw_validate_ansible.json" -# flat: true -# -# - name: Проверить статус валидации -# ansible.builtin.shell: | -# python3 - <<'PY' -# import json, sys -# with open('{{ aw_windows_validation_local_dir }}/{{ inventory_hostname }}-aw_validate_ansible.json', 'r') as f: -# data = json.load(f) -# if not data.get('overallOk', False): -# print(f"Validation failed for {{ inventory_hostname }}: {data.get('summary', 'Unknown error')}") -# sys.exit(1) -# PY -# delegate_to: localhost -# when: aw_windows_fail_on_validation_error | bool + - name: Стянуть отчёт валидации с эндпоинта + ansible.windows.win_fetch: + src: "{{ aw_windows_validation_remote_path }}" + dest: "{{ aw_windows_validation_local_dir }}/{{ inventory_hostname }}-aw_validate_ansible.json" + flat: true + + - name: Проверить статус валидации + ansible.builtin.shell: | + python3 - <<'PY' + import json, sys + with open('{{ aw_windows_validation_local_dir }}/{{ inventory_hostname }}-aw_validate_ansible.json', 'r') as f: + data = json.load(f) + if not data.get('overallOk', False): + print(f"Validation failed for {{ inventory_hostname }}: {data.get('summary', 'Unknown error')}") + sys.exit(1) + PY + delegate_to: localhost + when: aw_windows_fail_on_validation_error | bool diff --git a/windows/file-operations-collector.ps1 b/windows/file-operations-collector.ps1 index ff4c399..3fb5246 100644 --- a/windows/file-operations-collector.ps1 +++ b/windows/file-operations-collector.ps1 @@ -14,7 +14,11 @@ param( Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' -# Реестр известных бакетов +# Force TLS 1.2 and load networking types +[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 +Add-Type -AssemblyName System.Net.Http + +# Bucket registry $script:KnownBuckets = @{} $script:Hostname = $env:COMPUTERNAME $script:SessionId = [System.Diagnostics.Process]::GetCurrentProcess().SessionId @@ -44,7 +48,14 @@ function Invoke-AwJsonPost { [Parameter(Mandatory = $true)][string]$Uri, [Parameter(Mandatory = $true)][string]$Json ) - Invoke-RestMethod -Method Post -Uri $Uri -ContentType 'application/json' -Body $Json | Out-Null + try { + $httpClient = New-Object System.Net.Http.HttpClient + $content = New-Object System.Net.Http.StringContent($Json, [System.Text.Encoding]::UTF8, "application/json") + $response = $httpClient.PostAsync($Uri, $content).Result + $httpClient.Dispose() + } catch { + Write-FileCollectorLog "POST Error: $($_.Exception.Message)" + } } function Ensure-Bucket { @@ -99,7 +110,7 @@ function Send-FileOperationEvent { } $config = Get-DeploymentConfig -Path $ConfigPath -if (-not $config) { throw "Не найден конфигурационный файл: $ConfigPath" } +if (-not $config) { throw "Configuration file not found: $ConfigPath" } $scheme = if ($ServerScheme) { $ServerScheme } elseif ($config.server.scheme) { $config.server.scheme } else { 'http' } $hostName = if ($ServerHost) { $ServerHost } elseif ($config.server.host) { $config.server.host } else { 'localhost' } @@ -109,7 +120,7 @@ $script:ApiBase = "{0}://{1}:{2}/api/0" -f $scheme, $hostName, $port $bucketId = 'aw-file-operations_' + $script:Hostname Ensure-Bucket -BucketId $bucketId -ClientName 'aw-file-operations' -BucketType 'aw.file.operation' -# Разрешение путей для мониторинга +# Resolve paths for monitoring $resolvedPaths = @() foreach ($p in $WatchPaths) { $fullPath = $p @@ -126,11 +137,11 @@ foreach ($p in $WatchPaths) { } if ($resolvedPaths.Count -eq 0) { - Write-FileCollectorLog "Нет доступных путей для мониторинга. Завершение." + Write-FileCollectorLog "No valid watch paths found. Exiting." exit 0 } -Write-FileCollectorLog "Запуск мониторинга путей: $($resolvedPaths -join ', ')" +Write-FileCollectorLog "Starting watch on paths: $($resolvedPaths -join ', ')" $watchers = @() foreach ($path in $resolvedPaths) { @@ -155,7 +166,7 @@ foreach ($path in $resolvedPaths) { $watchers += $watcher } -Write-FileCollectorLog "Коллектор запущен. Ожидание событий..." +Write-FileCollectorLog "Collector started. Waiting for events..." try { while ($true) { @@ -163,7 +174,7 @@ try { } } finally { - Write-FileCollectorLog "Остановка коллектора..." + Write-FileCollectorLog "Stopping collector..." foreach ($w in $watchers) { $w.EnableRaisingEvents = $false $w.Dispose()