From a4d85f0527364e94a3030bea560500f320c328e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C5=A1per=20Oblak?= Date: Fri, 28 Feb 2025 14:06:32 +0100 Subject: [PATCH] fix(main,vmware): display errors at the end of the main function and fix undefined probability in vmware --- cmd/netbox-ssot/main.go | 10 +++++----- internal/source/vmware/vmware_sync.go | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/netbox-ssot/main.go b/cmd/netbox-ssot/main.go index c8b37f3..2e36f21 100644 --- a/cmd/netbox-ssot/main.go +++ b/cmd/netbox-ssot/main.go @@ -74,7 +74,7 @@ func main() { // Variable to store if the run was successful. If it wasn't we don't remove orphans. successfullRun := true // Variable to store failed sourcesFalse - encounteredErrors := map[string]bool{} + encounteredErrors := map[string]error{} // Go through all sources and sync data var wg sync.WaitGroup @@ -104,7 +104,7 @@ func main() { if err != nil { ssotLogger.Error(sourceCtx, err) successfullRun = false - encounteredErrors[sourceName] = true + encounteredErrors[sourceName] = err return } ssotLogger.Infof(sourceCtx, "Successfully initialized source %s", constants.CheckMark) @@ -115,7 +115,7 @@ func main() { if err != nil { successfullRun = false ssotLogger.Error(sourceCtx, err) - encounteredErrors[sourceName] = true + encounteredErrors[sourceName] = err return } ssotLogger.Infof(sourceCtx, "Source synced successfully %s", constants.CheckMark) @@ -148,8 +148,8 @@ func main() { seconds, ) } else { - for source := range encounteredErrors { - ssotLogger.Infof(mainCtx, "%s syncing of source %s failed", constants.WarningSign, source) + for source, err := range encounteredErrors { + ssotLogger.Infof(mainCtx, "%s syncing of source %s failed with: %v", constants.WarningSign, source, err) } os.Exit(1) } diff --git a/internal/source/vmware/vmware_sync.go b/internal/source/vmware/vmware_sync.go index e37fdb9..3b3d165 100644 --- a/internal/source/vmware/vmware_sync.go +++ b/internal/source/vmware/vmware_sync.go @@ -1066,8 +1066,11 @@ func (vc *VmwareSource) syncVM( } // vmVCPUs and vmMemory - vmVCPUs := vm.Config.Hardware.NumCPU - vmMemoryMB := vm.Config.Hardware.MemoryMB + var vmVCPUs, vmMemoryMB int32 + if vm.Config != nil { + vmVCPUs = vm.Config.Hardware.NumCPU + vmMemoryMB = vm.Config.Hardware.MemoryMB + } // DisksSize // vmTotalDiskSizeMiB := int64(0)