VM cannot connect via HTTPS due to self-signed certificate errors. Added: - test-vm-connectivity.ps1: 5-step diagnostic for VM - agent/QUICK-FIX-VM.md: Use HTTP for Hyper-V local network - open-firewall-for-vm.ps1: Open Windows Firewall Since VM and host are on same physical machine (Hyper-V internal network), HTTP is acceptable for local monitoring. For production: Use proper TLS certificates.
97 lines
4.1 KiB
PowerShell
97 lines
4.1 KiB
PowerShell
# Test VM to Host Connectivity
|
|
# Run this ON THE VM to diagnose connection issues
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "ShopDB VM Connectivity Test" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
$HostIP = "172.31.96.1"
|
|
$Port = 5001
|
|
|
|
# Test 1: Ping
|
|
Write-Host "[1/5] Testing ping to host..." -ForegroundColor Yellow
|
|
$ping = Test-Connection -ComputerName $HostIP -Count 2 -Quiet
|
|
if ($ping) {
|
|
Write-Host " OK: Host is reachable" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " FAIL: Cannot ping host" -ForegroundColor Red
|
|
}
|
|
|
|
# Test 2: TCP Port
|
|
Write-Host "[2/5] Testing TCP port $Port..." -ForegroundColor Yellow
|
|
$tcp = Test-NetConnection -ComputerName $HostIP -Port $Port -WarningAction SilentlyContinue
|
|
if ($tcp.TcpTestSucceeded) {
|
|
Write-Host " OK: Port $Port is open" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " FAIL: Port $Port is closed or blocked" -ForegroundColor Red
|
|
Write-Host " Check: Windows Firewall on host PC" -ForegroundColor Yellow
|
|
}
|
|
|
|
# Test 3: HTTP (plain)
|
|
Write-Host "[3/5] Testing HTTP (without SSL)..." -ForegroundColor Yellow
|
|
try {
|
|
$http = Invoke-WebRequest -Uri "http://${HostIP}:${Port}/" -UseBasicParsing -TimeoutSec 5 -ErrorAction Stop
|
|
Write-Host " OK: HTTP works (got $($http.StatusCode))" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host " INFO: HTTP not available (expected - server uses HTTPS)" -ForegroundColor Yellow
|
|
}
|
|
|
|
# Test 4: HTTPS (self-signed cert)
|
|
Write-Host "[4/5] Testing HTTPS (ignoring cert errors)..." -ForegroundColor Yellow
|
|
try {
|
|
# Disable cert validation temporarily
|
|
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
|
|
$https = Invoke-WebRequest -Uri "https://${HostIP}:${Port}/" -UseBasicParsing -TimeoutSec 10 -ErrorAction Stop
|
|
Write-Host " OK: HTTPS works! (got $($https.StatusCode))" -ForegroundColor Green
|
|
Write-Host " Content: $($https.Content.Substring(0, 50))..." -ForegroundColor Gray
|
|
} catch {
|
|
Write-Host " FAIL: HTTPS connection failed" -ForegroundColor Red
|
|
Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red
|
|
} finally {
|
|
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null
|
|
}
|
|
|
|
# Test 5: curl (if available)
|
|
Write-Host "[5/5] Testing with curl..." -ForegroundColor Yellow
|
|
$curlPath = Get-Command curl.exe -ErrorAction SilentlyContinue
|
|
if ($curlPath) {
|
|
$curlResult = & curl.exe -k -s -o $null -w "%{http_code}" "https://${HostIP}:${Port}/" 2>&1
|
|
if ($curlResult -match "^\d{3}$") {
|
|
Write-Host " OK: curl got HTTP $curlResult" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " FAIL: curl error: $curlResult" -ForegroundColor Red
|
|
}
|
|
} else {
|
|
Write-Host " SKIP: curl not found" -ForegroundColor Gray
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "Summary" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "Host IP: $HostIP" -ForegroundColor White
|
|
Write-Host "Port: $Port" -ForegroundColor White
|
|
Write-Host ""
|
|
|
|
if ($tcp.TcpTestSucceeded) {
|
|
Write-Host "Status: Network connectivity OK" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "If agent still fails:" -ForegroundColor Yellow
|
|
Write-Host "1. Check registry key: HKLM:\SOFTWARE\GE\ShopDB\BaseUrl" -ForegroundColor White
|
|
Write-Host "2. Should be: https://${HostIP}:${Port}" -ForegroundColor White
|
|
Write-Host "3. Check collector key matches" -ForegroundColor White
|
|
Write-Host ""
|
|
Write-Host "To ignore SSL cert errors in agent:" -ForegroundColor Yellow
|
|
Write-Host "Use HTTP instead: http://${HostIP}:${Port}" -ForegroundColor White
|
|
} else {
|
|
Write-Host "Status: Connection BLOCKED" -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host "Fix on HOST PC:" -ForegroundColor Yellow
|
|
Write-Host "1. Run: .\open-firewall-for-vm.ps1 (as Administrator)" -ForegroundColor White
|
|
Write-Host "2. Or add firewall rule manually" -ForegroundColor White
|
|
Write-Host "3. Check Docker is running: docker ps" -ForegroundColor White
|
|
}
|
|
Write-Host ""
|