Adding Event Handlers (Linux Hosting)

Let's, for example, create an event handler for the 'client account creation' event. The handler will accept a client name and the client's login from environment variables. For simplicity we will use a shell-script called test-handler.sh that looks as follows:

#!/bin/bash

echo "--------------" >> /tmp/event_handler.log

/bin/date >> /tmp/event_handler.log # information on the event date and time

/usr/bin/id >> /tmp/event_handler.log # information on the user, on behalf of which the script was executed (to ensure control)

echo "client created" >> /tmp/event_handler.log # information on the created client account

echo "name: ${NEW_CONTACT_NAME}" >> /tmp/event_handler.log # client's name

echo "login: ${NEW_LOGIN_NAME}" >> /tmp/event_handler.log # client's login

echo "--------------" >> /tmp/event_handler.log


This script prints some information to a file so that we could control its execution (we cannot output information to stdout/stderr, as the script is executed in the background mode).

Suppose, that our script is located in the directory /parallels_plesk_panel_installation_directory/bin (for instance). Let's register it by creating an event handler via the control panel:

  1. Go to Home > Event Manager (in the Logs & Statistics group).
  2. Click Add New Event Handler. The event handler setup page appears.
  3. Select the event, you wish to assign a handler to in the Event menu.
  4. Select the priority for handler execution, or specify a custom value. To do this, select custom in the Priority menu and type in the value.

    When assigning several handlers to a single event you can specify the handler execution sequence, setting different priorities (higher value corresponds to a higher priority).

  5. Select the system user, on behalf of which the handler will be executed ("root" user, for example).
  6. In the Command input field, specify a command to be executed upon the selected event. In our example it is /usr/local/psa/bin/test-handler.sh.
  7. Click OK.

Note: In the script, we have specified the variables $NEW_CONTACT_NAME and $NEW_LOGIN_NAME. During execution of the handler, they will be replaced with name and login of the created client respectively. The entire list of available variables is provided in the section Events and Variables Passed by Event Handlers.

You should keep in mind that with the removal operations, the variables of type $NEW_xxx are not set. And with creation operations the parameters of type $OLD_xxx are not set.

Now if you login to your Parallels Plesk Panel and create a new client, specifying the value 'Some Client' in the Contact name field, and 'some_client' in the field Login, the handler will be invoked, and the following records will be added to the /tmp/event_handler.log:

Fri Mar 16 15:57:25 NOVT 2007

uid=0(root) gid=0(root) groups=0(root)

client created

name: Some client

login: some_client

If you want to specify one or few handlers more, repeat the actions above for another handler.

In this section:

Events and Variables Passed by Event Handlers on Linux Systems