1
# Copyright 2010-2015 Canonical Ltd. This software is licensed under the
2
# GNU Lesser General Public License version 3 (see the file LICENSE).
4
"""Events generated by the SSH server."""
6
from __future__ import absolute_import, print_function
10
'AuthenticationFailed',
26
from zope.interface import (
33
class ILoggingEvent(Interface):
34
"""An event is a logging event if it has a message and a severity level.
36
Events that provide this interface will be logged in the SSH server access
40
level = Attribute("The level to log the event at.")
41
message = Attribute("The message to log.")
44
@implementer(ILoggingEvent)
46
"""An event that can be logged to a Python logger.
48
:ivar level: The level to log itself as. This should be defined as a
49
class variable in subclasses.
50
:ivar template: The format string of the message to log. This should be
51
defined as a class variable in subclasses.
54
def __init__(self, level=None, template=None, **data):
55
"""Construct a logging event.
57
:param level: The level to log the event as. If specified, overrides
58
the 'level' class variable.
59
:param template: The format string of the message to log. If
60
specified, overrides the 'template' class variable.
61
:param **data: Information to be logged. Entries will be substituted
62
into the template and stored as attributes.
66
if template is not None:
67
self.template = template
72
"""See `ILoggingEvent`."""
77
"""See `ILoggingEvent`."""
78
return self.template % self._data
81
class ServerStarting(LoggingEvent):
84
template = '---- Server started ----'
87
class ServerStopped(LoggingEvent):
90
template = '---- Server stopped ----'
93
class UserConnected(LoggingEvent):
96
template = '[%(session_id)s] %(address)s connected.'
98
def __init__(self, transport, address):
99
LoggingEvent.__init__(
100
self, session_id=id(transport), address=address)
103
class AuthenticationFailed(LoggingEvent):
106
template = '[%(session_id)s] failed to authenticate.'
108
def __init__(self, transport):
109
LoggingEvent.__init__(self, session_id=id(transport))
112
class UserDisconnected(LoggingEvent):
115
template = '[%(session_id)s] disconnected.'
117
def __init__(self, transport):
118
LoggingEvent.__init__(self, session_id=id(transport))
121
class AvatarEvent(LoggingEvent):
122
"""Base avatar event."""
126
def __init__(self, avatar):
128
LoggingEvent.__init__(
129
self, session_id=id(avatar.transport), username=avatar.username)
132
class UserLoggedIn(AvatarEvent):
134
template = '[%(session_id)s] %(username)s logged in.'
137
class UserLoggedOut(AvatarEvent):
139
template = '[%(session_id)s] %(username)s disconnected.'
142
class SFTPStarted(AvatarEvent):
144
template = '[%(session_id)s] %(username)s started SFTP session.'
147
class SFTPClosed(AvatarEvent):
149
template = '[%(session_id)s] %(username)s closed SFTP session.'