Nutanix webhook is an HTTP callback – an HTTP POST that occurs when something happens; a simple event-notification via HTTP POST. Nutanix Webhooks are basically user defined HTTP callbacks (or small code snippets linked to a web application) which are triggered by specific events.
Whenever that trigger event occurs in the source site, the Nutanix webhook sees the event, collects the data, and sends it to the URL specified by you in the form of an HTTP request. You can even configure an event in one site to trigger an action in another site.
Nutanix webhooks are events that trigger an action. In most cases, they are used for communication between systems. This is the simplest way of getting an alert when something happens in another system. They are called webhooks because they work as software hooks over the web.
Explained Nutanix webhook with code examples to how to create / update / delete / Nutanix webhook here.
Creating a Webhook
Lets create the Nutanix Webhook to Send the Nutanix cluster an HTTP POST request whose body contains the information essential to creating a webhook (the events for which you want the listener to receive notifications, the listener URL, and other information such as a name and description of the listener).
Note: Each POST request creates a separate webhook with a unique UUID, even if the data in the body is identical. Each webhook generates a notification when an event occurs, and that results in multiple notifications for the same event. If you want to update a webhook, do not send another request with changes. Instead, update the webhook. See Updating a Webhook.
To create a webhook, send the Nutanix cluster an API request of the following form:
POST https://cluster_IP_address:9440/api/nutanix/v3/webhooks { "metadata": { "kind": "webhook" }, "spec": { "name": "string", "resources": { "post_url": "string", "credentials": { "username":"string", "password":"string" }, "events_filter_list": [ string ] }, "description": "string" }, "api_version": "string" }
Replace cluster_IP_address with the IP address of the Nutanix cluster and specify appropriate values for the following parameters:
- name. Name for the webhook.
- post_url. URL at which the webhook listener receives notifications.
- username and password. User name and password to use for authenticating to the listener. Include these parameters if the listener requires them.
- events_filter_list. Comma-separated list of events for which notifications must be generated.
- description. Description of the webhook.
- api_version. Version of Nutanix REST API in use.
The following sample API request creates a webhook that generates notifications when VMs are powered on and powered off:
POST https://192.0.2.3:9440/api/nutanix/v3/webhooks { "metadata": { "kind": "webhook" }, "spec": { "name": "vm_notifications_webhook", "resources": { "post_url": "http://192.0.2.10:8080/", "credentials": { "username":"admin", "password":"Nutanix/4u" }, "events_filter_list": [ "VM.ON", "VM.OFF", "VM.UPDATE", "VM.CREATE", "NETWORK.CREATE" ] }, "description": "Notifications for VM events." }, "api_version": "3.0" }
The Nutanix cluster responds to the API request with a 200 OK
HTTP response that contains the UUID of the webhook that is created. The following response is an example:
{ "status": { "state": "PENDING" }, "spec": { . . . "uuid": "003f8c42-748d-4c0b-b23d-ab594c087399" } }
The notification contains metadata about the entity along with information about the type of event that occurred. The event type is specified by the event_type parameter.
Listing Webhooks
Listing Nutanix Webhook – You can list webhooks to view their specifications or to verify that they were created successfully.To list webhooks, do the following:
Procedure
- To show a single webhook, send the Nutanix cluster an API request of the following form:GET https://cluster_IP_address/api/nutanix/v3/webhooks/webhook_uuidReplace cluster_IP_address with the IP address of the Nutanix cluster. Replace webhook_uuid with the UUID of the webhook that you want to show.
- To list all the Nutanix webhooks configured on the Nutanix cluster, send the Nutanix cluster an API request of the following form:POST
https://cluster_IP_address:9440/api/nutanix/v3/webhooks/list { “filter“: “string”, “kind”: “webhook”, “sort_order“: “ASCENDING”, “offset“: 0, “total_matches“: 0, “sort_column“: “string”, “length“: 0 }Replace cluster_IP_address with the IP address of the Nutanix cluster.
specify appropriate values for the following parameters:
- filter – Filter to apply to the list of webhooks.
- sort_order – Order in which to sort the list of webhooks. Ordering is performed on webhook names.
- offset
- total_matches – Number of matches to list.
- sort_column – Parameter on which to sort the list.
- length.
Updating a Webhook
Lets update the Nutanix Webhook – You can update a webhook by sending a PUT request to the Nutanix cluster. You can update the name, listener URL, event list, and description.To update a webhook, send the Nutanix cluster an API request of the following form:
PUT https://cluster_IP_address:9440/api/nutanix/v3/webhooks/webhook_uuid { "metadata": { "kind": "webhook" }, "spec": { "name": "string", "resources": { "post_url": "string", "credentials": { "username":"string", "password":"string" }, "events_filter_list": [ string ] }, "description": "string" }, "api_version": "string" }
Replace cluster_IP_address and webhook_uuid with the IP address of the cluster and the UUID of the webhook you want to update, respectively. For a description of the parameters, see Creating a Webhook.
Deleting a Webhook
Delete Nutanix Webhook – To delete a webhook, send the Nutanix cluster an API request of the following form:
DELETE https://cluster_IP_address/api/nutanix/v3/webhooks/webhook_uuid
Replace cluster_IP_address and webhook_uuid with the IP address of the cluster and the UUID of the webhook you want to update, respectively.
Notification Format
Nutanix Webhook notification format – An event notification has the same content and format as the response to the version 3.0 REST API call associated with that event. For example, the notification generated when a VM is powered on has the same format and content as the response to a REST API call that powers on a VM. However, the notification also contains a notification version, and event type, and an entity reference, as shown:
{ "version":"1.0", "data":{ "metadata":{ "status": { "name": "string", "providers": {}, . . . "event_type":"VM.ON", "entity_reference":{ "kind":"vm", "uuid":"63a942ac-d0ee-4dc8-b92e-8e009b703d84" } }
For VM.DELETE and SUBNET.DELETE, the UUID of the entity is included but not the metadata.
Nutanix Webhook Coding Example
This is the Nutanix Webhook code example:
// Copyright (c) 2017 Nutanix Inc. All rights reserved. // Package with all the constants required by the listener library. package lib const ( // Webhook URLs CreateWebhook = "/api/nutanix/v3/webhooks" ListWebhooks = "/api/nutanix/v3/webhooks/list" GetWebhook = "/api/nutanix/v3/webhooks/{uuid}" UpdateWebhook = "/api/nutanix/v3/webhooks/" DeleteWebhook = "/api/nutanix/v3/webhooks/{uuid}" // Auth Check URL GetCurrentUser = "/api/nutanix/v3/users/me" // Listener Defaults DefaultListenerPort = "8080" ListenerCallbackURL = "/listener/callback" EventConsumerCallbackMethod = "OnEvent" WebhookNamePrefix = "Nutanix_Listener_Webhook_" WebhookKind = "webhook" // Events (Can be taken from the YAML config later) VM_CREATE = "VM.CREATE" VM_DELETE = "VM.DELETE" VM_ON = "VM.ON" VM_OFF = "VM.OFF" VM_UPDATE = "VM.UPDATE" VM_MIGRATE = "VM.MIGRATE" VM_NIC_PLUG = "VM.NIC_PLUG" VM_NIC_UNPLUG = "VM.NIC_UNPLUG" )
hopefully, You have got the detailed information about Nuanix Webhook concept and coding idea.
Thanks to being with HyperHCI Tech Blog to stay tuned with latesat and trending technology.!
Useful Links
- Shutdown / Start Nutanix vSphere Cluster – Best Practice
- Nutanix Prism Supports Top 5 Web Browsers
- Nutanix AHV Supported Guest OSÂ List
- Install Nutanix LCM Dark Site Bundle on Linux Server