From ed235d6e6d40fa56180c4379fa7d0b018f3aa0cc Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Sun, 15 Mar 2026 21:56:26 -0400 Subject: [PATCH] Send email alerts when monitored servers go offline/online (#529) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing NotifyOnConnectionLost/Restored settings only sent tray notifications. Now also sends an email (if SMTP is configured) on the online→offline transition and a "Server Restored" email when it comes back. Fires exactly once per transition — no repeated alerts while the server stays down. Co-Authored-By: Claude Opus 4.6 (1M context) --- Dashboard/MainWindow.xaml.cs | 19 +++++++++++++++++++ Dashboard/Services/EmailTemplateBuilder.cs | 2 ++ 2 files changed, 21 insertions(+) diff --git a/Dashboard/MainWindow.xaml.cs b/Dashboard/MainWindow.xaml.cs index 44a66a60..8d67436b 100644 --- a/Dashboard/MainWindow.xaml.cs +++ b/Dashboard/MainWindow.xaml.cs @@ -423,10 +423,29 @@ private async System.Threading.Tasks.Task CheckAllConnectionsAsync() _notificationService?.ShowServerOfflineNotification( item.DisplayName, newStatus.ErrorMessage); + + var errorDetail = newStatus.ErrorMessage ?? "Connection failed"; + _emailAlertService.RecordAlert(item.Id, item.DisplayName, "Server Unreachable", + errorDetail, "Online", true, "email"); + _ = _emailAlertService.TrySendAlertEmailAsync( + "Server Unreachable", + item.DisplayName, + errorDetail, + "Online", + item.Id); } else if (!wasOnline && isOnline && prefs.NotifyOnConnectionRestored) { _notificationService?.ShowConnectionRestoredNotification(item.DisplayName); + + _emailAlertService.RecordAlert(item.Id, item.DisplayName, "Server Restored", + "Online", "Online", true, "email"); + _ = _emailAlertService.TrySendAlertEmailAsync( + "Server Restored", + item.DisplayName, + "Connection restored", + "Online", + item.Id); } } diff --git a/Dashboard/Services/EmailTemplateBuilder.cs b/Dashboard/Services/EmailTemplateBuilder.cs index 87387439..c2b9efbb 100644 --- a/Dashboard/Services/EmailTemplateBuilder.cs +++ b/Dashboard/Services/EmailTemplateBuilder.cs @@ -74,6 +74,8 @@ private static (string AccentColor, string BadgeText) GetSeverity(string metricN "Long-Running Query" => ("#D97706", "WARNING"), "TempDB Space" => ("#D97706", "WARNING"), "Long-Running Job" => ("#D97706", "WARNING"), + "Server Unreachable" => ("#DC2626", "CRITICAL"), + "Server Restored" => ("#16A34A", "RESOLVED"), _ => ("#2eaef1", "INFO") }; }