Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
fix: resolve critical stability and auth issues
rcourtman4f40c3d7516b
diff --git a/internal/api/router.go b/internal/api/router.goindex af8e9f1b83..ce4dbb029a 100644--- a/internal/api/router.go+++ b/internal/api/router.go@@ -997,7 +997,13 @@ func (r *Router) setupRoutes() {return ok}- hasValidAPIToken := validateAPIToken(req.Header.Get("X-API-Token"))+ token := req.Header.Get("X-API-Token")+ if token == "" {+ if authHeader := req.Header.Get("Authorization"); strings.HasPrefix(authHeader, "Bearer ") {+ token = strings.TrimPrefix(authHeader, "Bearer ")+ }+ }+ hasValidAPIToken := validateAPIToken(token)// Check if any valid auth method is presenthasValidAuth := hasValidProxyAuth || hasValidSession || hasValidAPIToken@@ -1091,7 +1097,13 @@ func (r *Router) setupRoutes() {return ok}- hasValidAPIToken := validateAPIToken(req.Header.Get("X-API-Token"))+ token := req.Header.Get("X-API-Token")+ if token == "" {+ if authHeader := req.Header.Get("Authorization"); strings.HasPrefix(authHeader, "Bearer ") {+ token = strings.TrimPrefix(authHeader, "Bearer ")+ }+ }+ hasValidAPIToken := validateAPIToken(token)// Check if any valid auth method is presenthasValidAuth := hasValidProxyAuth || hasValidSession || hasValidAPITokendiff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex 9c8b86e991..04ee9c41f7 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -2666,18 +2666,10 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.now := time.Now()hostMetricKey := fmt.Sprintf("host:%s", host.ID)- // Record host CPU usage- m.metricsHistory.AddGuestMetric(hostMetricKey, "cpu", host.CPUUsage, now)-- // Record host Memory usage- m.metricsHistory.AddGuestMetric(hostMetricKey, "memory", host.Memory.Usage, now)-- // Record host Disk usage (use first disk or calculate aggregate)var hostDiskPercent float64if len(host.Disks) > 0 {hostDiskPercent = host.Disks[0].Usage}- m.metricsHistory.AddGuestMetric(hostMetricKey, "disk", hostDiskPercent, now)// Record host Network I/O (sum across all interfaces)var totalRXBytes, totalTXBytes uint64@@ -2685,8 +2677,19 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.totalRXBytes += nic.RXBytestotalTXBytes += nic.TXBytes}- m.metricsHistory.AddGuestMetric(hostMetricKey, "netin", float64(totalRXBytes), now)- m.metricsHistory.AddGuestMetric(hostMetricKey, "netout", float64(totalTXBytes), now)++ if m.metricsHistory != nil {+ // Record host CPU usage+ m.metricsHistory.AddGuestMetric(hostMetricKey, "cpu", host.CPUUsage, now)++ // Record host Memory usage+ m.metricsHistory.AddGuestMetric(hostMetricKey, "memory", host.Memory.Usage, now)++ m.metricsHistory.AddGuestMetric(hostMetricKey, "disk", hostDiskPercent, now)++ m.metricsHistory.AddGuestMetric(hostMetricKey, "netin", float64(totalRXBytes), now)+ m.metricsHistory.AddGuestMetric(hostMetricKey, "netout", float64(totalTXBytes), now)+ }// Also write to persistent SQLite storeif m.metricsStore != nil {@@ -3570,27 +3573,9 @@ func New(cfg *config.Config) (*Monitor, error) {}ms, err := metrics.NewStore(metricsStoreConfig)if err != nil {- log.Error().Err(err).Msg("Failed to initialize persistent metrics store - attempting recovery by clearing DB")-- // Attempt recovery by removing the likely locked/corrupted DB- if err := os.Remove(metricsStoreConfig.DBPath); err != nil {- log.Error().Err(err).Msg("Failed to remove corrupted metrics DB")- } else {- // Remove SHM/WAL files too just in case- os.Remove(metricsStoreConfig.DBPath + "-shm")- os.Remove(metricsStoreConfig.DBPath + "-wal")-- ms, err = metrics.NewStore(metricsStoreConfig)- if err != nil {- log.Error().Err(err).Msg("Failed to initialize persistent metrics store after recovery - continuing with in-memory only")- } else {- if mock.IsMockEnabled() {- ms.SetMaxOpenConns(10)- }- metricsStore = ms- log.Info().Msg("Recovered persistent metrics store by clearing corrupted DB")- }- }+ // Do not automatically delete the DB on error, as it causes data loss on transient errors (e.g. locks).+ // If the DB is truly corrupted, the user should manually remove it.+ log.Error().Err(err).Msg("Failed to initialize persistent metrics store - continuing without metrics persistence")} else {if mock.IsMockEnabled() {ms.SetMaxOpenConns(10)diff --git a/internal/monitoring/reload.go b/internal/monitoring/reload.goindex 615f49448b..20f61bf2f2 100644--- a/internal/monitoring/reload.go+++ b/internal/monitoring/reload.go@@ -100,6 +100,12 @@ func (rm *ReloadableMonitor) doReload() error {rm.cancel()}+ // Stop the underlying multi-tenant monitor to ensure its global context is canceled+ // and all child monitors are stopped.+ if rm.mtMonitor != nil {+ rm.mtMonitor.Stop()+ }+// Wait a moment for cleanuptime.Sleep(1 * time.Second)diff --git a/internal/notifications/notifications.go b/internal/notifications/notifications.goindex f09a3b822e..70df51e522 100644--- a/internal/notifications/notifications.go+++ b/internal/notifications/notifications.go@@ -57,7 +57,6 @@ const (// createSecureWebhookClient creates an HTTP client with security controlsfunc (n *NotificationManager) createSecureWebhookClient(timeout time.Duration) *http.Client {- redirectCount := 0return &http.Client{Timeout: timeout,CheckRedirect: func(req *http.Request, via []*http.Request) error {@@ -66,7 +65,6 @@ func (n *NotificationManager) createSecureWebhookClient(timeout time.Duration) *return fmt.Errorf("stopped after %d redirects", WebhookMaxRedirects)}- redirectCount++newURL := req.URL.String()// Prevent redirects to localhost or private networks (SSRF protection)@@ -82,7 +80,7 @@ func (n *NotificationManager) createSecureWebhookClient(timeout time.Duration) *log.Debug().Str("from", via[len(via)-1].URL.String()).Str("to", newURL).- Int("redirectCount", redirectCount).+ Int("redirectCount", len(via)).Msg("Following webhook redirect")return nil