Files
Comtropy_CargoRadar/scripts/health-check.ps1

33 lines
745 B
PowerShell

param(
[string]$BaseUrl = "http://127.0.0.1:8080",
[string]$AdminToken = ""
)
$ErrorActionPreference = "Stop"
function Invoke-CargoRadarJson {
param(
[Parameter(Mandatory = $true)]
[string]$Path
)
$headers = @{}
if ($AdminToken) {
$headers["X-Admin-Token"] = $AdminToken
}
Invoke-RestMethod -Uri "$BaseUrl$Path" -Method Get -Headers $headers
}
$health = Invoke-CargoRadarJson -Path "/health"
$drivers = Invoke-CargoRadarJson -Path "/api/v1/drivers"
$latest = Invoke-CargoRadarJson -Path "/api/v1/locations/latest"
[pscustomobject]@{
BaseUrl = $BaseUrl
Health = $health.status
ServerTime = $health.time
DriverCount = $drivers.drivers.Count
LatestLocationCount = $latest.locations.Count
} | Format-List