This commit is contained in:
124
server/handler/snapshots.go
Normal file
124
server/handler/snapshots.go
Normal file
@@ -0,0 +1,124 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"vctp/components/views"
|
||||
"vctp/internal/report"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
// SnapshotHourlyList renders the hourly snapshot list page.
|
||||
// @Summary List hourly snapshots
|
||||
// @Description Lists hourly inventory snapshot tables.
|
||||
// @Tags snapshots
|
||||
// @Produce text/html
|
||||
// @Success 200 {string} string "HTML page"
|
||||
// @Failure 500 {string} string "Server error"
|
||||
// @Router /snapshots/hourly [get]
|
||||
func (h *Handler) SnapshotHourlyList(w http.ResponseWriter, r *http.Request) {
|
||||
h.renderSnapshotList(w, r, "inventory_daily_", "Hourly Inventory Snapshots", views.SnapshotHourlyList)
|
||||
}
|
||||
|
||||
// SnapshotDailyList renders the daily snapshot list page.
|
||||
// @Summary List daily snapshots
|
||||
// @Description Lists daily summary snapshot tables.
|
||||
// @Tags snapshots
|
||||
// @Produce text/html
|
||||
// @Success 200 {string} string "HTML page"
|
||||
// @Failure 500 {string} string "Server error"
|
||||
// @Router /snapshots/daily [get]
|
||||
func (h *Handler) SnapshotDailyList(w http.ResponseWriter, r *http.Request) {
|
||||
h.renderSnapshotList(w, r, "inventory_daily_summary_", "Daily Inventory Snapshots", views.SnapshotDailyList)
|
||||
}
|
||||
|
||||
// SnapshotMonthlyList renders the monthly snapshot list page.
|
||||
// @Summary List monthly snapshots
|
||||
// @Description Lists monthly summary snapshot tables.
|
||||
// @Tags snapshots
|
||||
// @Produce text/html
|
||||
// @Success 200 {string} string "HTML page"
|
||||
// @Failure 500 {string} string "Server error"
|
||||
// @Router /snapshots/monthly [get]
|
||||
func (h *Handler) SnapshotMonthlyList(w http.ResponseWriter, r *http.Request) {
|
||||
h.renderSnapshotList(w, r, "inventory_monthly_summary_", "Monthly Inventory Snapshots", views.SnapshotMonthlyList)
|
||||
}
|
||||
|
||||
// SnapshotReportDownload streams a snapshot table as XLSX.
|
||||
// @Summary Download snapshot report
|
||||
// @Description Downloads a snapshot table as an XLSX file.
|
||||
// @Tags snapshots
|
||||
// @Produce application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
||||
// @Param table query string true "Snapshot table name"
|
||||
// @Success 200 {file} file "Snapshot XLSX report"
|
||||
// @Failure 400 {object} map[string]string "Invalid request"
|
||||
// @Failure 500 {object} map[string]string "Server error"
|
||||
// @Router /api/report/snapshot [get]
|
||||
func (h *Handler) SnapshotReportDownload(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.Background()
|
||||
tableName := r.URL.Query().Get("table")
|
||||
if tableName == "" {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
"status": "ERROR",
|
||||
"message": "Missing table parameter",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
reportData, err := report.CreateTableReport(h.Logger, h.Database, ctx, tableName)
|
||||
if err != nil {
|
||||
h.Logger.Error("Failed to create snapshot report", "error", err, "table", tableName)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
"status": "ERROR",
|
||||
"message": fmt.Sprintf("Unable to create snapshot report: '%s'", err),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
filename := fmt.Sprintf("%s.xlsx", tableName)
|
||||
w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename))
|
||||
w.Header().Set("File-Name", filename)
|
||||
w.Write(reportData)
|
||||
}
|
||||
|
||||
func (h *Handler) renderSnapshotList(w http.ResponseWriter, r *http.Request, prefix string, title string, renderer func([]views.SnapshotEntry) templ.Component) {
|
||||
ctx := context.Background()
|
||||
tables, err := report.ListTablesByPrefix(ctx, h.Database, prefix)
|
||||
if err != nil {
|
||||
h.Logger.Error("Failed to list snapshot tables", "error", err, "prefix", prefix)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprintf(w, "Unable to list snapshot tables: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
entries := make([]views.SnapshotEntry, 0, len(tables))
|
||||
for _, table := range tables {
|
||||
if prefix == "inventory_daily_" && strings.HasPrefix(table, "inventory_daily_summary_") {
|
||||
continue
|
||||
}
|
||||
label := table
|
||||
if parsed, ok := report.FormatSnapshotLabel(prefix, table); ok {
|
||||
label = parsed
|
||||
}
|
||||
entries = append(entries, views.SnapshotEntry{
|
||||
Label: label,
|
||||
Link: "/api/report/snapshot?table=" + url.QueryEscape(table),
|
||||
})
|
||||
}
|
||||
|
||||
if err := renderer(entries).Render(r.Context(), w); err != nil {
|
||||
h.Logger.Error("Failed to render snapshot list", "error", err, "title", title)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprintf(w, "Failed to render snapshot list")
|
||||
}
|
||||
}
|
||||
1
server/router/.gitignore
vendored
Normal file
1
server/router/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
swagger-ui-dist/
|
||||
768
server/router/docs/docs.go
Normal file
768
server/router/docs/docs.go
Normal file
@@ -0,0 +1,768 @@
|
||||
// Package docs Code generated by swaggo/swag. DO NOT EDIT
|
||||
package docs
|
||||
|
||||
import "github.com/swaggo/swag"
|
||||
|
||||
const docTemplate = `{
|
||||
"schemes": {{ marshal .Schemes }},
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "{{escape .Description}}",
|
||||
"title": "{{.Title}}",
|
||||
"contact": {},
|
||||
"version": "{{.Version}}"
|
||||
},
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {
|
||||
"/": {
|
||||
"get": {
|
||||
"description": "Renders the main UI page.",
|
||||
"produces": [
|
||||
"text/html"
|
||||
],
|
||||
"tags": [
|
||||
"ui"
|
||||
],
|
||||
"summary": "Home page",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "HTML page",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Render failed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/cleanup/updates": {
|
||||
"delete": {
|
||||
"description": "Removes update records that are no longer associated with a VM.",
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"maintenance"
|
||||
],
|
||||
"summary": "Cleanup updates",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Cleanup completed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/cleanup/vcenter": {
|
||||
"delete": {
|
||||
"description": "Removes all inventory entries associated with a vCenter URL.",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"maintenance"
|
||||
],
|
||||
"summary": "Cleanup vCenter inventory",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "vCenter URL",
|
||||
"name": "vc_url",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Cleanup completed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/encrypt": {
|
||||
"post": {
|
||||
"description": "Encrypts a plaintext value and returns the ciphertext.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"crypto"
|
||||
],
|
||||
"summary": "Encrypt data",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Plaintext payload",
|
||||
"name": "payload",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Ciphertext response",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/event/vm/create": {
|
||||
"post": {
|
||||
"description": "Parses a VM create CloudEvent and stores the event data.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"events"
|
||||
],
|
||||
"summary": "Record VM create event",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "CloudEvent payload",
|
||||
"name": "event",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.CloudEventReceived"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Create event processed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/event/vm/delete": {
|
||||
"post": {
|
||||
"description": "Parses a VM delete CloudEvent and marks the VM as deleted in inventory.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"events"
|
||||
],
|
||||
"summary": "Record VM delete event",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "CloudEvent payload",
|
||||
"name": "event",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.CloudEventReceived"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Delete event processed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/event/vm/modify": {
|
||||
"post": {
|
||||
"description": "Parses a VM modify CloudEvent and creates an update record when relevant changes are detected.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"events"
|
||||
],
|
||||
"summary": "Record VM modify event",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "CloudEvent payload",
|
||||
"name": "event",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.CloudEventReceived"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Modify event processed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"202": {
|
||||
"description": "No relevant changes",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/event/vm/move": {
|
||||
"post": {
|
||||
"description": "Parses a VM move CloudEvent and creates an update record.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"events"
|
||||
],
|
||||
"summary": "Record VM move event",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "CloudEvent payload",
|
||||
"name": "event",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.CloudEventReceived"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Move event processed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/import/vm": {
|
||||
"post": {
|
||||
"description": "Imports existing VM inventory data in bulk.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"inventory"
|
||||
],
|
||||
"summary": "Import VMs",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Bulk import payload",
|
||||
"name": "import",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.ImportReceived"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Import processed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/inventory/vm/delete": {
|
||||
"delete": {
|
||||
"description": "Removes a VM inventory entry by VM ID and datacenter name.",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"inventory"
|
||||
],
|
||||
"summary": "Cleanup VM inventory entry",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "VM ID",
|
||||
"name": "vm_id",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Datacenter name",
|
||||
"name": "datacenter_name",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Cleanup completed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/inventory/vm/update": {
|
||||
"post": {
|
||||
"description": "Queries vCenter and updates inventory records with missing details.",
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"inventory"
|
||||
],
|
||||
"summary": "Refresh VM details",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Update completed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/report/inventory": {
|
||||
"get": {
|
||||
"description": "Generates an inventory XLSX report and returns it as a file download.",
|
||||
"produces": [
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
],
|
||||
"tags": [
|
||||
"reports"
|
||||
],
|
||||
"summary": "Download inventory report",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Inventory XLSX report",
|
||||
"schema": {
|
||||
"type": "file"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Report generation failed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/report/snapshot": {
|
||||
"get": {
|
||||
"description": "Downloads a snapshot table as an XLSX file.",
|
||||
"produces": [
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
],
|
||||
"tags": [
|
||||
"snapshots"
|
||||
],
|
||||
"summary": "Download snapshot report",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Snapshot table name",
|
||||
"name": "table",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Snapshot XLSX report",
|
||||
"schema": {
|
||||
"type": "file"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/report/updates": {
|
||||
"get": {
|
||||
"description": "Generates an updates XLSX report and returns it as a file download.",
|
||||
"produces": [
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
],
|
||||
"tags": [
|
||||
"reports"
|
||||
],
|
||||
"summary": "Download updates report",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Updates XLSX report",
|
||||
"schema": {
|
||||
"type": "file"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Report generation failed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/snapshots/daily": {
|
||||
"get": {
|
||||
"description": "Lists daily summary snapshot tables.",
|
||||
"produces": [
|
||||
"text/html"
|
||||
],
|
||||
"tags": [
|
||||
"snapshots"
|
||||
],
|
||||
"summary": "List daily snapshots",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "HTML page",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/snapshots/hourly": {
|
||||
"get": {
|
||||
"description": "Lists hourly inventory snapshot tables.",
|
||||
"produces": [
|
||||
"text/html"
|
||||
],
|
||||
"tags": [
|
||||
"snapshots"
|
||||
],
|
||||
"summary": "List hourly snapshots",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "HTML page",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/snapshots/monthly": {
|
||||
"get": {
|
||||
"description": "Lists monthly summary snapshot tables.",
|
||||
"produces": [
|
||||
"text/html"
|
||||
],
|
||||
"tags": [
|
||||
"snapshots"
|
||||
],
|
||||
"summary": "List monthly snapshots",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "HTML page",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"models.CloudEventReceived": {
|
||||
"type": "object"
|
||||
},
|
||||
"models.CloudEventResourcePool": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Name": {
|
||||
"type": "string"
|
||||
},
|
||||
"ResourcePool": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Type": {
|
||||
"type": "string"
|
||||
},
|
||||
"Value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"models.CloudEventVm": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Name": {
|
||||
"type": "string"
|
||||
},
|
||||
"Vm": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Type": {
|
||||
"type": "string"
|
||||
},
|
||||
"Value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"models.ImportReceived": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Cluster": {
|
||||
"type": "string"
|
||||
},
|
||||
"CreationTime": {
|
||||
"type": "integer"
|
||||
},
|
||||
"Datacenter": {
|
||||
"type": "string"
|
||||
},
|
||||
"Folder": {
|
||||
"type": "string"
|
||||
},
|
||||
"InitialRam": {
|
||||
"type": "integer"
|
||||
},
|
||||
"InitialVcpus": {
|
||||
"type": "integer"
|
||||
},
|
||||
"Name": {
|
||||
"type": "string"
|
||||
},
|
||||
"PowerState": {
|
||||
"type": "integer"
|
||||
},
|
||||
"ProvisionedDisk": {
|
||||
"type": "number"
|
||||
},
|
||||
"ResourcePool": {
|
||||
"type": "string"
|
||||
},
|
||||
"Vcenter": {
|
||||
"type": "string"
|
||||
},
|
||||
"VmId": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = &swag.Spec{
|
||||
Version: "",
|
||||
Host: "",
|
||||
BasePath: "",
|
||||
Schemes: []string{},
|
||||
Title: "",
|
||||
Description: "",
|
||||
InfoInstanceName: "swagger",
|
||||
SwaggerTemplate: docTemplate,
|
||||
LeftDelim: "{{",
|
||||
RightDelim: "}}",
|
||||
}
|
||||
|
||||
func init() {
|
||||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
||||
}
|
||||
739
server/router/docs/swagger.json
Normal file
739
server/router/docs/swagger.json
Normal file
@@ -0,0 +1,739 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"contact": {}
|
||||
},
|
||||
"paths": {
|
||||
"/": {
|
||||
"get": {
|
||||
"description": "Renders the main UI page.",
|
||||
"produces": [
|
||||
"text/html"
|
||||
],
|
||||
"tags": [
|
||||
"ui"
|
||||
],
|
||||
"summary": "Home page",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "HTML page",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Render failed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/cleanup/updates": {
|
||||
"delete": {
|
||||
"description": "Removes update records that are no longer associated with a VM.",
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"maintenance"
|
||||
],
|
||||
"summary": "Cleanup updates",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Cleanup completed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/cleanup/vcenter": {
|
||||
"delete": {
|
||||
"description": "Removes all inventory entries associated with a vCenter URL.",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"maintenance"
|
||||
],
|
||||
"summary": "Cleanup vCenter inventory",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "vCenter URL",
|
||||
"name": "vc_url",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Cleanup completed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/encrypt": {
|
||||
"post": {
|
||||
"description": "Encrypts a plaintext value and returns the ciphertext.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"crypto"
|
||||
],
|
||||
"summary": "Encrypt data",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Plaintext payload",
|
||||
"name": "payload",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Ciphertext response",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/event/vm/create": {
|
||||
"post": {
|
||||
"description": "Parses a VM create CloudEvent and stores the event data.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"events"
|
||||
],
|
||||
"summary": "Record VM create event",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "CloudEvent payload",
|
||||
"name": "event",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.CloudEventReceived"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Create event processed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/event/vm/delete": {
|
||||
"post": {
|
||||
"description": "Parses a VM delete CloudEvent and marks the VM as deleted in inventory.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"events"
|
||||
],
|
||||
"summary": "Record VM delete event",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "CloudEvent payload",
|
||||
"name": "event",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.CloudEventReceived"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Delete event processed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/event/vm/modify": {
|
||||
"post": {
|
||||
"description": "Parses a VM modify CloudEvent and creates an update record when relevant changes are detected.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"events"
|
||||
],
|
||||
"summary": "Record VM modify event",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "CloudEvent payload",
|
||||
"name": "event",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.CloudEventReceived"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Modify event processed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"202": {
|
||||
"description": "No relevant changes",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/event/vm/move": {
|
||||
"post": {
|
||||
"description": "Parses a VM move CloudEvent and creates an update record.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"events"
|
||||
],
|
||||
"summary": "Record VM move event",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "CloudEvent payload",
|
||||
"name": "event",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.CloudEventReceived"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Move event processed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/import/vm": {
|
||||
"post": {
|
||||
"description": "Imports existing VM inventory data in bulk.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"inventory"
|
||||
],
|
||||
"summary": "Import VMs",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Bulk import payload",
|
||||
"name": "import",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.ImportReceived"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Import processed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/inventory/vm/delete": {
|
||||
"delete": {
|
||||
"description": "Removes a VM inventory entry by VM ID and datacenter name.",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"inventory"
|
||||
],
|
||||
"summary": "Cleanup VM inventory entry",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "VM ID",
|
||||
"name": "vm_id",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Datacenter name",
|
||||
"name": "datacenter_name",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Cleanup completed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/inventory/vm/update": {
|
||||
"post": {
|
||||
"description": "Queries vCenter and updates inventory records with missing details.",
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"inventory"
|
||||
],
|
||||
"summary": "Refresh VM details",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Update completed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/report/inventory": {
|
||||
"get": {
|
||||
"description": "Generates an inventory XLSX report and returns it as a file download.",
|
||||
"produces": [
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
],
|
||||
"tags": [
|
||||
"reports"
|
||||
],
|
||||
"summary": "Download inventory report",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Inventory XLSX report",
|
||||
"schema": {
|
||||
"type": "file"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Report generation failed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/report/snapshot": {
|
||||
"get": {
|
||||
"description": "Downloads a snapshot table as an XLSX file.",
|
||||
"produces": [
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
],
|
||||
"tags": [
|
||||
"snapshots"
|
||||
],
|
||||
"summary": "Download snapshot report",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Snapshot table name",
|
||||
"name": "table",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Snapshot XLSX report",
|
||||
"schema": {
|
||||
"type": "file"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/report/updates": {
|
||||
"get": {
|
||||
"description": "Generates an updates XLSX report and returns it as a file download.",
|
||||
"produces": [
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
],
|
||||
"tags": [
|
||||
"reports"
|
||||
],
|
||||
"summary": "Download updates report",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Updates XLSX report",
|
||||
"schema": {
|
||||
"type": "file"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Report generation failed",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/snapshots/daily": {
|
||||
"get": {
|
||||
"description": "Lists daily summary snapshot tables.",
|
||||
"produces": [
|
||||
"text/html"
|
||||
],
|
||||
"tags": [
|
||||
"snapshots"
|
||||
],
|
||||
"summary": "List daily snapshots",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "HTML page",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/snapshots/hourly": {
|
||||
"get": {
|
||||
"description": "Lists hourly inventory snapshot tables.",
|
||||
"produces": [
|
||||
"text/html"
|
||||
],
|
||||
"tags": [
|
||||
"snapshots"
|
||||
],
|
||||
"summary": "List hourly snapshots",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "HTML page",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/snapshots/monthly": {
|
||||
"get": {
|
||||
"description": "Lists monthly summary snapshot tables.",
|
||||
"produces": [
|
||||
"text/html"
|
||||
],
|
||||
"tags": [
|
||||
"snapshots"
|
||||
],
|
||||
"summary": "List monthly snapshots",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "HTML page",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"models.CloudEventReceived": {
|
||||
"type": "object"
|
||||
},
|
||||
"models.CloudEventResourcePool": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Name": {
|
||||
"type": "string"
|
||||
},
|
||||
"ResourcePool": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Type": {
|
||||
"type": "string"
|
||||
},
|
||||
"Value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"models.CloudEventVm": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Name": {
|
||||
"type": "string"
|
||||
},
|
||||
"Vm": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Type": {
|
||||
"type": "string"
|
||||
},
|
||||
"Value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"models.ImportReceived": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Cluster": {
|
||||
"type": "string"
|
||||
},
|
||||
"CreationTime": {
|
||||
"type": "integer"
|
||||
},
|
||||
"Datacenter": {
|
||||
"type": "string"
|
||||
},
|
||||
"Folder": {
|
||||
"type": "string"
|
||||
},
|
||||
"InitialRam": {
|
||||
"type": "integer"
|
||||
},
|
||||
"InitialVcpus": {
|
||||
"type": "integer"
|
||||
},
|
||||
"Name": {
|
||||
"type": "string"
|
||||
},
|
||||
"PowerState": {
|
||||
"type": "integer"
|
||||
},
|
||||
"ProvisionedDisk": {
|
||||
"type": "number"
|
||||
},
|
||||
"ResourcePool": {
|
||||
"type": "string"
|
||||
},
|
||||
"Vcenter": {
|
||||
"type": "string"
|
||||
},
|
||||
"VmId": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
483
server/router/docs/swagger.yaml
Normal file
483
server/router/docs/swagger.yaml
Normal file
@@ -0,0 +1,483 @@
|
||||
definitions:
|
||||
models.CloudEventReceived:
|
||||
type: object
|
||||
models.CloudEventResourcePool:
|
||||
properties:
|
||||
Name:
|
||||
type: string
|
||||
ResourcePool:
|
||||
properties:
|
||||
Type:
|
||||
type: string
|
||||
Value:
|
||||
type: string
|
||||
type: object
|
||||
type: object
|
||||
models.CloudEventVm:
|
||||
properties:
|
||||
Name:
|
||||
type: string
|
||||
Vm:
|
||||
properties:
|
||||
Type:
|
||||
type: string
|
||||
Value:
|
||||
type: string
|
||||
type: object
|
||||
type: object
|
||||
models.ImportReceived:
|
||||
properties:
|
||||
Cluster:
|
||||
type: string
|
||||
CreationTime:
|
||||
type: integer
|
||||
Datacenter:
|
||||
type: string
|
||||
Folder:
|
||||
type: string
|
||||
InitialRam:
|
||||
type: integer
|
||||
InitialVcpus:
|
||||
type: integer
|
||||
Name:
|
||||
type: string
|
||||
PowerState:
|
||||
type: integer
|
||||
ProvisionedDisk:
|
||||
type: number
|
||||
ResourcePool:
|
||||
type: string
|
||||
Vcenter:
|
||||
type: string
|
||||
VmId:
|
||||
type: string
|
||||
type: object
|
||||
info:
|
||||
contact: {}
|
||||
paths:
|
||||
/:
|
||||
get:
|
||||
description: Renders the main UI page.
|
||||
produces:
|
||||
- text/html
|
||||
responses:
|
||||
"200":
|
||||
description: HTML page
|
||||
schema:
|
||||
type: string
|
||||
"500":
|
||||
description: Render failed
|
||||
schema:
|
||||
type: string
|
||||
summary: Home page
|
||||
tags:
|
||||
- ui
|
||||
/api/cleanup/updates:
|
||||
delete:
|
||||
description: Removes update records that are no longer associated with a VM.
|
||||
produces:
|
||||
- text/plain
|
||||
responses:
|
||||
"200":
|
||||
description: Cleanup completed
|
||||
schema:
|
||||
type: string
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
type: string
|
||||
summary: Cleanup updates
|
||||
tags:
|
||||
- maintenance
|
||||
/api/cleanup/vcenter:
|
||||
delete:
|
||||
description: Removes all inventory entries associated with a vCenter URL.
|
||||
parameters:
|
||||
- description: vCenter URL
|
||||
in: query
|
||||
name: vc_url
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Cleanup completed
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
"400":
|
||||
description: Invalid request
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
summary: Cleanup vCenter inventory
|
||||
tags:
|
||||
- maintenance
|
||||
/api/encrypt:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Encrypts a plaintext value and returns the ciphertext.
|
||||
parameters:
|
||||
- description: Plaintext payload
|
||||
in: body
|
||||
name: payload
|
||||
required: true
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Ciphertext response
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
summary: Encrypt data
|
||||
tags:
|
||||
- crypto
|
||||
/api/event/vm/create:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Parses a VM create CloudEvent and stores the event data.
|
||||
parameters:
|
||||
- description: CloudEvent payload
|
||||
in: body
|
||||
name: event
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.CloudEventReceived'
|
||||
produces:
|
||||
- text/plain
|
||||
responses:
|
||||
"200":
|
||||
description: Create event processed
|
||||
schema:
|
||||
type: string
|
||||
"400":
|
||||
description: Invalid request
|
||||
schema:
|
||||
type: string
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
type: string
|
||||
summary: Record VM create event
|
||||
tags:
|
||||
- events
|
||||
/api/event/vm/delete:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Parses a VM delete CloudEvent and marks the VM as deleted in inventory.
|
||||
parameters:
|
||||
- description: CloudEvent payload
|
||||
in: body
|
||||
name: event
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.CloudEventReceived'
|
||||
produces:
|
||||
- text/plain
|
||||
responses:
|
||||
"200":
|
||||
description: Delete event processed
|
||||
schema:
|
||||
type: string
|
||||
"400":
|
||||
description: Invalid request
|
||||
schema:
|
||||
type: string
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
type: string
|
||||
summary: Record VM delete event
|
||||
tags:
|
||||
- events
|
||||
/api/event/vm/modify:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Parses a VM modify CloudEvent and creates an update record when
|
||||
relevant changes are detected.
|
||||
parameters:
|
||||
- description: CloudEvent payload
|
||||
in: body
|
||||
name: event
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.CloudEventReceived'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Modify event processed
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
"202":
|
||||
description: No relevant changes
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
summary: Record VM modify event
|
||||
tags:
|
||||
- events
|
||||
/api/event/vm/move:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Parses a VM move CloudEvent and creates an update record.
|
||||
parameters:
|
||||
- description: CloudEvent payload
|
||||
in: body
|
||||
name: event
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.CloudEventReceived'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Move event processed
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
"400":
|
||||
description: Invalid request
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
summary: Record VM move event
|
||||
tags:
|
||||
- events
|
||||
/api/import/vm:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Imports existing VM inventory data in bulk.
|
||||
parameters:
|
||||
- description: Bulk import payload
|
||||
in: body
|
||||
name: import
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.ImportReceived'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Import processed
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
summary: Import VMs
|
||||
tags:
|
||||
- inventory
|
||||
/api/inventory/vm/delete:
|
||||
delete:
|
||||
description: Removes a VM inventory entry by VM ID and datacenter name.
|
||||
parameters:
|
||||
- description: VM ID
|
||||
in: query
|
||||
name: vm_id
|
||||
required: true
|
||||
type: string
|
||||
- description: Datacenter name
|
||||
in: query
|
||||
name: datacenter_name
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Cleanup completed
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
"400":
|
||||
description: Invalid request
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
summary: Cleanup VM inventory entry
|
||||
tags:
|
||||
- inventory
|
||||
/api/inventory/vm/update:
|
||||
post:
|
||||
description: Queries vCenter and updates inventory records with missing details.
|
||||
produces:
|
||||
- text/plain
|
||||
responses:
|
||||
"200":
|
||||
description: Update completed
|
||||
schema:
|
||||
type: string
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
type: string
|
||||
summary: Refresh VM details
|
||||
tags:
|
||||
- inventory
|
||||
/api/report/inventory:
|
||||
get:
|
||||
description: Generates an inventory XLSX report and returns it as a file download.
|
||||
produces:
|
||||
- application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
||||
responses:
|
||||
"200":
|
||||
description: Inventory XLSX report
|
||||
schema:
|
||||
type: file
|
||||
"500":
|
||||
description: Report generation failed
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
summary: Download inventory report
|
||||
tags:
|
||||
- reports
|
||||
/api/report/snapshot:
|
||||
get:
|
||||
description: Downloads a snapshot table as an XLSX file.
|
||||
parameters:
|
||||
- description: Snapshot table name
|
||||
in: query
|
||||
name: table
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
||||
responses:
|
||||
"200":
|
||||
description: Snapshot XLSX report
|
||||
schema:
|
||||
type: file
|
||||
"400":
|
||||
description: Invalid request
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
summary: Download snapshot report
|
||||
tags:
|
||||
- snapshots
|
||||
/api/report/updates:
|
||||
get:
|
||||
description: Generates an updates XLSX report and returns it as a file download.
|
||||
produces:
|
||||
- application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
||||
responses:
|
||||
"200":
|
||||
description: Updates XLSX report
|
||||
schema:
|
||||
type: file
|
||||
"500":
|
||||
description: Report generation failed
|
||||
schema:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
summary: Download updates report
|
||||
tags:
|
||||
- reports
|
||||
/snapshots/daily:
|
||||
get:
|
||||
description: Lists daily summary snapshot tables.
|
||||
produces:
|
||||
- text/html
|
||||
responses:
|
||||
"200":
|
||||
description: HTML page
|
||||
schema:
|
||||
type: string
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
type: string
|
||||
summary: List daily snapshots
|
||||
tags:
|
||||
- snapshots
|
||||
/snapshots/hourly:
|
||||
get:
|
||||
description: Lists hourly inventory snapshot tables.
|
||||
produces:
|
||||
- text/html
|
||||
responses:
|
||||
"200":
|
||||
description: HTML page
|
||||
schema:
|
||||
type: string
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
type: string
|
||||
summary: List hourly snapshots
|
||||
tags:
|
||||
- snapshots
|
||||
/snapshots/monthly:
|
||||
get:
|
||||
description: Lists monthly summary snapshot tables.
|
||||
produces:
|
||||
- text/html
|
||||
responses:
|
||||
"200":
|
||||
description: HTML page
|
||||
schema:
|
||||
type: string
|
||||
"500":
|
||||
description: Server error
|
||||
schema:
|
||||
type: string
|
||||
summary: List monthly snapshots
|
||||
tags:
|
||||
- snapshots
|
||||
swagger: "2.0"
|
||||
@@ -1,6 +1,7 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
@@ -46,10 +47,31 @@ func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver st
|
||||
|
||||
mux.HandleFunc("/api/report/inventory", h.InventoryReportDownload)
|
||||
mux.HandleFunc("/api/report/updates", h.UpdateReportDownload)
|
||||
mux.HandleFunc("/api/report/snapshot", h.SnapshotReportDownload)
|
||||
|
||||
mux.HandleFunc("/snapshots/hourly", h.SnapshotHourlyList)
|
||||
mux.HandleFunc("/snapshots/daily", h.SnapshotDailyList)
|
||||
mux.HandleFunc("/snapshots/monthly", h.SnapshotMonthlyList)
|
||||
|
||||
// endpoint for encrypting vcenter credential
|
||||
mux.HandleFunc("/api/encrypt", h.EncryptData)
|
||||
|
||||
// serve swagger related components from the embedded fs
|
||||
swaggerSub, err := fs.Sub(swaggerUI, "swagger-ui-dist")
|
||||
if err != nil {
|
||||
logger.Error("failed to load swagger ui assets", "error", err)
|
||||
} else {
|
||||
mux.Handle("/swagger/", http.StripPrefix("/swagger/", http.FileServer(http.FS(swaggerSub))))
|
||||
}
|
||||
mux.HandleFunc("/swagger", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/swagger/", http.StatusPermanentRedirect)
|
||||
})
|
||||
mux.HandleFunc("/swagger.json", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(swaggerSpec)
|
||||
})
|
||||
|
||||
// Register pprof handlers
|
||||
mux.HandleFunc("/debug/pprof/", pprof.Index)
|
||||
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
||||
|
||||
11
server/router/swagger_embed.go
Normal file
11
server/router/swagger_embed.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"embed"
|
||||
)
|
||||
|
||||
//go:embed swagger-ui-dist/*
|
||||
var swaggerUI embed.FS
|
||||
|
||||
//go:embed docs/swagger.json
|
||||
var swaggerSpec []byte
|
||||
Reference in New Issue
Block a user