Event Handlers

Event handlers are designed to help you receive notifications about Plesk events. The most typical way to use them is as follows: you create a script to be executed upon a certain Plesk event, and then you associate the event and your script using an event handler. Each time the event happens, the event handler will trigger your script.

event-handlers.gif

The instruction to run is not necessarily a script. You can also associate event handlers with a system command or a binary file. In addition, there are two facts to consider before you start using event handlers:

Note: We strongly recommend that you enter a full path to a script file as a command to event handlers. Although you can assign direct system commands, they might not work. Say, commands with output redirection operators >, <, >>, or | will not work.

Running scripts via event handlers

For example, let's store the names of new customers on the file system. To do this, first we should find the environment variable that contains the contact name. This variable is listed in the Administrator's Guide, Appendix > Customer account created.

As you can see, the variable name is NEW_CONTACT_NAME. Now we need to create an event handler.

To create the event handler on Linux:

  1. Create a shell script (for example, write-names.sh) containing the following code:
#!/bin/bash
echo "Customer account has been created. Name: ${NEW_CONTACT_NAME}" >> /tmp/event_handler.log
  1. Log in to Plesk, go to the Tools & Settings tab > Event Manager.
  2. Click Add New Event Handler and specify the following:
  3. Click OK.

To create the event handler on Windows:

  1. Create a batch file (for example, write-names.bat) containing the following code:
echo "Customer account has been created. Name: %1" >> C:\Windows\Temp\event_handler.log
  1. Log in to Plesk, go to the Tools & Settings tab > Event Manager.
  2. Click Add New Event Handler and specify the following:
C:\Windows\Temp\write-names.bat <new_contact_name>
  1. Click OK.

The event handler will be triggered every time a new customer account is created, and will write the customer’s contact name to the specified file.

For more details on event handlers, refer to the Administrator's Guide, the chapter Event Tracking. This chapter provides instructions on how to create event handlers and describes environment variables related to each Plesk event.