diff ServerMonitor/Objects/Checks/SshCheck.cs @ 3:96f0b028176d

File check
author Brad Greco <brad@bgreco.net>
date Fri, 11 Jan 2019 22:34:18 -0500
parents 453ecc1ed9ea
children 3142e52cbe69
line wrap: on
line diff
--- a/ServerMonitor/Objects/Checks/SshCheck.cs	Sun Jan 06 20:49:08 2019 -0500
+++ b/ServerMonitor/Objects/Checks/SshCheck.cs	Fri Jan 11 22:34:18 2019 -0500
@@ -13,7 +13,7 @@
     [DisplayName("SSH check"), Description("Check the result of a command run over SSH"), DisplayWeight(10)]
     public class SshCheck : Check
     {
-        public string Command { get; set; }
+        public virtual string Command { get; set; }
 
         public bool CheckExitCode { get; set; }
 
@@ -36,7 +36,7 @@
                     if (!Server.SshClient.IsConnected)
                         Server.SshClient.Connect();
                     token.ThrowIfCancellationRequested();
-                    using (SshCommand command = Server.SshClient.CreateCommand(GetCommand()))
+                    using (SshCommand command = Server.SshClient.CreateCommand(Command))
                     {
                         token.Register(command.CancelAsync);
                         IAsyncResult ar = command.BeginExecute();
@@ -68,16 +68,16 @@
             //return tcs.Task;
         }
 
-        protected virtual string GetCommand()
-        {
-            return Command;
-        }
-
         protected virtual List<CheckResult> ProcessCommandResult(string output, int exitCode)
         {
             List<CheckResult> results = new List<CheckResult>();
             if (CheckExitCode)
-                results.Add(GetIntResult(ExitCode, exitCode, "Exit code"));
+            {
+                CheckResult result = GetIntResult(ExitCode, exitCode, "Exit code");
+                if (result.CheckStatus != CheckStatus.Success)
+                    result.Message += ". Command output: " + output;
+                results.Add(result);
+            }
             if (CheckCommandOutput)
                 results.Add(GetStringResult(CommandOutputMatchType, CommandOutputPattern, CommandOutputUseRegex, output, "Command output"));
             return results;