Skip to content

Commit a4d85f0

Browse files
committed
fix(main,vmware): display errors at the end of the main function and fix undefined probability in vmware
1 parent 4c098e3 commit a4d85f0

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

cmd/netbox-ssot/main.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func main() {
7474
// Variable to store if the run was successful. If it wasn't we don't remove orphans.
7575
successfullRun := true
7676
// Variable to store failed sourcesFalse
77-
encounteredErrors := map[string]bool{}
77+
encounteredErrors := map[string]error{}
7878

7979
// Go through all sources and sync data
8080
var wg sync.WaitGroup
@@ -104,7 +104,7 @@ func main() {
104104
if err != nil {
105105
ssotLogger.Error(sourceCtx, err)
106106
successfullRun = false
107-
encounteredErrors[sourceName] = true
107+
encounteredErrors[sourceName] = err
108108
return
109109
}
110110
ssotLogger.Infof(sourceCtx, "Successfully initialized source %s", constants.CheckMark)
@@ -115,7 +115,7 @@ func main() {
115115
if err != nil {
116116
successfullRun = false
117117
ssotLogger.Error(sourceCtx, err)
118-
encounteredErrors[sourceName] = true
118+
encounteredErrors[sourceName] = err
119119
return
120120
}
121121
ssotLogger.Infof(sourceCtx, "Source synced successfully %s", constants.CheckMark)
@@ -148,8 +148,8 @@ func main() {
148148
seconds,
149149
)
150150
} else {
151-
for source := range encounteredErrors {
152-
ssotLogger.Infof(mainCtx, "%s syncing of source %s failed", constants.WarningSign, source)
151+
for source, err := range encounteredErrors {
152+
ssotLogger.Infof(mainCtx, "%s syncing of source %s failed with: %v", constants.WarningSign, source, err)
153153
}
154154
os.Exit(1)
155155
}

internal/source/vmware/vmware_sync.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,11 @@ func (vc *VmwareSource) syncVM(
10661066
}
10671067

10681068
// vmVCPUs and vmMemory
1069-
vmVCPUs := vm.Config.Hardware.NumCPU
1070-
vmMemoryMB := vm.Config.Hardware.MemoryMB
1069+
var vmVCPUs, vmMemoryMB int32
1070+
if vm.Config != nil {
1071+
vmVCPUs = vm.Config.Hardware.NumCPU
1072+
vmMemoryMB = vm.Config.Hardware.MemoryMB
1073+
}
10711074

10721075
// DisksSize
10731076
// vmTotalDiskSizeMiB := int64(0)

0 commit comments

Comments
 (0)