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.
This commit is contained in:
rcourtman
2026-06-26 11:35:12 +01:00
parent 47d6ad94db
commit adf6c6f1e5
3 changed files with 9 additions and 7 deletions
+5 -3
View File
@@ -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 == "" {
@@ -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},
@@ -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 {