Skip to content

Using Event Handlers

You can use event handlers in SolusVM 2 to have certain actions take place automatically when specific events take place. At the moment, webhooks are the only supported event handler type. Other event handler types may be added in the future.

When creating an event handler, you can choose one or more events from the list of supported events, such as adding an IP address or removing a server. You can only create an event handler for supported events. Every time a supported event takes place, no matter whether it is initiated by an administrator or a customer, all event handlers associated with that event are triggered.

Creating a Webhook

A webhook is a user-defined HTTP/HTTPS callback. Every time an event handler of this type is triggered, it executes the webhook, and then SolusVM 2 sends a POST request to the webhook URL. SolusVM 2 follows up to five redirects, and does not check the validity of the website's SSL/TLS certificate (if any). A number of predetermined parameters are always passed via the URL (for example, the ID of the server being deleted, or the IP address being added). A webhook may also be configured to pass additional parameters defined by the user.

Every time a webhook is triggered, a task is created in SolusVM 2. The task will have the "Failed" status if the script returns a 4хх or 5хх HTTP status code.

To create a webhook:

  1. Log in to SolusVM 2.
  2. Go to Settings > Event Handlers, and then click Add Webhook.
  3. Give your webhook a unique name.
  4. Specify the webhook URL. A request will be sent to this URL every time the webhook is triggered.
  5. Select one or more events from the drop-down menu. Every time a supported event takes place, the webhook will be triggered.
  6. (Optional) Specify additional request parameters to be passed via the webhook URL. The parameters must be in the JSON format.
  7. (Optional) Select the "Enabled" checkbox if you want the webhook to become active after creation. Alternatively, you can enable the webhook later.
  8. Click Save.

The webhook has been created. You can find it in Settings > Event Handlers. If you enabled the webhook during creation, the next time a supported event takes place, the webhook will be triggered, and a request will be sent to the webhook URL.

Modifying, Disabling, and Removing Webhooks

To modify a webhook:

  1. Log in to SolusVM 2.
  2. Go to Settings > Event Handlers.
  3. Click the icon corresponding to the webhook you want to modify.
  4. Make the desired changes, and then click Save.

The changes are now in effect.

To enable or disable a webhook:

  1. Log in to SolusVM 2.
  2. Go to Settings > Event Handlers.
  3. Click the toggle button corresponding to the webhook you want to enable or disable so that it shows "Enabled" (blue) or "Disabled" (grey).

The webhook is now enabled (or disabled).

To delete a webhook:

  1. Log in to SolusVM 2.
  2. Go to Settings > Event Handlers.
  3. Click the icon corresponding to the webhook you want to delete, and then click Delete.

The webhook is deleted.

The List of Parameters Passed by Webhooks

Every time a webhook is triggered, it passes the following parameters via the URL:

  • crId
  • crHostname
  • crStatus (commissioning, configure_network, active, failed, unavailable)
  • crLicenseType (micro, mini, standard)
  • serverId
  • serverIps (for example, ["10.0.0.1","10.0.0.2"])
  • serverHostname
  • serverUuid
  • serverStatus (not exist, started, stopped, unavailable)
  • userId
  • billingUserId
  • userEmail
  • userStatus (active, locked, suspended)
  • userAllowedIps (for example, ["10.0.0.1","10.0.0.2"])

Webhook Example

You can create a webhook that will automatically update the IP addresses of servers migrated from one compute resource to another in WHMCS.

To create the webhook:

  1. Log in to your WHMCS server via SSH.
  2. Locate the hook_example.php file shipped with the SolusVM 2 WHMCS addon. The file should be in the modules/servers/solusvm2vps/ directory.
  3. Make a copy of the file, and then start editing the copy.
  4. Remove the exit(); on line 6.
  5. Add your secret(s) to the $securitySecrets variable.
  6. Add your SolusVM 2 management node's IP address(es) to the $connectionIPs variable.
  7. Save changes.
  8. Log in to SolusVM 2.
  9. Go to Settings > Event Handlers, and then click Add Webhook.
  10. Give your webhook a unique name.
  11. Specify the URL of the edited script.
  12. Select "Add or remove an additional IP" from the drop-down menu.
  13. Specify the secret(s) you added to the script during step 5 of this procedure:

    {
     "secret": "<your secret goes here>"
    }
    
  14. Select the "Enabled" checkbox, and then click Save.

Now, every time a server is migrated, a task to update the server's IP address in WHMCS will be created in SolusVM 2.

Back to top