feat: storage watchdog — USB disconnect detection, auto-stop, safe eject, auto-reconnect (v0.17.0)
New storage watchdog monitors registered storage paths every 5s. On disconnect (3 consecutive probe failures), auto-stops affected apps, lazy-unmounts stale VFS entries, fires alerts/notifications/hub report. On reconnect (UUID detected), auto-remounts via fstab, cleans stale restic locks, offers app restart. Safe disconnect UI for USB drives: confirmation dialog, stop apps, sync, unmount. Disconnected state visible across all pages (dashboard, settings, backups, monitoring) with hatched red bars and badges. Backup guards skip disconnected drives. 22 files changed (1 new: monitor/watchdog.go), ~1500 lines added. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,8 +25,9 @@ type Notifier struct {
|
||||
enabled bool
|
||||
settings *settings.Settings
|
||||
|
||||
mu sync.Mutex
|
||||
cooldowns map[string]time.Time // event_type -> last notification time
|
||||
mu sync.Mutex
|
||||
cooldowns map[string]time.Time // event_type -> last notification time
|
||||
perEventCooldown map[string]time.Duration // per-event override cooldown durations
|
||||
|
||||
// prevHealthStatus tracks the previous health check status for change detection
|
||||
prevHealthStatus string
|
||||
@@ -50,6 +51,10 @@ func New(hubURL, apiKey, customerID string, sett *settings.Settings, logger *log
|
||||
enabled: enabled,
|
||||
settings: sett,
|
||||
cooldowns: make(map[string]time.Time),
|
||||
perEventCooldown: map[string]time.Duration{
|
||||
"storage_disconnected": 1 * time.Hour,
|
||||
"storage_reconnected": 1 * time.Hour,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,11 +146,14 @@ func (n *Notifier) Notify(eventType, severity, message, details string) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check cooldown
|
||||
// Check cooldown — per-event override takes priority over global
|
||||
cooldownDuration := time.Duration(prefs.CooldownHours) * time.Hour
|
||||
if cooldownDuration == 0 {
|
||||
cooldownDuration = 6 * time.Hour
|
||||
}
|
||||
if override, ok := n.perEventCooldown[eventType]; ok {
|
||||
cooldownDuration = override
|
||||
}
|
||||
|
||||
n.mu.Lock()
|
||||
lastSent, exists := n.cooldowns[eventType]
|
||||
@@ -329,3 +337,19 @@ func classifyWarning(message string) string {
|
||||
func contains(s, substr string) bool {
|
||||
return strings.Contains(s, substr)
|
||||
}
|
||||
|
||||
// NotifyStorageDisconnected sends a notification about a drive disconnection.
|
||||
func (n *Notifier) NotifyStorageDisconnected(label string, stoppedApps []string) {
|
||||
msg := fmt.Sprintf("Meghajtó váratlanul leválasztva: %s", label)
|
||||
details := ""
|
||||
if len(stoppedApps) > 0 {
|
||||
details = fmt.Sprintf("Leállított alkalmazások: %s", strings.Join(stoppedApps, ", "))
|
||||
}
|
||||
n.Notify("storage_disconnected", "critical", msg, details)
|
||||
}
|
||||
|
||||
// NotifyStorageReconnected sends a notification about a drive reconnection.
|
||||
func (n *Notifier) NotifyStorageReconnected(label string) {
|
||||
n.Notify("storage_reconnected", "info",
|
||||
fmt.Sprintf("Meghajtó újra csatlakoztatva: %s. Az alkalmazások manuálisan indíthatók.", label), "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user