diff --git a/internal/tasks/processEvents.go b/internal/tasks/processEvents.go index f46b68a..9b43096 100644 --- a/internal/tasks/processEvents.go +++ b/internal/tasks/processEvents.go @@ -75,6 +75,7 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error { if vmObject.Vm.Config != nil { numRam = vmObject.Vm.Config.Hardware.MemoryMB numVcpus = vmObject.Vm.Config.Hardware.NumCPU + var totalDiskBytes int64 // Calculate the total disk allocated in GB for _, device := range vmObject.Vm.Config.Hardware.Device { @@ -87,9 +88,12 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error { c.Logger.Debug("Adding disk, unknown backing type", "size_bytes", disk.CapacityInBytes) } - totalDiskGB += float64(disk.CapacityInBytes / 1024 / 1024 / 1024) // Convert from bytes to GB + totalDiskBytes += disk.CapacityInBytes + //totalDiskGB += float64(disk.CapacityInBytes / 1024 / 1024 / 1024) // Convert from bytes to GB } } + totalDiskGB = float64(totalDiskBytes / 1024 / 1024 / 1024) + c.Logger.Debug("Converted total disk size", "bytes", totalDiskBytes, "GB", totalDiskGB) // Determine if the VM is a normal VM or an SRM placeholder if vmObject.Vm.Config.ManagedBy != nil && vmObject.Vm.Config.ManagedBy.Type == "com.vmware.vcDr" { diff --git a/server/handler/vmModifyEvent.go b/server/handler/vmModifyEvent.go index 5c8a333..47af039 100644 --- a/server/handler/vmModifyEvent.go +++ b/server/handler/vmModifyEvent.go @@ -241,6 +241,7 @@ func (h *Handler) processConfigChanges(configChanges string) []map[string]string func (h *Handler) calculateNewDiskSize(event models.CloudEventReceived) float64 { var diskSize float64 + var totalDiskBytes int64 h.Logger.Debug("connecting to vcenter") vc := vcenter.New(h.Logger) vc.Login(event.CloudEvent.Source) @@ -252,6 +253,7 @@ func (h *Handler) calculateNewDiskSize(event models.CloudEventReceived) float64 } else { if vmObject.Vm.Config != nil { h.Logger.Debug("Found VM with config, calculating new total disk size", "vmID", event.CloudEvent.Data.VM.VM.Value) + // Calculate the total disk allocated in GB for _, device := range vmObject.Vm.Config.Hardware.Device { if disk, ok := device.(*types.VirtualDisk); ok { @@ -263,9 +265,12 @@ func (h *Handler) calculateNewDiskSize(event models.CloudEventReceived) float64 h.Logger.Debug("Adding disk, unknown backing type", "size_bytes", disk.CapacityInBytes) } - diskSize += float64(disk.CapacityInBytes / 1024 / 1024 / 1024) // Convert from bytes to GB + //diskSize += float64(disk.CapacityInBytes / 1024 / 1024 / 1024) // Convert from bytes to GB + totalDiskBytes += disk.CapacityInBytes } } + diskSize = float64(totalDiskBytes / 1024 / 1024 / 1024) + h.Logger.Debug("Converted total disk size", "bytes", totalDiskBytes, "GB", diskSize) } }