Fold alerts under their host, recurring maintenance, run playbooks from alerts, and an Updates page

- Servers can say what they run on (or it is worked out from the Proxmox node); when the host is
  down the guests' offline alerts fold under it: held back, not counted, not notified, still recorded.
- Recurring maintenance schedules made into ordinary windows a week ahead (maintenance_schedules).
- Run a Semaphore template limited to a server from its page or an alert, and watch the run.
- Agents report pending updates (apt, dnf, zypper, Windows Update); an Updates page lists them.
- Migrations 0024 and 0025.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-17 01:35:15 +02:00
1 parent 44e393f172
commit 171511c6db
45 files changed
+6772 -44

No files matched your search

+49
View File
@@ -220,6 +220,50 @@ function Get-ListeningPorts {
return @($rows | Where-Object { $_.port -ge 1 -and $_.port -le 65535 } | Select-Object -First 2000)
}
# ---- updates waiting to be installed ------------------------------------------------------------
$script:UpdatesCachePath = Join-Path $env:ProgramData 'HomelabManager\updates.json'
function Test-RebootRequired {
foreach ($key in @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired',
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending')) {
if (Test-Path $key) { return $true }
}
return $false
}
# Asks Windows Update what is waiting. That goes over the network and can take a minute, so it is done at most every six hours and the
# last answer is reused in between; whether a restart is due is cheap and always read fresh. Nothing is installed or downloaded.
function Get-PendingUpdates {
$result = $null
try {
if (Test-Path $script:UpdatesCachePath) {
$cached = Get-Content -Raw -Path $script:UpdatesCachePath | ConvertFrom-Json
$checked = [datetime]::Parse([string]$cached.checked_at, [Globalization.CultureInfo]::InvariantCulture, [Globalization.DateTimeStyles]::RoundtripKind)
if (([datetime]::UtcNow - $checked.ToUniversalTime()).TotalHours -lt 6) { $result = $cached }
}
} catch { $result = $null }
if (-not $result) {
$session = New-Object -ComObject Microsoft.Update.Session
$found = $session.CreateUpdateSearcher().Search("IsInstalled=0 and IsHidden=0 and Type='Software'")
$security = 0
foreach ($u in $found.Updates) {
foreach ($c in $u.Categories) {
if ($c.Name -eq 'Security Updates' -or $c.Name -eq 'Critical Updates') { $security++; break }
}
}
$result = [pscustomobject][ordered]@{ checked_at = [datetime]::UtcNow.ToString('o'); count = [int]$found.Updates.Count; security = [int]$security }
try {
$dir = Split-Path $script:UpdatesCachePath
if (-not (Test-Path $dir)) { $null = New-Item -ItemType Directory -Path $dir -Force }
ConvertTo-Json -InputObject $result | Set-Content -Path $script:UpdatesCachePath -Encoding UTF8
} catch { }
}
return [ordered]@{ manager = 'windows-update'; count = [int]$result.count; security = [int]$result.security; reboot_required = (Test-RebootRequired) }
}
function Get-SystemInfo {
$ips = @(Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue |
Where-Object { $_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.254.*' -and $_.AddressState -eq 'Preferred' } |
@@ -240,7 +284,12 @@ function Get-SystemInfo {
$disks += [pscustomobject][ordered]@{ mount = [string]$d.DeviceID; size_bytes = [int64]$d.Size; used_bytes = [int64]($d.Size - $d.FreeSpace) }
}
# Best-effort: Windows Update being unreachable must not cost the rest of the report.
$updates = $null
try { $updates = Get-PendingUpdates } catch { Write-Warning "Checking for updates failed. ($($_.Exception.Message))" }
return [ordered]@{
updates = $updates
ip_addresses = @($ips)
cpu = [ordered]@{ model = [string]($cpus[0].Name).Trim(); cores = [int]$cores; load_percent = $(if ($null -ne $load) { [math]::Round([double]$load, 1) } else { $null }) }
memory = [ordered]@{ total_bytes = $totalBytes; used_bytes = ($totalBytes - $freeBytes) }