• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Event Handler for new domain

GregSmid

New Pleskian
Hi there,

I can't seem to get the Event Handlers to trigger when creating a new Subscription with a new Domain. My understanding is that the "Domain created" event should fire, but I've assigned a script to that event and I don't get the expected output when I create a new Subscription. For troubleshooting purposes, I've kept the script very simple for now, it just writes the date, time and domain name to file.

C:\Scripts\DateTime.bat
Code:
echo %1 %date% %time% >> C:\Scripts\DatetimeLog.txt

The event handler has been created as follows:
Event: Domain Created
Priority: Normal (50)
User: Plesk Administrator
Command: C:\Scripts\DateTime.bat <new_domain_name>

Am I using the wrong Event Handler?
 
Command: C:\Scripts\DateTime.bat <new_domain_name>

Why you use <new_domain_name> as parameter for bat file in this command? Have you tried to use just C:\Scripts\DateTime.bat as command?
 
Hi Igor, thanks for your reply!

I'm passing the <new_domain_name> paramater to the script because I'd like it to log the name of the domain that gets created. The log file (C:\Scripts\DatetimeLog.txt) should look like:

Code:
mynewdomain.com Fri 01/10/2014  8:39:21.45

Once I get this working, I won't just be using the event handler for logging... I'll also be using it to create a new DNS zone on a secondary DNS server, as well as other functions. So, the name of the new domain has to be passed to the script.
 
Ok, after a lot of Googling, I've discovered here that the event I need to use for Plesk running on Windows is actually "Website Created". I can pass it the <new_domain_name> parameter and it works as I want it to, but only when I've created a new Subscription.

For new Subdomains, I can use the "Subdomain of a default domain created" event handler and pass it the <new_subdomain_name> parameter

For Domain Aliases, I had to use the "Default domain, alias created" event and pass it the <new_domain_alias_name> parameter. Using the "Domain alias created" did not work when creating an alias of a Default Domain, although I suspect it would fire if I made a secondary domain for a particular subscription, and then made an alias for that secondary domain.

This level of complexity for different events does give me a lot of granular control, I just wish the events were named more clearly -- especially the "Website Created" event!

Also, the Appendix C: Event Parameters Passed by Event Handlers page in the Plesk 11.5 documentation seems to be specifically for Plesk running on Linux. Is there a companion page that lists the events and event parameters specifically for Plesk running on Windows?
 
If that's the case, I respectfully say that there's a lot of work that needs to be done on the Appendix page. Below is a list of Event Trigger options that I took screenshots of from my Plesk Panel for Windows installation; you can see there are a number of entries on my list that don't appear in the Appendix, and there are a number of entries in the Appendix that don't appear on my list.

PleskEvents.jpg

Greg
 
I've run into a new snag... I can't find the event trigger that fires when the DNS is modified for the primary domain in a subscription.

When I make a change to the DNS zone for a primary domain, I see an 'Update Domain DNS Zone' event in the Action Log.
When I make a change to the DNS zone for a secondary domain, I see an 'Update additional domain DNS zone status' event in the Action log.

However, the "Domain DNS zone updated" Event Trigger only fires for updates to the DNS for the secondary zone. That event trigger actually appears in the list twice (35th from the top and 13th from the bottom) but I tried them both and they both had the same result. There are also event triggers listed for updates to the DNS zone for a domain alias (also in the list twice) and for updates to the DNS zone of subdomains, both of which work as expected.

Is there a trigger that will fire when I edit the DNS for a default domain?
 
Last edited:
Workaround!

Well, I've created a workaround for my problem of not having an Event Trigger that fires when I update the DNS for the default domain in a Subscription -- I created my own!

I used the Developing Extensions for Parallels Plesk Panel 11.5 - Event Handlers documentation figure this all out.

I created a .php file in "<plesk_dir>\admin\plib\registry\EventListener" and for my purposes called it DNSUpdate.php. The contents of the file are:

Code:
<?php
class UpdateDNS_EventListener implements EventListener
	{
	
	public function handleEvent($objectType, $objectId, $action, 
	$oldValues, $newValues)
		{
		
		/* // Debugging: Write the values to the error log:

		error_log("objectType:" . $objectType . " objectId:" . $objectId . " action:" . $action . " oldValues:" . $oldValues['Domain Name'] . " newValues:" . $newValues);
		
		*/

		// Check if this is a DNS zone update:
		
		if ($action == "domain_dns_update")
			{
			
			/* // Debugging:  Loop through the oldValues array and write the contents to a log file:
			
			$file = fopen("C:\\Program Files (x86)\\Parallels\\Plesk\\admin\\logs\\oldValue_array.log", "w");
			
			foreach($oldValues as $x=>$x_value)
				{
				
				fwrite($file, "Key=" . $x . ", Value=" . $x_value . "\r\n");
				
				}
			
			fclose($file);
			
			*/
			
			// Set the $DomainName variable:
			
			$DomainName = $oldValues['Domain Name'];
			
			// Set the command to run:
			
			$command = "C:\PROGRA~2\Parallels\Plesk\Scripts\DNS.bat " . $DomainName;
			
			// Run the DNS batch script:

			exec($command);
			
			}

		}
		
	}
	
return new F12_UpdateDNS_EventListener();

?>

Then I've put all the DNS manipulations I want to do into DNS.bat.

Hope this helps someone else in the same boat as I was. It really is just a workaround; what really needs to happen is that the available Event Triggers need to be fixed up.
 
Last edited:
Dammit, accidentally just deleted my post with a workaround solution. Three cheers for browser plugins that remember the contents of forms you submit! Here it is again:

I've created a workaround for my problem of not having an Event Trigger that fires when I update the DNS for the default domain in a Subscription -- I created my own!

I used the Developing Extensions for Parallels Plesk Panel 11.5 - Event Handlers documentation to figure this all out.

I created a .php file in "<plesk_dir>\admin\plib\registry\EventListener" and for my purposes called it DNSUpdate.php. The contents of the file are:

Code:
<?php
class UpdateDNS_EventListener implements EventListener
	{
	
	public function handleEvent($objectType, $objectId, $action, 
	$oldValues, $newValues)
		{
		
		/* // Debugging: Write the values to the error log:

		error_log("objectType:" . $objectType . " objectId:" . $objectId . " action:" . $action . " oldValues:" . $oldValues['Domain Name'] . " newValues:" . $newValues);
		
		*/

		// Check if this is a DNS zone update:
		
		if ($action == "domain_dns_update")
			{
			
			/* // Debugging:  Loop through the oldValues array and write the contents to a log file:
			
			$file = fopen("C:\\Program Files (x86)\\Parallels\\Plesk\\admin\\logs\\oldValue_array.log", "w");
			
			foreach($oldValues as $x=>$x_value)
				{
				
				fwrite($file, "Key=" . $x . ", Value=" . $x_value . "\r\n");
				
				}
			
			fclose($file);
			
			*/
			
			// Set the $DomainName variable:
			
			$DomainName = $oldValues['Domain Name'];
			
			// Set the command to run:
			
			$command = "C:\PROGRA~2\Parallels\Plesk\Scripts\DNS.bat " . $DomainName;
			
			// Run the DNS batch script:

			exec($command);
			
			}

		}
		
	}
	
return new F12_UpdateDNS_EventListener();

?>

Then I've put all the DNS manipulations I want to do into DNS.bat.

Hope this helps someone else in the same boat as I was. It really is just a workaround; what really needs to happen is that the available Event Triggers need to be fixed up.
 
Back
Top