PLESK EVENT MANAGER

Section 4.3 Example of handler

Example of adding a custom event handler.

Let's set up an event handler for the 'client creation', which accepts a client name as the first parameter, and the client's login as the second. For simplicity we will write a program in C, which will be further compiled to the client_create.exe executable file. The following is the source code used:

#include <stdio.h>
#include <tchar.h>

int _tmain(int argc, _TCHAR* argv[])
{
if (argc < 2) {
printf (_T ("Usage: eventtest filepath, args, ...\n"));
return 1;
}

FILE *f = _tfopen (argv[1], _T("a+"));
if (!f) {
printf (_T ("Can't open %s\n"), argv[1]);
return 1;
}

for (int i = 2; i < argc; ++i)
fprintf (f, _T ("arg %d: %s\n"), i - 2, argv[i]);

return 0;
}

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

In the command prompt you may see the parameters in the angle brackets <new_contact_name> and <new_login_name>. Before handler execution, they will be replaced with the name and login of the created client respectively. The entire list of available parameters is provided in Table 2. You should keep in mind that with the removal operations the parameters of the new_xxx type contain an empty string. And with creation operations the parameters of the old_xxx type contain an empty string.

Now if you log in to your Plesk control panel and create a new client, specifying the Some Client value in the Contact name field, and some_client in the Login field, the handler will be invoked, and the corresponding records will be added to the c:\result.txt file:

arg 0: param1
arg 1: Param2
arg 2: Parameter with spaces
arg 3: some_client
arg 4: Some Client


to top