store event type
This commit is contained in:
@@ -47,9 +47,9 @@ RETURNING *;
|
||||
|
||||
-- name: CreateEvent :one
|
||||
INSERT INTO "Events" (
|
||||
"CloudId", "Source", "EventTime", "ChainId", "VmId", "VmName", "EventKey", "DatacenterId", "DatacenterName", "ComputeResourceId", "ComputeResourceName", "UserName"
|
||||
"CloudId", "Source", "EventTime", "ChainId", "VmId", "VmName", "EventType", "EventKey", "DatacenterId", "DatacenterName", "ComputeResourceId", "ComputeResourceName", "UserName"
|
||||
) VALUES(
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
|
@@ -28,9 +28,9 @@ func (q *Queries) CleanupUpdates(ctx context.Context, arg CleanupUpdatesParams)
|
||||
|
||||
const createEvent = `-- name: CreateEvent :one
|
||||
INSERT INTO "Events" (
|
||||
"CloudId", "Source", "EventTime", "ChainId", "VmId", "VmName", "EventKey", "DatacenterId", "DatacenterName", "ComputeResourceId", "ComputeResourceName", "UserName"
|
||||
"CloudId", "Source", "EventTime", "ChainId", "VmId", "VmName", "EventType", "EventKey", "DatacenterId", "DatacenterName", "ComputeResourceId", "ComputeResourceName", "UserName"
|
||||
) VALUES(
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
RETURNING Eid, CloudId, Source, EventTime, ChainId, VmId, EventKey, DatacenterName, ComputeResourceName, UserName, Processed, DatacenterId, ComputeResourceId, VmName, EventType
|
||||
`
|
||||
@@ -42,6 +42,7 @@ type CreateEventParams struct {
|
||||
ChainId string
|
||||
VmId sql.NullString
|
||||
VmName sql.NullString
|
||||
EventType sql.NullString
|
||||
EventKey sql.NullString
|
||||
DatacenterId sql.NullString
|
||||
DatacenterName sql.NullString
|
||||
@@ -58,6 +59,7 @@ func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) (Event
|
||||
arg.ChainId,
|
||||
arg.VmId,
|
||||
arg.VmName,
|
||||
arg.EventType,
|
||||
arg.EventKey,
|
||||
arg.DatacenterId,
|
||||
arg.DatacenterName,
|
||||
|
@@ -68,6 +68,7 @@ func (h *Handler) VmCleanup(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
} else {
|
||||
// Successful cleanup
|
||||
h.Logger.Debug("VM successfully removed from inventory", "vm_name", vm.Name, "iid", vm.Iid, "vm_id", vmId, "datacenter_name", datacenterName)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
|
@@ -14,8 +14,8 @@ import (
|
||||
models "vctp/server/models"
|
||||
)
|
||||
|
||||
// VmCreate receives the CloudEvent for a VM creation
|
||||
func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) {
|
||||
// VmCreateEvent receives the CloudEvent for a VM creation
|
||||
func (h *Handler) VmCreateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
unixTimestamp int64
|
||||
//numVcpus int32
|
||||
@@ -67,6 +67,7 @@ func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) {
|
||||
Source: event.CloudEvent.Source,
|
||||
CloudId: event.CloudEvent.ID,
|
||||
EventTime: sql.NullInt64{Int64: unixTimestamp, Valid: unixTimestamp > 0},
|
||||
EventType: sql.NullString{String: event.CloudEvent.Type, Valid: event.CloudEvent.Type != ""},
|
||||
ChainId: strconv.Itoa(e.ChainID),
|
||||
VmId: sql.NullString{String: e.VM.VM.Value, Valid: e.VM.VM.Value != ""},
|
||||
VmName: sql.NullString{String: e.VM.Name, Valid: e.VM.Name != ""},
|
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
// VmUpdate receives the CloudEvent for a VM modification or move
|
||||
func (h *Handler) VmDelete(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *Handler) VmDeleteEvent(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
deletedTimestamp int64
|
||||
)
|
@@ -18,8 +18,8 @@ import (
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
// VmModify receives the CloudEvent for a VM modification or move
|
||||
func (h *Handler) VmModify(w http.ResponseWriter, r *http.Request) {
|
||||
// VmModifyEvent receives the CloudEvent for a VM modification or move
|
||||
func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
|
||||
var configChanges []map[string]string
|
||||
params := queries.CreateUpdateParams{}
|
||||
var unixTimestamp int64
|
@@ -22,9 +22,9 @@ func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver st
|
||||
|
||||
mux.Handle("/assets/", middleware.CacheMiddleware(http.FileServer(http.FS(dist.AssetsDir))))
|
||||
mux.HandleFunc("/", h.Home)
|
||||
mux.HandleFunc("/api/event/vm/create", h.VmCreate)
|
||||
mux.HandleFunc("/api/event/vm/modify", h.VmModify)
|
||||
mux.HandleFunc("/api/event/vm/delete", h.VmDelete)
|
||||
mux.HandleFunc("/api/event/vm/create", h.VmCreateEvent)
|
||||
mux.HandleFunc("/api/event/vm/modify", h.VmModifyEvent)
|
||||
mux.HandleFunc("/api/event/vm/delete", h.VmDeleteEvent)
|
||||
mux.HandleFunc("/api/import/vm", h.VmImport)
|
||||
// Use this when we need to manually remove a VM from the database to clean up
|
||||
mux.HandleFunc("/api/inventory/vm/delete", h.VmCleanup)
|
||||
|
Reference in New Issue
Block a user