feat: Hub monitoring takeover — event push system + config cleanup (v0.21.0)
Replace external Healthchecks.io with Hub-native event system. Controller now pushes structured events via POST /api/v1/event with typed detail structs. Hub handles dead man's switch, notification dispatch, and cooldowns. Phase 5: PushEvent() core method, 21 event types, expanded notification settings (11 toggles), Hub connection monitoring on dashboard, alerts. Phase 6: Deprecation log for ping UUIDs, pinger kept for transition. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/backup"
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/config"
|
||||
@@ -27,9 +28,10 @@ type Alert struct {
|
||||
// Alerts are state-based (not event-based) — they reflect current system state
|
||||
// and are regenerated after each health check cycle.
|
||||
type AlertManager struct {
|
||||
mu sync.RWMutex
|
||||
alerts []Alert
|
||||
logger *log.Logger
|
||||
mu sync.RWMutex
|
||||
alerts []Alert
|
||||
logger *log.Logger
|
||||
hubPushStatusFn func() HubPushStatusData
|
||||
}
|
||||
|
||||
// NewAlertManager creates a new AlertManager.
|
||||
@@ -39,6 +41,13 @@ func NewAlertManager(logger *log.Logger) *AlertManager {
|
||||
}
|
||||
}
|
||||
|
||||
// SetHubPushStatus sets the hub push status callback for generating hub alerts.
|
||||
func (am *AlertManager) SetHubPushStatus(fn func() HubPushStatusData) {
|
||||
am.mu.Lock()
|
||||
am.hubPushStatusFn = fn
|
||||
am.mu.Unlock()
|
||||
}
|
||||
|
||||
// Refresh regenerates alerts from the latest health check report and config state.
|
||||
// Called after each health check cycle (every 5 minutes) and on storage state changes.
|
||||
func (am *AlertManager) Refresh(report *monitor.HealthReport, cfg *config.Config, backupMgr *backup.Manager, updateAvailable bool, latestVersion string, storagePaths ...[]settings.StoragePath) {
|
||||
@@ -92,14 +101,22 @@ func (am *AlertManager) Refresh(report *monitor.HealthReport, cfg *config.Config
|
||||
alerts = append(alerts, alert)
|
||||
}
|
||||
|
||||
// Missing ping UUIDs
|
||||
if cfg.Monitoring.Enabled {
|
||||
missing := countMissingPings(cfg)
|
||||
if missing > 0 {
|
||||
// Hub connection status
|
||||
if !cfg.Hub.Enabled || cfg.Hub.URL == "" {
|
||||
alerts = append(alerts, Alert{
|
||||
ID: "hub-disabled",
|
||||
Level: "warning",
|
||||
Message: "Hub kapcsolat kikapcsolva — a központi monitoring nem aktív",
|
||||
Link: "/monitoring",
|
||||
LinkText: "Rendszermonitor",
|
||||
})
|
||||
} else if am.hubPushStatusFn != nil {
|
||||
ps := am.hubPushStatusFn()
|
||||
if ps.LastError != "" && (ps.LastSuccess.IsZero() || time.Since(ps.LastSuccess) > 30*time.Minute) {
|
||||
alerts = append(alerts, Alert{
|
||||
ID: "pings-missing",
|
||||
Level: "warning",
|
||||
Message: fmt.Sprintf("%d monitoring ellenőrzés nincs beállítva", missing),
|
||||
ID: "hub-unreachable",
|
||||
Level: "error",
|
||||
Message: fmt.Sprintf("Hub nem elérhető — utolsó hiba: %s", ps.LastError),
|
||||
Link: "/monitoring",
|
||||
LinkText: "Rendszermonitor",
|
||||
})
|
||||
@@ -200,24 +217,6 @@ func (am *AlertManager) GetInlineAlerts(page string) []Alert {
|
||||
return result
|
||||
}
|
||||
|
||||
// countMissingPings counts how many ping UUIDs are not configured.
|
||||
func countMissingPings(cfg *config.Config) int {
|
||||
count := 0
|
||||
uuids := []string{
|
||||
cfg.Monitoring.PingUUIDs.Heartbeat,
|
||||
cfg.Monitoring.PingUUIDs.SystemHealth,
|
||||
cfg.Monitoring.PingUUIDs.DBDump,
|
||||
cfg.Monitoring.PingUUIDs.Backup,
|
||||
cfg.Monitoring.PingUUIDs.BackupIntegrity,
|
||||
}
|
||||
for _, uuid := range uuids {
|
||||
if !isPingConfigured(uuid) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// simpleHash returns a short deterministic hash for deduplication.
|
||||
func simpleHash(s string) string {
|
||||
h := uint32(0)
|
||||
|
||||
Reference in New Issue
Block a user