This commit is contained in:
@@ -801,7 +801,11 @@ func writeTotalsChart(logger *slog.Logger, xlsx *excelize.File, sheetName string
|
||||
if len(points) == 0 {
|
||||
return
|
||||
}
|
||||
index := xlsx.NewSheet(sheetName)
|
||||
index, err := xlsx.NewSheet(sheetName)
|
||||
if err != nil {
|
||||
logger.Error("Error creating totals sheet", "error", err)
|
||||
return
|
||||
}
|
||||
xlsx.SetActiveSheet(index)
|
||||
|
||||
headers := []string{"Label", "VmCount", "VcpuCount", "RamGB", "PresenceRatio", "Tin", "Bronze", "Silver", "Gold"}
|
||||
@@ -823,29 +827,23 @@ func writeTotalsChart(logger *slog.Logger, xlsx *excelize.File, sheetName string
|
||||
}
|
||||
|
||||
lastRow := len(points) + 1
|
||||
chart := fmt.Sprintf(`{
|
||||
"type": "line",
|
||||
"series": [
|
||||
{"name": "%s!$B$1", "categories": "%s!$A$2:$A$%d", "values": "%s!$B$2:$B$%d"},
|
||||
{"name": "%s!$C$1", "categories": "%s!$A$2:$A$%d", "values": "%s!$C$2:$C$%d"},
|
||||
{"name": "%s!$D$1", "categories": "%s!$A$2:$A$%d", "values": "%s!$D$2:$D$%d"},
|
||||
{"name": "%s!$E$1", "categories": "%s!$A$2:$A$%d", "values": "%s!$E$2:$E$%d"},
|
||||
{"name": "%s!$F$1", "categories": "%s!$A$2:$A$%d", "values": "%s!$F$2:$F$%d"},
|
||||
{"name": "%s!$G$1", "categories": "%s!$A$2:$A$%d", "values": "%s!$G$2:$G$%d"},
|
||||
{"name": "%s!$H$1", "categories": "%s!$A$2:$A$%d", "values": "%s!$H$2:$H$%d"},
|
||||
{"name": "%s!$I$1", "categories": "%s!$A$2:$A$%d", "values": "%s!$I$2:$I$%d"}
|
||||
],
|
||||
"legend": {"position": "bottom"}
|
||||
}`, sheetName, sheetName, lastRow, sheetName, lastRow,
|
||||
sheetName, sheetName, lastRow, sheetName, lastRow,
|
||||
sheetName, sheetName, lastRow, sheetName, lastRow,
|
||||
sheetName, sheetName, lastRow, sheetName, lastRow,
|
||||
sheetName, sheetName, lastRow, sheetName, lastRow,
|
||||
sheetName, sheetName, lastRow, sheetName, lastRow,
|
||||
sheetName, sheetName, lastRow, sheetName, lastRow,
|
||||
sheetName, sheetName, lastRow, sheetName, lastRow)
|
||||
series := []excelize.ChartSeries{
|
||||
{Name: fmt.Sprintf("%s!$B$1", sheetName), Categories: fmt.Sprintf("%s!$A$2:$A$%d", sheetName, lastRow), Values: fmt.Sprintf("%s!$B$2:$B$%d", sheetName, lastRow)},
|
||||
{Name: fmt.Sprintf("%s!$C$1", sheetName), Categories: fmt.Sprintf("%s!$A$2:$A$%d", sheetName, lastRow), Values: fmt.Sprintf("%s!$C$2:$C$%d", sheetName, lastRow)},
|
||||
{Name: fmt.Sprintf("%s!$D$1", sheetName), Categories: fmt.Sprintf("%s!$A$2:$A$%d", sheetName, lastRow), Values: fmt.Sprintf("%s!$D$2:$D$%d", sheetName, lastRow)},
|
||||
{Name: fmt.Sprintf("%s!$E$1", sheetName), Categories: fmt.Sprintf("%s!$A$2:$A$%d", sheetName, lastRow), Values: fmt.Sprintf("%s!$E$2:$E$%d", sheetName, lastRow)},
|
||||
{Name: fmt.Sprintf("%s!$F$1", sheetName), Categories: fmt.Sprintf("%s!$A$2:$A$%d", sheetName, lastRow), Values: fmt.Sprintf("%s!$F$2:$F$%d", sheetName, lastRow)},
|
||||
{Name: fmt.Sprintf("%s!$G$1", sheetName), Categories: fmt.Sprintf("%s!$A$2:$A$%d", sheetName, lastRow), Values: fmt.Sprintf("%s!$G$2:$G$%d", sheetName, lastRow)},
|
||||
{Name: fmt.Sprintf("%s!$H$1", sheetName), Categories: fmt.Sprintf("%s!$A$2:$A$%d", sheetName, lastRow), Values: fmt.Sprintf("%s!$H$2:$H$%d", sheetName, lastRow)},
|
||||
{Name: fmt.Sprintf("%s!$I$1", sheetName), Categories: fmt.Sprintf("%s!$A$2:$A$%d", sheetName, lastRow), Values: fmt.Sprintf("%s!$I$2:$I$%d", sheetName, lastRow)},
|
||||
}
|
||||
chart := excelize.Chart{
|
||||
Type: excelize.Line,
|
||||
Series: series,
|
||||
Legend: excelize.ChartLegend{Position: "bottom"},
|
||||
}
|
||||
|
||||
if err := xlsx.AddChart(sheetName, "G2", chart); err != nil {
|
||||
if err := xlsx.AddChart(sheetName, "G2", &chart); err != nil {
|
||||
logger.Error("Error adding totals chart", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"vctp/db"
|
||||
"vctp/internal/secrets"
|
||||
"vctp/internal/settings"
|
||||
"vctp/internal/vcenter"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
// Handler handles requests.
|
||||
@@ -24,6 +20,7 @@ type Handler struct {
|
||||
Settings *settings.Settings
|
||||
}
|
||||
|
||||
/*
|
||||
func (h *Handler) html(ctx context.Context, w http.ResponseWriter, status int, t templ.Component) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.WriteHeader(status)
|
||||
@@ -32,3 +29,4 @@ func (h *Handler) html(ctx context.Context, w http.ResponseWriter, status int, t
|
||||
h.Logger.Error("Failed to render component", "error", err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -116,22 +116,23 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
|
||||
params.UpdateType = "reconfigure"
|
||||
}
|
||||
case "config.managedBy": // This changes when a VM becomes a placeholder or vice versa
|
||||
if change["newValue"] == "(extensionKey = \"com.vmware.vcDr\", type = \"placeholderVm\")" {
|
||||
switch change["newValue"] {
|
||||
case "(extensionKey = \"com.vmware.vcDr\", type = \"placeholderVm\")":
|
||||
params.PlaceholderChange = sql.NullString{String: "placeholderVm", Valid: true}
|
||||
h.Logger.Debug("placeholderVm")
|
||||
changeFound = true
|
||||
params.UpdateType = "srm"
|
||||
} else if change["newValue"] == "<unset>" {
|
||||
case "<unset>":
|
||||
params.PlaceholderChange = sql.NullString{String: "Vm", Valid: true}
|
||||
h.Logger.Debug("vm")
|
||||
changeFound = true
|
||||
params.UpdateType = "srm"
|
||||
} else if change["newValue"] == "testVm" {
|
||||
case "testVm":
|
||||
h.Logger.Debug("testVm")
|
||||
params.PlaceholderChange = sql.NullString{String: "testVm", Valid: true}
|
||||
changeFound = true
|
||||
params.UpdateType = "srm"
|
||||
} else {
|
||||
default:
|
||||
h.Logger.Error("Unexpected value for managedBy configuration", "new_value", change["newValue"])
|
||||
}
|
||||
|
||||
@@ -145,12 +146,13 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO - track when this happens, maybe need a new database column?
|
||||
case "config.managedBy.type":
|
||||
h.Logger.Debug("config.managedBy.type")
|
||||
if change["newValue"] == "testVm" {
|
||||
switch change["newValue"] {
|
||||
case "testVm":
|
||||
h.Logger.Debug("testVm")
|
||||
params.PlaceholderChange = sql.NullString{String: "testVm", Valid: true}
|
||||
changeFound = true
|
||||
params.UpdateType = "srm"
|
||||
} else if change["newValue"] == "\\\"placeholderVm\\\"" {
|
||||
case "\\\"placeholderVm\\\"":
|
||||
h.Logger.Debug("placeholderVm")
|
||||
params.PlaceholderChange = sql.NullString{String: "placeholderVm", Valid: true}
|
||||
changeFound = true
|
||||
|
||||
Reference in New Issue
Block a user