From adf6c6f1e5cc9f6205062586df27e27284018cd7 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Fri, 26 Jun 2026 11:35:12 +0100 Subject: [PATCH] fix: treat absent onboot as no-autostart (Proxmox default) for alert suppression parseProxmoxOnBoot returned nil when the onboot key was absent from a valid config, but Proxmox's default is onboot=0 (do not start on boot). This caused stopped VMs without an explicit onboot line (like windows-runner and tails-anon) to still generate powered-off alerts despite not being configured to autostart. Now returns false for absent keys in non-empty configs. nil is reserved for empty/failed config fetches and unrecognised values, preserving the 'unknown' fallback for genuine uncertainty. --- internal/monitoring/container_parsing.go | 8 +++++--- internal/monitoring/container_parsing_test.go | 2 +- internal/monitoring/monitor_pve_guest_builders.go | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/monitoring/container_parsing.go b/internal/monitoring/container_parsing.go index ac231709e..708af50f9 100644 --- a/internal/monitoring/container_parsing.go +++ b/internal/monitoring/container_parsing.go @@ -492,15 +492,17 @@ func extractContainerOSType(config map[string]interface{}) string { } // parseProxmoxOnBoot extracts the onboot (autostart) setting from a Proxmox -// guest config map. Returns nil when the key is absent or unrecognised so -// callers can distinguish "explicitly off" from "unknown". +// guest config map. Returns nil only when the config is empty/unavailable or +// the value is unrecognised. When the onboot key is absent from a valid config, +// returns false because Proxmox's default is "do not start on boot". func parseProxmoxOnBoot(config map[string]interface{}) *bool { if len(config) == 0 { return nil } raw, ok := config["onboot"] if !ok || raw == nil { - return nil + v := false + return &v } s := strings.TrimSpace(fmt.Sprint(raw)) if s == "" { diff --git a/internal/monitoring/container_parsing_test.go b/internal/monitoring/container_parsing_test.go index d872f3820..40afe2ea7 100644 --- a/internal/monitoring/container_parsing_test.go +++ b/internal/monitoring/container_parsing_test.go @@ -1965,7 +1965,7 @@ func TestParseProxmoxOnBoot(t *testing.T) { }{ {name: "nil config", config: nil, wantNil: true}, {name: "empty config", config: map[string]interface{}{}, wantNil: true}, - {name: "missing key", config: map[string]interface{}{"ostype": "debian"}, wantNil: true}, + {name: "missing key", config: map[string]interface{}{"ostype": "debian"}, wantVal: false}, {name: "onboot 1 (string)", config: map[string]interface{}{"onboot": "1"}, wantVal: true}, {name: "onboot 0 (string)", config: map[string]interface{}{"onboot": "0"}, wantVal: false}, {name: "onboot true", config: map[string]interface{}{"onboot": "true"}, wantVal: true}, diff --git a/internal/monitoring/monitor_pve_guest_builders.go b/internal/monitoring/monitor_pve_guest_builders.go index b9c80c854..9a5edba28 100644 --- a/internal/monitoring/monitor_pve_guest_builders.go +++ b/internal/monitoring/monitor_pve_guest_builders.go @@ -397,9 +397,9 @@ func (m *Monitor) buildVMFromClusterResource( } // fetchVMOnBoot retrieves the onboot (autostart) setting for a stopped VM by -// fetching its config. Returns nil when the config is unavailable or the -// onboot key is absent, so callers can distinguish "explicitly off" from -// "unknown". Uses a type assertion because PVEClientInterface does not include +// fetching its config. Returns nil only when the config is unavailable or the +// value is unrecognised. When onboot is absent from a valid config, returns +// false because Proxmox's default is "do not start on boot". Uses a type assertion because PVEClientInterface does not include // GetVMConfig (it is only on the concrete client, matching the pattern in // guest_config.go). func (m *Monitor) fetchVMOnBoot(ctx context.Context, client PVEClientInterface, node string, vmid int) *bool {