Mercurial > servermonitor
comparison 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 |
comparison
equal
deleted
inserted
replaced
12:d92176c5398a | 13:a36cc5c123f4 |
---|---|
3 using System.ComponentModel; | 3 using System.ComponentModel; |
4 using System.Linq; | 4 using System.Linq; |
5 using System.Text; | 5 using System.Text; |
6 using System.Text.RegularExpressions; | 6 using System.Text.RegularExpressions; |
7 using System.Threading.Tasks; | 7 using System.Threading.Tasks; |
8 using System.Xml.Serialization; | |
8 | 9 |
9 namespace ServerMonitorApp | 10 namespace ServerMonitorApp |
10 { | 11 { |
11 [DisplayName("File check"), Description("Check file size or modified time"), DisplayWeight(12)] | 12 [DisplayName("File check"), Description("Check file size or modified time"), DisplayWeight(12)] |
12 public class FileCheck : SshCheck | 13 public class FileCheck : SshCheck |
13 { | 14 { |
14 public override string Command => string.Format(base.Command, Regex.Replace(File, "^~", "$HOME")); | 15 public override string Command => string.Format(FileCommand, Regex.Replace(File, "^~", "$HOME")); |
16 | |
17 protected string FileCommand | |
18 { | |
19 get | |
20 { | |
21 int timeZoneOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now).Hours * -1; // Invert because POSIX says so. | |
22 return "export TIME_STYLE=long-iso; export TZ=UTC" + timeZoneOffset + "; ls -l \"{0}\""; | |
23 } | |
24 } | |
15 | 25 |
16 public string File { get; set; } | 26 public string File { get; set; } |
17 | 27 |
18 public bool CheckFileSize { get; set; } | 28 public bool CheckFileSize { get; set; } |
19 | 29 |
37 | 47 |
38 public TimeUnits DateModifiedUnits { get; set; } | 48 public TimeUnits DateModifiedUnits { get; set; } |
39 | 49 |
40 public FileCheck() | 50 public FileCheck() |
41 { | 51 { |
42 Command = "export TIME_STYLE=long-iso; ls -l \"{0}\""; | |
43 //Command = "export TIME_STYLE=long-iso; ls -l \"{0}\" | tr -s ' ' | cut -d ' ' -f 5,6,7"; | |
44 CheckExitCode = true; | 52 CheckExitCode = true; |
45 ExitCode = 0; | 53 ExitCode = 0; |
46 } | 54 } |
47 | 55 |
48 protected override List<CheckResult> ProcessCommandResult(string output, int exitCode) | 56 protected override List<CheckResult> ProcessCommandResult(string output, int exitCode) |
73 results.Add(Fail("Unable to parse ls output as integer: " + tokens[4])); | 81 results.Add(Fail("Unable to parse ls output as integer: " + tokens[4])); |
74 } | 82 } |
75 } | 83 } |
76 if (CheckDateModified) | 84 if (CheckDateModified) |
77 { | 85 { |
78 // TODO use the server time instead | |
79 string dateString = tokens[5] + " " + tokens[6]; | 86 string dateString = tokens[5] + " " + tokens[6]; |
80 if (DateTime.TryParse(dateString, out DateTime modified)) | 87 if (DateTime.TryParse(dateString, out DateTime modified)) |
81 { | 88 { |
82 string message = string.Format("Last modified date is {0}", modified); | 89 string message = string.Format("Last modified date is {0}", modified); |
83 TimeSpan age = DateTime.Now.Subtract(modified); | 90 TimeSpan age = DateTime.Now.Subtract(modified); |