diff ServerMonitor/Objects/Checks/FileCheck.cs @ 13:a36cc5c123f4

Fix SSH command sublclasses holding on to old command strings after a program update.
author Brad Greco <brad@bgreco.net>
date Mon, 15 Apr 2019 19:25:27 -0400
parents 7127d5b5ac75
children 68d7834dc28e
line wrap: on
line diff
--- a/ServerMonitor/Objects/Checks/FileCheck.cs	Mon Apr 15 19:24:55 2019 -0400
+++ b/ServerMonitor/Objects/Checks/FileCheck.cs	Mon Apr 15 19:25:27 2019 -0400
@@ -5,13 +5,23 @@
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
+using System.Xml.Serialization;
 
 namespace ServerMonitorApp
 {
     [DisplayName("File check"), Description("Check file size or modified time"), DisplayWeight(12)]
     public class FileCheck : SshCheck
     {
-        public override string Command => string.Format(base.Command, Regex.Replace(File, "^~", "$HOME"));
+        public override string Command => string.Format(FileCommand, Regex.Replace(File, "^~", "$HOME"));
+
+        protected string FileCommand
+        {
+            get
+            {
+                int timeZoneOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now).Hours * -1; // Invert because POSIX says so.
+                return "export TIME_STYLE=long-iso; export TZ=UTC" + timeZoneOffset + "; ls -l \"{0}\"";
+            }
+        }
 
         public string File { get; set; }
 
@@ -39,8 +49,6 @@
 
         public FileCheck()
         {
-            Command = "export TIME_STYLE=long-iso; ls -l \"{0}\"";
-            //Command = "export TIME_STYLE=long-iso; ls -l \"{0}\" | tr -s ' ' | cut -d ' ' -f 5,6,7";
             CheckExitCode = true;
             ExitCode = 0;
         }
@@ -75,7 +83,6 @@
                 }
                 if (CheckDateModified)
                 {
-                    // TODO use the server time instead
                     string dateString = tokens[5] + " " + tokens[6];
                     if (DateTime.TryParse(dateString, out DateTime modified))
                     {