Previous page | Next page | Locate page |

### Adding Event Handlers (Windows Hosting)

To add an Event Handler:

For instance, let's create an event handler for the 'client account creation' event. The handler will accept a client name as the first parameter, and the client's login 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 client account

    echo "client created" >> c:\windows\temp\event_handler.log

    rem client's name

    echo "name: %1"       >> c:\windows\temp\event_handler.log

    rem client's login

    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 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 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 login of the created client respectively. The entire list of available parameters is provided below. You should keep in mind that with the removal operations, the parameters of type new_xxx contain an empty string. And with creation operations the parameters of type old_xxx contain an empty string.

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 `c:\windows\temp\event_handler.log`:

    Sat Jun 26 21:46:34 NOVT 2004

    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.

To learn more about the events that can be processed by the event handler, refer to the Parallels Plesk Panel Advanced Administration Guide available from the Parallels Web site.