Adding Event Handlers (Windows)

To add an Event Handler:

For instance, let's create an event handler for the 'customer account creation' event. The handler will accept a customer's name as the first parameter, and the customer's username as the second. For simplicity, we will use a batch file called test-handler.bat that looks as follows:

echo "--------------" >> c:\windows\temp\event_handler.log
rem information on the event date and time
date /T   >> c:\windows\temp\event_handler.log
rem information on the created customer account
echo "customer created" >> c:\windows\temp\event_handler.log
rem customer's name
echo "name: %1"       >> c:\windows\temp\event_handler.log
rem customer's username in Plesk
echo "login: %2"      >> c:\windows\temp\event_handler.log
echo "--------------" >> c:\windows\temp\event_handler.log

This script prints some information to a file so that we could control its execution.

Suppose that our script is located in the directory c:\program files\parallels\plesk\scripts\. Let's register it by creating an event handler via the Administrative Panel:

  1. Go to Tools & Settings > Event Manager.
  2. Click Add Event Handler.
  3. Select the event you wish to assign a handler to in the Event drop-down box.
  4. Select the priority for handler execution, or specify a custom value. To do this, select custom in the Priority drop-down list 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.
  6. In the Command input field, specify a command to be executed upon the selected event. In our example, it is c:\program files\parallels\plesk\scripts\test-handler.bat" <new_contact_name> <new_login_name>.

    Note that if directory names or the file name contains spaces, the path should be quoted.

  7. Click OK.

Note: In the command, we have specified the parameters in the angle brackets <new_contact_name> and <new_login_name>. Before executing the handler, they will be replaced with name and username of the created customer. The entire list of available parameters is provided in Event Parameters Passed by Event Handlers.

Now if you login to your Plesk and create a customer account, specifying the value 'Some Customer' in the Contact name field, and 'some_customer' in the field Login, the handler will be invoked, and the following records will be added to the c:\windows\temp\event_handler.log:

Mon March 15 21:46:34 NOVT 2010
customer created
name: Some Customer
username: some_customer

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