mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-25 19:10:10 +00:00
Log when a console connection is established and lost
This commit is contained in:
parent
db456dd9e5
commit
f3bd9569fd
@ -103,10 +103,16 @@ class _ConsoleHandler(object):
|
||||
|
||||
def _got_connected(self):
|
||||
self.connectstate = 'connected'
|
||||
self.logger.log(
|
||||
logdata='console connected', ltype=log.DataTypes.event,
|
||||
event=log.Events.consoleconnect)
|
||||
self._send_rcpts({'connectstate': self.connectstate})
|
||||
|
||||
def _got_disconnected(self):
|
||||
self.connecstate = 'unconnected'
|
||||
self.logger.log(
|
||||
logdata='console disconnected', ltype=log.DataTypes.event,
|
||||
event=log.Events.consoledisconnect)
|
||||
self._send_rcpts({'connectstate': self.connectstate})
|
||||
self._connect()
|
||||
|
||||
@ -216,7 +222,7 @@ class _ConsoleHandler(object):
|
||||
'clientcount': self.clientcount,
|
||||
}
|
||||
retdata = ''
|
||||
if self.shiftin is not None: #detected that terminal requested a
|
||||
if self.shiftin is not None: # detected that terminal requested a
|
||||
#shiftin character set, relay that to the terminal that cannected
|
||||
retdata += '\x1b)' + self.shiftin
|
||||
if self.appmodedetected:
|
||||
@ -254,6 +260,8 @@ def connect_node(node, configmanager):
|
||||
#holding the caller specific queue data, for example, when http api should be
|
||||
#sending data, but there is no outstanding POST request to hold it,
|
||||
# this object has the job of holding the data
|
||||
|
||||
|
||||
class ConsoleSession(object):
|
||||
"""Create a new socket to converse with node console
|
||||
|
||||
@ -282,7 +290,7 @@ class ConsoleSession(object):
|
||||
self.databuffer.extend(_handled_consoles[consk].get_recent())
|
||||
else:
|
||||
self.reghdl = _handled_consoles[consk].register_rcpt(datacallback)
|
||||
for recdata in _handled_consoles[consk].get_recent():
|
||||
for recdata in _handled_consoles[consk].get_recent():
|
||||
if recdata:
|
||||
datacallback(recdata)
|
||||
|
||||
@ -330,46 +338,3 @@ class ConsoleSession(object):
|
||||
# they are given up on
|
||||
self.reaper = eventlet.spawn_after(15, self.destroy)
|
||||
return retval
|
||||
|
||||
|
||||
def handle_request(request=None, connection=None, releaseconnection=False):
|
||||
"""
|
||||
Process a request from confluent.
|
||||
|
||||
:param request: For 'datagram' style console, this represents a wait for
|
||||
data or input.
|
||||
:param connection: For socket style console, this is a read/write socket
|
||||
that the caller has released from it's control and
|
||||
console plugin will do all IO
|
||||
:param releaseconnection: A function for console to call to indicate
|
||||
confluent should resume control over the connection
|
||||
|
||||
"""
|
||||
if request is not None: # This is indicative of http style
|
||||
pass # TODO(jbjohnso): support AJAX style interaction.
|
||||
# a web ui looking to actually take advantage will
|
||||
# probably have to pull in the GPL javascript
|
||||
# from shellinabox or something similar
|
||||
# the way that works is URI encoded input with width, heiht,
|
||||
# session or rooturl:opening
|
||||
# opening session
|
||||
# width=120&height=24&rooturl=/nodes/n1/console/session
|
||||
# making a request to wait for data:
|
||||
# width=120&height=24&session=blahblahblah
|
||||
# <hitting enter>:
|
||||
# width=120&height=24&session=blahblahblah&keys=0D
|
||||
# pasting 'rabbit'
|
||||
# width=120&height=24&session=blahblah&keys=726162626974
|
||||
# if no client session indicated, it expects some session number
|
||||
# in return.
|
||||
# the responses:
|
||||
# <responding to session open>: (the session seems to be opaque
|
||||
# {"session":"h5lrOKViIeQGp1nXjKWpAQ","data":""}
|
||||
# <responding to wait for data with data, specically a prompt
|
||||
# that sets title>
|
||||
# {"session":"blah","data":"\r\n\u001B]0;bob@thor:~\u0007$ "}
|
||||
# <responding to wait with no data (seems to wait 46 seconds)
|
||||
# {"session":"jSGBPmAxavsD/1acSl/uog","data":""}
|
||||
# closed session returns HTTP 400 to a console answer
|
||||
elif connection is not None: # This is a TLS or unix socket
|
||||
ConsoleSession(connection, releaseconnection)
|
||||
|
@ -62,7 +62,6 @@ import collections
|
||||
import confluent.config.configmanager as configuration
|
||||
import eventlet
|
||||
import fcntl
|
||||
import os
|
||||
import struct
|
||||
import time
|
||||
|
||||
@ -79,7 +78,10 @@ import time
|
||||
|
||||
|
||||
class Events(object):
|
||||
undefined, clearscreen, clientconnect, clientdisconnect = range(4)
|
||||
(
|
||||
undefined, clearscreen, clientconnect, clientdisconnect,
|
||||
consoledisconnect, consoleconnect,
|
||||
) = range(6)
|
||||
logstr = {
|
||||
2: 'connection by ',
|
||||
3: 'disconnection by ',
|
||||
@ -89,6 +91,7 @@ class Events(object):
|
||||
class DataTypes(object):
|
||||
text, dictionary, console, event = range(4)
|
||||
|
||||
|
||||
class Logger(object):
|
||||
"""
|
||||
:param console: If true, [] will be used to denote non-text events. If
|
||||
@ -137,8 +140,9 @@ class Logger(object):
|
||||
if eventaux is None:
|
||||
eventaux = 0
|
||||
# metadata length is always 16 for this code at the moment
|
||||
binrecord = struct.pack(">BBIHIBBH",
|
||||
16, ltype, offset, datalen, tstamp, evtdata, eventaux, 0)
|
||||
binrecord = struct.pack(
|
||||
">BBIHIBBH", 16, ltype, offset, datalen, tstamp, evtdata,
|
||||
eventaux, 0)
|
||||
if self.isconsole:
|
||||
if ltype == 2:
|
||||
textrecord = data
|
||||
@ -175,8 +179,6 @@ class Logger(object):
|
||||
recbytes = binfile.read(16)
|
||||
(_, ltype, offset, datalen, tstamp, evtdata, eventaux, _) = \
|
||||
struct.unpack(">BBIHIBBH", recbytes)
|
||||
binrecord = struct.pack(">BBIHIBBH",
|
||||
16, ltype, offset, datalen, tstamp, evtdata, eventaux, 0)
|
||||
if ltype != 2:
|
||||
continue
|
||||
currsize += datalen
|
||||
@ -218,7 +220,8 @@ class Logger(object):
|
||||
if eventdata is not None:
|
||||
self.logentries[-1][4] = eventdata
|
||||
else:
|
||||
self.logentries.append([ltype, timestamp, logdata, event, eventdata])
|
||||
self.logentries.append(
|
||||
[ltype, timestamp, logdata, event, eventdata])
|
||||
if self.writer is None:
|
||||
self.writer = eventlet.spawn_after(2, self.writedata)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user