Skip to content
Snippets Groups Projects
Commit bc3ea120 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Have SendLowSpaceMail retrieve the storage report itself

Relates to #20
parent 9fec2e55
No related branches found
No related tags found
No related merge requests found
...@@ -615,7 +615,7 @@ namespace ATxService ...@@ -615,7 +615,7 @@ namespace ATxService
// throw new Exception("just a test exception from RunMainTasks"); // throw new Exception("just a test exception from RunMainTasks");
// mandatory tasks, run on every call: // mandatory tasks, run on every call:
SendLowSpaceMail(SystemChecks.CheckFreeDiskSpace(_config.SpaceMonitoring)); SendLowSpaceMail();
UpdateServiceState(); UpdateServiceState();
_status.SerializeHeartbeat(); _status.SerializeHeartbeat();
......
...@@ -102,12 +102,12 @@ namespace ATxService ...@@ -102,12 +102,12 @@ namespace ATxService
/// <summary> /// <summary>
/// Send a notification about low drive space to the admin if the time since the last /// Send a notification about low drive space to the admin if the time since the last
/// notification has elapsed the configured delta. The report will also contain a summary /// notification has elapsed the configured delta. The report will also contain a summary
/// of the grace location status. /// of the grace location status. If none of the drives are low on space nothing will be
/// done (i.e. only a generic trace-level message will be logged).
/// </summary> /// </summary>
/// <param name="spaceDetails">String describing the drives being low on space.</param> private void SendLowSpaceMail() {
private void SendLowSpaceMail(string spaceDetails) { if (_storage.AllDrivesAboveThreshold()) {
if (string.IsNullOrWhiteSpace(spaceDetails)) { Log.Trace("Free space on all drives above threshold.");
Log.Trace("SendLowSpaceMail(): spaceDetails emtpy!");
return; return;
} }
...@@ -118,25 +118,21 @@ namespace ATxService ...@@ -118,25 +118,21 @@ namespace ATxService
return; return;
} }
// reaching this point means a notification will be sent to the admin, and in that // reaching this point means a notification will be sent, so now we can ask for the
// case it makes sense to also include details about the grace location: // full storage status report:
var graceReport = FsUtils.GraceLocationSummary( var report = _storage.Summary();
new DirectoryInfo(_config.DonePath), _config.GracePeriod);
Log.Warn("WARNING: {0}", report);
Log.Warn("WARNING: {0}", spaceDetails);
_status.LastStorageNotification = DateTime.Now; _status.LastStorageNotification = DateTime.Now;
var substitutions = new List<Tuple<string, string>> { var substitutions = new List<Tuple<string, string>> {
Tuple.Create("SERVICE_NAME", ServiceName), Tuple.Create("SERVICE_NAME", ServiceName),
Tuple.Create("HOST_ALIAS", _config.HostAlias), Tuple.Create("HOST_ALIAS", _config.HostAlias),
Tuple.Create("HOST_NAME", Environment.MachineName), Tuple.Create("HOST_NAME", Environment.MachineName),
Tuple.Create("LOW_SPACE_DRIVES", spaceDetails) Tuple.Create("LOW_SPACE_DRIVES", report)
}; };
try { try {
var body = LoadMailTemplate("DiskSpace-Low.txt", substitutions); var body = LoadMailTemplate("DiskSpace-Low.txt", substitutions);
if (graceReport.Length > 0)
body += $"\n\n--\n{graceReport}";
SendEmail(_config.AdminEmailAdress, "low disk space", body); SendEmail(_config.AdminEmailAdress, "low disk space", body);
} }
catch (Exception ex) { catch (Exception ex) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment