From c7dccc69a8635586e69d826f5d0b119b2b459371 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Wed, 7 Mar 2018 23:47:58 +0100 Subject: [PATCH] Fix space comparison expression and use gigabytes for threshold. Megabytes have shown to be a bit clumsy in the configuration files, so simply switch to the more useful Gigabytes unit. Fixes #39 --- ATxCommon/Serializables/DriveToCheck.cs | 2 +- ATxCommon/Serializables/ServiceConfig.cs | 2 +- ATxCommon/SystemChecks.cs | 12 ++++++++---- ATxService/Email.cs | 6 ++++-- Resources/conf/host-specific.template.xml | 6 +++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ATxCommon/Serializables/DriveToCheck.cs b/ATxCommon/Serializables/DriveToCheck.cs index 279dcb8..6411bdb 100644 --- a/ATxCommon/Serializables/DriveToCheck.cs +++ b/ATxCommon/Serializables/DriveToCheck.cs @@ -11,7 +11,7 @@ public string DriveName { get; set; } /// <summary> - /// Limit (in MB) of free space, lower values will trigger a notification. + /// Limit (in GB) of free space, lower values will trigger a notification. /// </summary> public long SpaceThreshold { get; set; } } diff --git a/ATxCommon/Serializables/ServiceConfig.cs b/ATxCommon/Serializables/ServiceConfig.cs index 378bf1a..bf65c98 100644 --- a/ATxCommon/Serializables/ServiceConfig.cs +++ b/ATxCommon/Serializables/ServiceConfig.cs @@ -489,7 +489,7 @@ namespace ATxCommon.Serializables var space = ""; foreach (var drive in SpaceMonitoring) { space += $" DriveName: {drive.DriveName} " + - $"(threshold: {Conv.MegabytesToString(drive.SpaceThreshold)})\n"; + $"(threshold: {Conv.GigabytesToString(drive.SpaceThreshold)})\n"; } if (!string.IsNullOrWhiteSpace(space)) msg += $"SpaceMonitoring:\n{space}"; diff --git a/ATxCommon/SystemChecks.cs b/ATxCommon/SystemChecks.cs index 61ba1f0..1fa1c74 100644 --- a/ATxCommon/SystemChecks.cs +++ b/ATxCommon/SystemChecks.cs @@ -80,12 +80,16 @@ namespace ATxCommon var msg = ""; foreach (var driveToCheck in drives) { var freeSpace = GetFreeDriveSpace(driveToCheck.DriveName); - if (freeSpace >= driveToCheck.SpaceThreshold) + if (freeSpace >= driveToCheck.SpaceThreshold * Conv.GigaBytes) { + Log.Trace("Drive [{0}] free space: {1}, above threshold ({2})", + driveToCheck.DriveName, Conv.BytesToString(freeSpace), + Conv.GigabytesToString(driveToCheck.SpaceThreshold)); continue; + } - msg += "Drive '" + driveToCheck.DriveName + - "' - free space: " + Conv.BytesToString(freeSpace) + - " (threshold: " + Conv.BytesToString(driveToCheck.SpaceThreshold) + ")\n"; + msg += $"Drive [{driveToCheck.DriveName}] " + + $"free space: {Conv.BytesToString(freeSpace)} " + + $"(threshold: {Conv.GigabytesToString(driveToCheck.SpaceThreshold)})\n"; } return msg; diff --git a/ATxService/Email.cs b/ATxService/Email.cs index c4dfbf4..9bfcf63 100644 --- a/ATxService/Email.cs +++ b/ATxService/Email.cs @@ -104,12 +104,14 @@ namespace ATxService /// </summary> /// <param name="spaceDetails">String describing the drives being low on space.</param> private void SendLowSpaceMail(string spaceDetails) { - if (string.IsNullOrWhiteSpace(spaceDetails)) + if (string.IsNullOrWhiteSpace(spaceDetails)) { + Log.Trace("SendLowSpaceMail(): spaceDetails emtpy!"); return; + } var delta = TimeUtils.MinutesSince(_status.LastStorageNotification); if (delta < _config.StorageNotificationDelta) { - Log.Trace("Only {0} since last low-space-notification, skipping.", + Log.Trace("Last low-space-notification was {0}, skipping.", TimeUtils.MinutesToHuman(delta)); return; } diff --git a/Resources/conf/host-specific.template.xml b/Resources/conf/host-specific.template.xml index 0feb144..70161d2 100644 --- a/Resources/conf/host-specific.template.xml +++ b/Resources/conf/host-specific.template.xml @@ -20,12 +20,12 @@ <DriveToCheck> <!-- DriveName: the drive letter followed by a colon --> <DriveName>C:</DriveName> - <!-- SpaceThreshold: minimum amount of free megabytes --> - <SpaceThreshold>14000</SpaceThreshold> + <!-- SpaceThreshold: minimum amount of free gigabytes --> + <SpaceThreshold>14</SpaceThreshold> </DriveToCheck> <!--><DriveToCheck> <DriveName>D:</DriveName> - <SpaceThreshold>120000</SpaceThreshold> + <SpaceThreshold>120</SpaceThreshold> </DriveToCheck><--> </SpaceMonitoring> -- GitLab