Fix: ensure file collector robustness (HttpClient, TLS 1.2, English logs)
This commit is contained in:
@@ -233,21 +233,21 @@
|
|||||||
mode: "0755"
|
mode: "0755"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
# - name: Стянуть отчёт валидации с эндпоинта
|
- name: Стянуть отчёт валидации с эндпоинта
|
||||||
# ansible.windows.win_fetch:
|
ansible.windows.win_fetch:
|
||||||
# src: "{{ aw_windows_validation_remote_path }}"
|
src: "{{ aw_windows_validation_remote_path }}"
|
||||||
# dest: "{{ aw_windows_validation_local_dir }}/{{ inventory_hostname }}-aw_validate_ansible.json"
|
dest: "{{ aw_windows_validation_local_dir }}/{{ inventory_hostname }}-aw_validate_ansible.json"
|
||||||
# flat: true
|
flat: true
|
||||||
#
|
|
||||||
# - name: Проверить статус валидации
|
- name: Проверить статус валидации
|
||||||
# ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
# python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
# import json, sys
|
import json, sys
|
||||||
# with open('{{ aw_windows_validation_local_dir }}/{{ inventory_hostname }}-aw_validate_ansible.json', 'r') as f:
|
with open('{{ aw_windows_validation_local_dir }}/{{ inventory_hostname }}-aw_validate_ansible.json', 'r') as f:
|
||||||
# data = json.load(f)
|
data = json.load(f)
|
||||||
# if not data.get('overallOk', False):
|
if not data.get('overallOk', False):
|
||||||
# print(f"Validation failed for {{ inventory_hostname }}: {data.get('summary', 'Unknown error')}")
|
print(f"Validation failed for {{ inventory_hostname }}: {data.get('summary', 'Unknown error')}")
|
||||||
# sys.exit(1)
|
sys.exit(1)
|
||||||
# PY
|
PY
|
||||||
# delegate_to: localhost
|
delegate_to: localhost
|
||||||
# when: aw_windows_fail_on_validation_error | bool
|
when: aw_windows_fail_on_validation_error | bool
|
||||||
|
|||||||
@@ -14,7 +14,11 @@ param(
|
|||||||
Set-StrictMode -Version Latest
|
Set-StrictMode -Version Latest
|
||||||
$ErrorActionPreference = 'Stop'
|
$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:KnownBuckets = @{}
|
||||||
$script:Hostname = $env:COMPUTERNAME
|
$script:Hostname = $env:COMPUTERNAME
|
||||||
$script:SessionId = [System.Diagnostics.Process]::GetCurrentProcess().SessionId
|
$script:SessionId = [System.Diagnostics.Process]::GetCurrentProcess().SessionId
|
||||||
@@ -44,7 +48,14 @@ function Invoke-AwJsonPost {
|
|||||||
[Parameter(Mandatory = $true)][string]$Uri,
|
[Parameter(Mandatory = $true)][string]$Uri,
|
||||||
[Parameter(Mandatory = $true)][string]$Json
|
[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 {
|
function Ensure-Bucket {
|
||||||
@@ -99,7 +110,7 @@ function Send-FileOperationEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$config = Get-DeploymentConfig -Path $ConfigPath
|
$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' }
|
$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' }
|
$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
|
$bucketId = 'aw-file-operations_' + $script:Hostname
|
||||||
Ensure-Bucket -BucketId $bucketId -ClientName 'aw-file-operations' -BucketType 'aw.file.operation'
|
Ensure-Bucket -BucketId $bucketId -ClientName 'aw-file-operations' -BucketType 'aw.file.operation'
|
||||||
|
|
||||||
# Разрешение путей для мониторинга
|
# Resolve paths for monitoring
|
||||||
$resolvedPaths = @()
|
$resolvedPaths = @()
|
||||||
foreach ($p in $WatchPaths) {
|
foreach ($p in $WatchPaths) {
|
||||||
$fullPath = $p
|
$fullPath = $p
|
||||||
@@ -126,11 +137,11 @@ foreach ($p in $WatchPaths) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($resolvedPaths.Count -eq 0) {
|
if ($resolvedPaths.Count -eq 0) {
|
||||||
Write-FileCollectorLog "Нет доступных путей для мониторинга. Завершение."
|
Write-FileCollectorLog "No valid watch paths found. Exiting."
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-FileCollectorLog "Запуск мониторинга путей: $($resolvedPaths -join ', ')"
|
Write-FileCollectorLog "Starting watch on paths: $($resolvedPaths -join ', ')"
|
||||||
|
|
||||||
$watchers = @()
|
$watchers = @()
|
||||||
foreach ($path in $resolvedPaths) {
|
foreach ($path in $resolvedPaths) {
|
||||||
@@ -155,7 +166,7 @@ foreach ($path in $resolvedPaths) {
|
|||||||
$watchers += $watcher
|
$watchers += $watcher
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-FileCollectorLog "Коллектор запущен. Ожидание событий..."
|
Write-FileCollectorLog "Collector started. Waiting for events..."
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while ($true) {
|
while ($true) {
|
||||||
@@ -163,7 +174,7 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
Write-FileCollectorLog "Остановка коллектора..."
|
Write-FileCollectorLog "Stopping collector..."
|
||||||
foreach ($w in $watchers) {
|
foreach ($w in $watchers) {
|
||||||
$w.EnableRaisingEvents = $false
|
$w.EnableRaisingEvents = $false
|
||||||
$w.Dispose()
|
$w.Dispose()
|
||||||
|
|||||||
Reference in New Issue
Block a user