comparison ServerMonitor/Objects/Checks/SshCheck.cs @ 5:b6fe203af9d5

Private key passwords and validation
author Brad Greco <brad@bgreco.net>
date Thu, 28 Feb 2019 21:19:32 -0500
parents 3142e52cbe69
children 052aa62cb42a
comparison
equal deleted inserted replaced
4:3142e52cbe69 5:b6fe203af9d5
27 27
28 public bool CommandOutputUseRegex { get; set; } 28 public bool CommandOutputUseRegex { get; set; }
29 29
30 protected override Task<CheckResult> ExecuteCheckAsync(CancellationToken token) 30 protected override Task<CheckResult> ExecuteCheckAsync(CancellationToken token)
31 { 31 {
32 try
33 {
34 if (!Server.SshClient.IsConnected)
35 Server.SshClient.Connect();
36 }
37 catch (Exception e)
38 {
39 return Task.FromResult(Fail(e));
40 }
32 return Task.Run(() => 41 return Task.Run(() =>
33 { 42 {
34 try 43 try
35 { 44 {
36 if (!Server.SshClient.IsConnected)
37 Server.SshClient.Connect();
38 token.ThrowIfCancellationRequested(); 45 token.ThrowIfCancellationRequested();
39 using (SshCommand command = Server.SshClient.CreateCommand(Command)) 46 using (SshCommand command = Server.SshClient.CreateCommand(Command))
40 { 47 {
41 token.Register(command.CancelAsync); 48 token.Register(command.CancelAsync);
42 IAsyncResult ar = command.BeginExecute(); 49 IAsyncResult ar = command.BeginExecute();