From 3f2a67cf7b0e464b9f2428d19a1672a7f2af2e66 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Fri, 13 Sep 2024 09:11:31 +1000 Subject: [PATCH] store more fields in db --- server/handler/vmCreate.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/handler/vmCreate.go b/server/handler/vmCreate.go index 7d03dea..087f385 100644 --- a/server/handler/vmCreate.go +++ b/server/handler/vmCreate.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "runtime" + "strconv" "time" queries "vctp/db/queries" "vctp/internal/vcenter" @@ -74,6 +75,8 @@ func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) { params := queries.CreateInventoryParams{ Name: vm.CloudEvent.Data.VM.Name, Vcenter: vm.CloudEvent.Source, + EventId: sql.NullString{String: vm.CloudEvent.ID, Valid: vm.CloudEvent.ID != ""}, + EventKey: sql.NullString{String: strconv.Itoa(vm.CloudEvent.Data.Key), Valid: strconv.Itoa(vm.CloudEvent.Data.Key) != ""}, VmId: sql.NullString{String: "VirtualMachine-" + vm.CloudEvent.Data.VM.VM.Value, Valid: vm.CloudEvent.Data.VM.VM.Value != ""}, Datacenter: sql.NullString{String: vmObject.Datacenter, Valid: vmObject.Datacenter != ""}, CreationTime: sql.NullInt64{Int64: unixTimestamp, Valid: unixTimestamp > 0}, @@ -81,7 +84,7 @@ func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) { InitialRam: sql.NullInt64{Int64: int64(numRam), Valid: numRam > 0}, } - h.Logger.Debug("database params", "vm", vm) + h.Logger.Debug("database params", "params", params) // Insert the new inventory record into the database result, err := h.Database.Queries().CreateInventory(context.Background(), params)