Skip to content

Commit

Permalink
Merge pull request #263 from glennmatthews/log_send_receive_content
Browse files Browse the repository at this point in the history
Log sent and received messages at level INFO
  • Loading branch information
einarnn committed Aug 17, 2018
2 parents 49952de + 57e6002 commit d8126f8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ncclient/transport/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class SSHSession(Session):
def __init__(self, device_handler):
capabilities = Capabilities(device_handler.get_capabilities())
Session.__init__(self, capabilities)
self._host = None
self._host_keys = paramiko.HostKeys()
self._transport = None
self._connected = False
Expand All @@ -102,6 +103,10 @@ def __init__(self, device_handler):
self._size_num_list = []
self._message_list = []

def _dispatch_message(self, raw):
logger.info("Received from %s session %s:\n%s", self.host, self.id, raw)
return super(SSHSession, self)._dispatch_message(raw)

def _parse(self):
"Messages ae delimited by MSG_DELIM. The buffer could have grown by a maximum of BUF_SIZE bytes everytime this method is called. Retains state across method calls and if a byte has been read it will not be considered again."
return self._parse10()
Expand Down Expand Up @@ -356,6 +361,8 @@ def connect(self, host, port=830, timeout=None, unknown_host_cb=default_unknown_
if not (host or sock_fd):
raise SSHError("Missing host or socket fd")

self._host = host

# Optionally, parse .ssh/config
config = {}
if ssh_config is True:
Expand Down Expand Up @@ -585,7 +592,8 @@ def start_delim(data_len): return '\n#%s\n'%(data_len)
# send using v1.0 EOM markers
data = "%s%s"%(data, MSG_DELIM)
finally:
logger.debug("Sending: %s", data)
logger.info("Sending to %s session %s:\n%s",
self.host, self.id, data)
while data:
n = chan.send(data)
if n <= 0:
Expand All @@ -596,6 +604,11 @@ def start_delim(data_len): return '\n#%s\n'%(data_len)
self._dispatch_error(e)
self.close()

@property
def host(self):
"""Host this session is connected to, or None if not connected."""
return self._host

@property
def transport(self):
"Underlying `paramiko.Transport <http://www.lag.net/paramiko/docs/paramiko.Transport-class.html>`_ object. This makes it possible to call methods like :meth:`~paramiko.Transport.set_keepalive` on it."
Expand Down

0 comments on commit d8126f8

Please sign in to comment.