mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-01-11 19:44:44 +00:00
Merge pull request #127 from PepperDash/hotfix/ssh-logging
Log SSH messages to Error Log
This commit is contained in:
@@ -193,7 +193,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (IsConnecting)
|
if (IsConnecting)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Connection attempt in progress. Exiting Connect()");
|
Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "Connection attempt in progress. Exiting Connect()");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ namespace PepperDash.Core
|
|||||||
if (string.IsNullOrEmpty(Hostname) || Port < 1 || Port > 65535
|
if (string.IsNullOrEmpty(Hostname) || Port < 1 || Port > 65535
|
||||||
|| Username == null || Password == null)
|
|| Username == null || Password == null)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Connect failed. Check hostname, port, username and password are set or not null");
|
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Connect failed. Check hostname, port, username and password are set or not null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ namespace PepperDash.Core
|
|||||||
TheStream = Client.CreateShellStream("PDTShell", 100, 80, 100, 200, 65534);
|
TheStream = Client.CreateShellStream("PDTShell", 100, 80, 100, 200, 65534);
|
||||||
TheStream.DataReceived += Stream_DataReceived;
|
TheStream.DataReceived += Stream_DataReceived;
|
||||||
//TheStream.ErrorOccurred += TheStream_ErrorOccurred;
|
//TheStream.ErrorOccurred += TheStream_ErrorOccurred;
|
||||||
Debug.Console(1, this, "Connected");
|
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Connected");
|
||||||
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;
|
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;
|
||||||
IsConnecting = false;
|
IsConnecting = false;
|
||||||
return; // Success will not pass here
|
return; // Success will not pass here
|
||||||
@@ -257,24 +257,28 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
var ie = e.InnerException; // The details are inside!!
|
var ie = e.InnerException; // The details are inside!!
|
||||||
if (ie is SocketException)
|
if (ie is SocketException)
|
||||||
Debug.Console(1, this, "'{0}' CONNECTION failure: Cannot reach host, ({1})", Key, ie.GetType());
|
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "'{0}' CONNECTION failure: Cannot reach host, ({1})", Key, ie.Message);
|
||||||
else if (ie is System.Net.Sockets.SocketException)
|
else if (ie is System.Net.Sockets.SocketException)
|
||||||
Debug.Console(1, this, "'{0}' Connection failure: Cannot reach host '{1}' on port {2}, ({3})",
|
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "'{0}' Connection failure: Cannot reach host '{1}' on port {2}, ({3})",
|
||||||
Key, Hostname, Port, ie.GetType());
|
Key, Hostname, Port, ie.GetType());
|
||||||
else if (ie is SshAuthenticationException)
|
else if (ie is SshAuthenticationException)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Authentication failure for username '{0}', ({1})",
|
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Authentication failure for username '{0}', ({1})",
|
||||||
Username, ie.GetType());
|
Username, ie.Message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Debug.Console(1, this, "Error on connect:\r({0})", e);
|
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Error on connect:\r({0})", e);
|
||||||
|
|
||||||
|
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECT_FAILED;
|
||||||
|
HandleConnectionFailure();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Unhandled exception on connect:\r({0})", e);
|
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Unhandled exception on connect:\r({0})", e);
|
||||||
|
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECT_FAILED;
|
||||||
|
HandleConnectionFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sucess will not make it this far
|
|
||||||
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECT_FAILED;
|
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECT_FAILED;
|
||||||
HandleConnectionFailure();
|
HandleConnectionFailure();
|
||||||
}
|
}
|
||||||
@@ -320,25 +324,26 @@ namespace PepperDash.Core
|
|||||||
void HandleConnectionFailure()
|
void HandleConnectionFailure()
|
||||||
{
|
{
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||||
|
|
||||||
Debug.Console(1, this, "Client nulled due to connection failure. AutoReconnect: {0}, ConnectEnabled: {1}", AutoReconnect, ConnectEnabled);
|
Debug.Console(1, this, "Client nulled due to connection failure. AutoReconnect: {0}, ConnectEnabled: {1}", AutoReconnect, ConnectEnabled);
|
||||||
if (AutoReconnect && ConnectEnabled)
|
if (AutoReconnect && ConnectEnabled)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
Debug.Console(1, this, "Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||||
if (ReconnectTimer == null)
|
if (ReconnectTimer == null)
|
||||||
{
|
{
|
||||||
ReconnectTimer = new CTimer(o =>
|
ReconnectTimer = new CTimer(o =>
|
||||||
{
|
{
|
||||||
Connect();
|
Connect();
|
||||||
}, AutoReconnectIntervalMs);
|
}, AutoReconnectIntervalMs);
|
||||||
Debug.Console(1, this, "Attempting connection in {0} seconds",
|
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Attempting connection in {0} seconds",
|
||||||
(float)(AutoReconnectIntervalMs / 1000));
|
(float) (AutoReconnectIntervalMs/1000));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "{0} second reconnect cycle running",
|
Debug.Console(1, this, "{0} second reconnect cycle running",
|
||||||
(float)(AutoReconnectIntervalMs / 1000));
|
(float) (AutoReconnectIntervalMs/1000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -403,9 +408,9 @@ namespace PepperDash.Core
|
|||||||
void Client_ErrorOccurred(object sender, Crestron.SimplSharp.Ssh.Common.ExceptionEventArgs e)
|
void Client_ErrorOccurred(object sender, Crestron.SimplSharp.Ssh.Common.ExceptionEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Exception is SshConnectionException || e.Exception is System.Net.Sockets.SocketException)
|
if (e.Exception is SshConnectionException || e.Exception is System.Net.Sockets.SocketException)
|
||||||
Debug.Console(1, this, "Disconnected by remote");
|
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Disconnected by remote");
|
||||||
else
|
else
|
||||||
Debug.Console(1, this, "Unhandled SSH client error: {0}", e.Exception);
|
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Unhandled SSH client error: {0}", e.Exception);
|
||||||
|
|
||||||
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY;
|
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY;
|
||||||
HandleConnectionFailure();
|
HandleConnectionFailure();
|
||||||
@@ -449,7 +454,7 @@ namespace PepperDash.Core
|
|||||||
Debug.Console(0, "Exception: {0}", ex.Message);
|
Debug.Console(0, "Exception: {0}", ex.Message);
|
||||||
Debug.Console(0, "Stack Trace: {0}", ex.StackTrace);
|
Debug.Console(0, "Stack Trace: {0}", ex.StackTrace);
|
||||||
|
|
||||||
Debug.Console(1, this, "Stream write failed. Disconnected, closing");
|
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Stream write failed. Disconnected, closing");
|
||||||
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY;
|
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY;
|
||||||
HandleConnectionFailure();
|
HandleConnectionFailure();
|
||||||
}
|
}
|
||||||
@@ -478,7 +483,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Stream write failed. Disconnected, closing");
|
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Stream write failed. Disconnected, closing");
|
||||||
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY;
|
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY;
|
||||||
HandleConnectionFailure();
|
HandleConnectionFailure();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user