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

Send an email on expired folders in the grace location.

An email will be sent only if the time since the last one exceeds the
new configuration option "GraceNotificationDelta", defaulting to 12
hours.

Fixes #1
parent 9497b5fa
No related branches found
No related tags found
No related merge requests found
......@@ -931,9 +931,10 @@ namespace AutoTx
/// <summary>
/// Generate a report on expired folders in the grace location.
///
/// Check all user-directories in the grace location for subdirectories whose
/// name-timestamp exceeds the configured grace period and generate a summary
/// containing the age and size of those directories.
/// Check all user-directories in the grace location for subdirectories whose timestamp
/// (the directory name) exceeds the configured grace period and generate a summary
/// containing the age and size of those directories. The summary will be sent to the admin
/// if the configured GraceNotificationDelta has passed since the last email.
/// </summary>
/// <param name="threshold">The number of days used as expiration threshold.</param>
public string GraceLocationSummary(int threshold) {
......@@ -949,6 +950,13 @@ namespace AutoTx
if (string.IsNullOrEmpty(report))
return "";
report = "Expired folders in grace location:\n" + report;
var delta = (int)(DateTime.Now - _status.LastGraceNotification).TotalMinutes;
report += "\nTime since last grace notification: " + delta + "\n";
if (delta >= _config.GraceNotificationDelta) {
SendAdminEmail(report, "Grace location cleanup required.");
_status.LastGraceNotification = DateTime.Now;
report += "\nNotification sent to AdminEmailAdress.\n";
}
return report;
}
......
......@@ -87,6 +87,10 @@
messages to, e.g. on completed transfers. Can be empty. -->
<AdminDebugEmailAdress>admin@mydomain.xy</AdminDebugEmailAdress>
<!-- GraceNotificationDelta: minimum time (in minutes) between two emails
about expired folders in the grace location (default: 720 (12h)) -->
<GraceNotificationDelta>720</GraceNotificationDelta>
<!-- InterPacketGap: RoboCopy parameter to limit the bandwidth -->
<InterPacketGap>0</InterPacketGap>
......
......@@ -24,6 +24,7 @@ namespace AutoTx.XmlWrapper
EmailPrefix = "";
AdminEmailAdress = "";
AdminDebugEmailAdress = "";
GraceNotificationDelta = 720;
InterPacketGap = 0;
......@@ -116,6 +117,8 @@ namespace AutoTx.XmlWrapper
public string AdminEmailAdress { get; set; }
public string AdminDebugEmailAdress { get; set; }
public int GraceNotificationDelta { get; set; }
public int InterPacketGap { get; set; }
/// <summary>
......@@ -212,8 +215,8 @@ namespace AutoTx.XmlWrapper
"AdminEmailAdress: " + AdminEmailAdress + "\n" +
"AdminDebugEmailAdress: " + AdminDebugEmailAdress + "\n" +
"StorageNotificationDelta: " + StorageNotificationDelta + "\n" +
"AdminNotificationDelta: " + AdminNotificationDelta + "\n";
"AdminNotificationDelta: " + AdminNotificationDelta + "\n" +
"GraceNotificationDelta: " + GraceNotificationDelta + "\n";
}
return msg;
}
......
......@@ -14,6 +14,7 @@ namespace AutoTx.XmlWrapper
private DateTime _lastStatusUpdate;
private DateTime _lastStorageNotification;
private DateTime _lastAdminNotification;
private DateTime _lastGraceNotification;
private string _limitReason;
string _currentTransferSrc;
......@@ -49,6 +50,15 @@ namespace AutoTx.XmlWrapper
}
}
[XmlElement("LastGraceNotification", DataType = "dateTime")]
public DateTime LastGraceNotification {
get { return _lastGraceNotification; }
set {
_lastGraceNotification = value;
Serialize();
}
}
public string LimitReason {
get { return _limitReason; }
set {
......@@ -209,7 +219,9 @@ namespace AutoTx.XmlWrapper
"LastStorageNotification: " +
LastStorageNotification.ToString("yyyy-MM-dd HH:mm:ss") + "\n" +
"LastAdminNotification: " +
LastAdminNotification.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
LastAdminNotification.ToString("yyyy-MM-dd HH:mm:ss") + "\n" +
"LastGraceNotification: " +
LastGraceNotification.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment