diff --git a/ATxService/AutoTx.cs b/ATxService/AutoTx.cs index e7a65ee8c14676d9147d63f7cc105aff7164cca2..197af95d1620a7b6f142438a85ab35b3eee6d55a 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 ac439b9ac81048ec73bb15a34c3e6703699a3367..df59f298ecce6c1b020d5a27c7fc2fe49cf5f22d 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