From 69e4e43c8b3833d6b55075c78ef3893274738728 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Mon, 29 Apr 2019 16:59:26 +0200 Subject: [PATCH] Send a system health report on service startup Refers to #20 --- ATxService/AutoTx.cs | 3 +-- ATxService/Email.cs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ATxService/AutoTx.cs b/ATxService/AutoTx.cs index e7a65ee..197af95 100644 --- a/ATxService/AutoTx.cs +++ b/ATxService/AutoTx.cs @@ -396,10 +396,9 @@ namespace ATxService var health = SystemChecks.HealthReport(_storage); + SendHealthReport(health); msg += "\n" + health; - // TODO: send health report! - Log.Debug(msg); // finally check if the validation gave warnings and send them to the admin: diff --git a/ATxService/Email.cs b/ATxService/Email.cs index ac439b9..df59f29 100644 --- a/ATxService/Email.cs +++ b/ATxService/Email.cs @@ -233,5 +233,24 @@ namespace ATxService _status.LastGraceNotification = DateTime.Now; return SendAdminEmail(report, "grace location summary"); } + + /// <summary> + /// Send a system health report if enough time has elapsed since the previous one. + /// </summary> + /// <param name="report">The health report.</param> + /// <returns>True in case the report was sent, false otherwise.</returns> + private bool SendHealthReport(string report) { + var elapsedHuman = TimeUtils.HumanSince(_status.LastStartupNotification); + + if (TimeUtils.MinutesSince(_status.LastStartupNotification) < _config.StartupNotificationDelta) { + Log.Trace("Not sending system health report now, last one has been sent {0}", + elapsedHuman); + return false; + } + + report += $"\nPrevious system health report notification was sent {elapsedHuman}.\n"; + _status.LastStartupNotification = DateTime.Now; + return SendAdminEmail(report, "system health report"); + } } } \ No newline at end of file -- GitLab