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_
(for instance). Let's register it by creating an event handler via the control panel:plesk_panel_installation_directory/bin
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).
/usr/local/psa/bin/test-handler.sh
.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 the Parallels Plesk Panel Advanced Administration Guide available from the Parallels Web site.
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.
For a full list of the parameter templates that can be used when setting up an event handler, refer to the Parallels Plesk Panel Advanced Administration Guide available from the Parallels Web site.