Webhooks in Xen Orchestra
A new feature coming for our next release: webhooks. What's the big deal with that? Well, in fact, that's huge, and we'll see why.
A new feature is coming for our next release: webhooks. What's the big deal with them? Well it's huge infact, and we'll see why.
What's a webhook?
The shortest definition you can find is:
Webhooks are user-defined HTTP callbacks
In other words when there is an event, it will "notify" a target URL of your choice.
Let's take a simple example: you want to be notified in a chat application (eg inside a Slack channel) when a VM is created. Possibilities are endless, as you will see in this blog post.
In Xen Orchestra
A webhook is very simple: it will perform an HTTP POST request, with a body containing JSON with some values.
You can set it up in the UI:
In this example, we'll send a webhook to
https://my-domain.net?action=vm.startjust before ("pre") executing
vm.start(starting a VM).
Here are a few examples, obviously your imagination is the limiting factor here.
Now you can ping your CI/CD platform when VMs are created. Notice that you can use the XO API in one way to create VMs and be notified when it's done thanks to our webhooks.
We are now closing the loop to offer you a complete solution that can be fully integrated.
These webhooks are also a great way to have more automation in your infrastructure. For example:
- a custom application managing your HA database could be notified in case of VM migration, and change a master/slave configuration accordingly
- load balancing applications can be aware of VM operations (eg HA proxy)
- trigger an action on your infrastructure in case of the emergency shutdown feature of XO (eg calling the UPS)
- change a firewall or network rule automatically (migration/creation)
- change a DHCP rule from a VM MAC address on VM creation
- billing: you can use a CRM/billing platform to know who created VMs in a self service environment and make the right decision/invoicing automatically
- store the UUID of all VMs created in your infrastructure tracking/database
Obviously, you can imagine notifications based on specific actions:
- a chat application can be notified every time a VM is created in Xen Orchestra (or if a VM is shutdown)
- you can page/alert (using PagerDuty or any external tool) if someone decides to shutdown a host, migrate a VM or perform any unexpected operations in XO
- security alerts on user creation
Pre or post webhooks
A webhook can be called before the command is executed, or after it returned.
Both can be useful: if you know that live migration will trigger consequences, a "pre" webhook can already perform necessary actions on your infrastructure. Post webhooks can be useful to trigger something after the call ends, and can forward the results.
Note: the migration action will start immediately after, so keep that in mind in case your custom action is longer than a potential live migration.
Your webhook use cases?
Feel free to share your potential use cases in our forum!