SFTPPlus Documentation

Start Page 7. Developer Documentation 7.1.4. Python API Event Handler

7.1.4. Python API Event Handler

7.1.4.1. Introduction

SFTPPlus allows developers to write custom event handlers using the Python programming language.

The code for the event handler needs to be placed in a Python file (module) inside the extension/ folder from the SFTPPlus installation folder.

Below is a brief example. You can find an extensive example inside the extension/ folder of the default SFTPPlus installation:

class DemoEventHandler(object):
    """
    An event handler which just prints to standard output the ID of the
    received events.
    """

    def __init__(self, parent):
        """
        Called when the event handler is started.
        """
        self._parent = parent

    def handle(self, event):
        """
        Called when we should handle the event.
        """
        print(b'Received %s' % (event.id,))

7.1.4.2. Event data members

The event object received in the handler has the following structure.

The overall structure of the event object is:

id
message
timestamp:
    cwa_14051
    timestamp
account:
    name
    uuid
    peer:
        address
        port
        protocol
component:
    name
    uuid
    type
    family
    restart_required
    start_time
    stop_time
    startup_configuration
data

The members of data are specific to each event. See Events page for more details regarding the data available for each event.

Below is the description for the main members of the event object.


name:id
type:string
optional:No
description:ID of this event. See Events page for the list of all available events.

name:message
type:string
optional:No
description:A human readable description of this event.

The timestmap contains the following attributes:


name:timestamp
type:string
optional:No
description:Date and time at which this event was created, as Unix timestamp with milliseconds.

name:cwa_14051
type:string
optional:No
description:Date and time in CWA 14051 at which this event was emitted.

The account contains the following attributes:


name:uuid
type:string
optional:No
description:UUID of the account emitting this event. In case no account is associated with the event, this will be the special process account. In case the associated account is not yet authenticated this will be the special peer account.

name:name
type:string
optional:No
description:Name of the account emitting this event.

name:peer
type:JSON Object
optional:No
description:Address of the peer attached to this account. This might be a local or remote address, depending on whether the account is used for client side or server side interaction.

The peer contains the following attributes:


name:address
type:string
optional:No
description:IP address of this connection.

name:port
type:integer
optional:No
description:Port number of this connection.

name:protocol
type:string
optional:No
description:OSI Layer 4 transport layer protocol used for this connection in the form of either TCP or UDP.

The component contains the following attributes:


name:uuid
type:string
optional:No
description:UUID of the server part emitting this event.

name:type
type:string
optional:No
description:Type of the server part emitting this event.