# HG changeset patch # User Brad Greco # Date 1555370727 14400 # Node ID a36cc5c123f45d5f8ce8a12cd1120626e4cc8e90 # Parent d92176c5398a40967b4c530abedadfa5092c267c Fix SSH command sublclasses holding on to old command strings after a program update. diff -r d92176c5398a -r a36cc5c123f4 ServerMonitor/Objects/Checks/DiskSpaceCheck.cs --- a/ServerMonitor/Objects/Checks/DiskSpaceCheck.cs Mon Apr 15 19:24:55 2019 -0400 +++ b/ServerMonitor/Objects/Checks/DiskSpaceCheck.cs Mon Apr 15 19:25:27 2019 -0400 @@ -10,7 +10,9 @@ [DisplayName("Disk space check"), Description("Check the remaining free disk space"), DisplayWeight(11)] public class DiskSpaceCheck : SshCheck { - public override string Command => string.Format(base.Command, Device); + public override string Command => string.Format(DiskSpaceCommand, Device); + + protected string DiskSpaceCommand => "df -P -k {0}"; public string Device { get; set; } @@ -20,8 +22,6 @@ public DiskSpaceCheck() { - //Command = "df -P -k {0} | awk 'NR>1' | tr -s ' ' | cut -d ' ' -f 4,5"; - Command = "df -P -k {0}"; CheckExitCode = true; ExitCode = 0; } diff -r d92176c5398a -r a36cc5c123f4 ServerMonitor/Objects/Checks/FileCheck.cs --- 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)) { diff -r d92176c5398a -r a36cc5c123f4 ServerMonitor/Objects/Checks/SshCheck.cs --- a/ServerMonitor/Objects/Checks/SshCheck.cs Mon Apr 15 19:24:55 2019 -0400 +++ b/ServerMonitor/Objects/Checks/SshCheck.cs Mon Apr 15 19:25:27 2019 -0400 @@ -66,6 +66,8 @@ protected virtual List ProcessCommandResult(string output, int exitCode) { List results = new List(); + if (CheckCommandOutput) + results.Add(GetStringResult(CommandOutputMatchType, CommandOutputPattern, CommandOutputUseRegex, output, "Command output")); if (CheckExitCode) { CheckResult result = GetIntResult(ExitCode, exitCode, "Exit code"); @@ -73,8 +75,6 @@ result.Message += ". Command output: " + output; results.Add(result); } - if (CheckCommandOutput) - results.Add(GetStringResult(CommandOutputMatchType, CommandOutputPattern, CommandOutputUseRegex, output, "Command output")); return results; }