-
Notifications
You must be signed in to change notification settings - Fork 3
Webhooks
- Tips & Tricks - Important considerations when implementing webhooks
- Examples - A repository of webhook examples for a variety of different platforms
- Getting Started - A quick guide on how to setup and implement your first webhook.
Please reference the official documentation to understand how Turbonomic's webhook functionality works:
- https://www.ibm.com/docs/en/tarm/latest?topic=policies-webhooks
- https://www.ibm.com/docs/en/tarm/latest?topic=policies-action-orchestration#orchestration_policy_1
- Identify what platform you’d like Turbo’s webhook to integrate with. Some questions to think about:
- Does this platform have an API you can make HTTP requests to? If "no", then Turbo cannot integrate its webhook functionality with that platform.
- In what format does this platform need to receive information?
- What kind of authentication do you need? Do you need to use custom headers?
- Before integrating with Turbo, test the platform’s API calls using tools like Postman or Advanced Rest Client (ARC)
- Can you successfully make API calls to the platform?
- Begin testing with Turbo
- Integrate the platform’s API payload into Turbo’s Workflow DTO. This involves escaping characters in the platform’s API payload and can lead to annoying syntactical errors when trying to add to Turbo. Leverage online escaping/unescaping tools. For example, JSON Escape and JSON Unescape Online Tool.
- Leverage Turbo’s Swagger API for testing:
- Swagger Documentation: https://www.ibm.com/docs/en/tarm/latest?topic=reference-turbonomic-rest-api-swagger-documentation
- API Documentation: https://www.ibm.com/docs/en/tarm/latest?topic=documentation-api-reference
- Access your Turbonomic Swagger Interface:
https://<YourTurboIP>/swagger- Add the webhook:
Workflows > POST /workflows - Test the webhook:
Workflows > POST /workflows/{workflow_Uuid} - Modify the webhook:
Workflows > PUT/workflows/{workflow_Uuid}
- Add the webhook:
- Consider which actions you plan on attaching your workflow to
- If using your webhook on multiple types of actions, ensure the Action DTO for each action has your specified variables, otherwise your webhook will fail. For example, if your Workflows DTO calls for the “cost” of an action (like for a cloud scale action)
$action.stats[0].filters[0].valuebut your webhook has been applied to on-prem VMs, then your webhook will fail for those VMs since there is no$action.stats[0].filters[0].valuein the Action DTO.
- If using your webhook on multiple types of actions, ensure the Action DTO for each action has your specified variables, otherwise your webhook will fail. For example, if your Workflows DTO calls for the “cost” of an action (like for a cloud scale action)
- For advanced uses, review the Apache Velocity documentation for more information. Examples include using a For Loop or If/Else logic.
- Implementation in Turbo
- Create a Policy and select your Workflow (webhook) to be used either during Action Generation, Before Execution, Action Execution, or After Execution.
- Consider having different webhooks for different action types and different scopes if you plan on referencing unique variables that only exist in certain Action DTOs.
These webhook examples have been built and maintained by the Turbonomic field organization. Use of these webhooks is unsupported.
A quick guide on how to setup and implement your first webhook.
Make sure the mediation-webhook pod is running on your Turbonomic deployment.
- Modify your deployment. Follow the
OVA Deploymentinstructions orKubernetes Deploymentinstructions based on your deployment type.-
OVA Deployment:
- SSH into your Turbonomic instance
- Edit the CR file:
vi /opt/turbonomic/kubernetes/operator/deploy/crds/charts_v1alpha1_xl_cr.yaml - Add the following line to your existing
specsection:webhook: enabled: true - Save and exit the file
- Apply the change:
kubectl apply -f /opt/turbonomic/kubernetes/operator/deploy/crds/charts_v1alpha1_xl_cr.yaml
-
Kubernetes Deployment:
- Edit your running deployment:
kubectl edit Xl - Add the following line to your existing
specsection:webhook: enabled: true - Save and exit the file.
- Edit your running deployment:
-
OVA Deployment:
- Verify the
mediation-webhookpod is running and ready:
kubectl get pods | grep webhook
Adding a webhook is done via the Turbonomic API. We'll use Turbonomic's Swagger API interface to add the webhook.
- Navigate to the Swagger interface:
https://<YOUR_TURBO_URL>/swaggerorhttps://<YOUR_TURBO_URL>/apidoc
- Expand the
Workflowssection and locatePOST /workflows. ClickTry It Out
- Paste your webhook payload in the
Bodysection. See theExamplessection to use pre-defined webhook payload examples for different platforms.- For quick testing you can use webhook.site to get a URL endpoint and investigate Turbonomic's action payload (the variables you can reference in your custom webhook).
- Here's a payload example using webhook.site, you can replace <YOUR_WEBHOOKSITE_URL> with your own.
{ "displayName": "Action Payload To Webhook.site", "className": "Workflow", "description": "Actions Send to Webhook Endpoint", "discoveredBy": { "readonly": false }, "type": "WEBHOOK", "typeSpecificDetails": { "url": "<YOUR_WEBHOOKSITE_URL>", "method": "POST", "template": "$converter.toJson($action)", "authenticationMethod": "NONE", "trustSelfSignedCertificates": false, "type": "WebhookApiDTO" } }
- For quick testing you can use webhook.site to get a URL endpoint and investigate Turbonomic's action payload (the variables you can reference in your custom webhook).
- Click
Executeto add the webhook to Turbo. Verify the200response.
- From the
Response Bodymake note of theuuidfor your webhook. You'll use this value to test your webhook in the next section.
You can use Turbonomic's Swagger API page (https://<YOUR_TURBO_URL>/swagger) to test your webhook before implementing it on real action execution.
- Now that you've created a webhook, on the Swagger API page, expand the
Workflowssection and locatePOST /workflows/{workflow_Uuid}. ClickTry It Out
- In the
workflow_Uuidbox, enter the UUID of the webhook you created in the previous section.
- Now we need the UUID of a Turbonomic action to test the webhook. One way to do this is to use your web browser's Developer Tools and open the Action Center in Turbonomic. This will allow you see the Action API call response which contains UUIDs for Turbonomic's pending actions.
- In a new browser tab, navigate to the Turbonomic web interface.
- While on this page, open your web browser's
Developer Tools> Navigate to theNetworksection - In the Turbonomic interface, navigate to any window that shows the
Pending Actionswidget. Click the widget'sShow Allbutton.
- In the
Developer Tools > Networkwindow, notice anactionsAPI call is made. Click on it and open itsPreviewtab. - You'll see a list of actions - the same actions that are visible in the Turbonomic interface. Expand one of the actions. Record its
actionID.
- Back on the Swagger page, in the
bodysection, replace <YOUR_ACTION_ID> with theactionIDyou recorded above. Click Execute.{ "operation": "TEST", "actionId": <YOUR_ACTION_ID> }
- Scroll down to the
Response Bodysection and verify you received the following response:{ "succeeded": true, "details": "The call to webhook endpoint was successful." }
- Your webhook has been successfully triggered! If you were using the webhook.site webhook as an example, you can see Turbonomic successfully sent the action payload and it was received. You can now see all the action details that can be referenced in your custom webhook integration.
Now that you've created a webhook and verified it executes properly, create an Automation Policy and attach your webhook to it.
- In the Turbonomic web interface, go to
Settings>Policies
- Click on
New Policy
- Select
Automation Policy
- In this example, we'll select
Virtual Machine. You can integrate a webhook into any automation policy for any entity type.
- Provide a name for your policy. Example:
VM Resize with Webhook
- In the
Scopesection, click onSelect Group of Virtual Machinesto specify which VMs should have this policy applied to them.
- Select an existing Group or click
New Groupto create something new. ClickSelectwhen done.
- Once you've selected your Scope, expand
Automation and Orchestrationand click onAdd Action
- In action type select the actions you'd like to associate with your webhook. In this example, we'll select
VCPU-Resize-Up,VCPU-Resize-Down,VMEM-RESIZE-UP,VMEM-RESIZE-DOWN
- We'll leave the
Action Acceptanceset toManual. In this example, we'll tell our webhook to triggerAfter Executionof an action. Expand the drop down forAfter Executionand selectNotify action workflow.
- Click
Select Workflow
- You'll see the list of workflows (ie Webhooks) that you've created. In this example, we'll select the webhook we created in the previous section. Click the check box of the workflow and click
Save.
- Click
Submit
- Click
Save Policy
- Once you've saved the policy, you'll need to wait ~10 minutes for Turbonomic to associate the policy with the scope you selected. To verify once it's done, on the navigation side bar, select
Search>Groups> Type the name of the group you used in the Scope of the policy. In my example, that wasMy VMs. Click on the Group to navigate to itsOverviewpage.
- Click on the
Policiestab at the top to see if the your policy has been associated with the group. If you don't see it listed, wait a few more minutes and refresh the page.
- Now that it's associated, go to the
Actionstab. Since the Policy we created is forVirtual MachineVCPUandVMEMresize actions, let's navigate in Action Center toResize>Virtual Machines
- To confirm the webhook will be triggered when we take an action, let's....take an action! Check the checkbox of one of the actions and click
Execute.
- Once the action is executed, you can see the webhook was triggered to send the action payload to the webhook.site URL. It works!
- Now you can reference the real-world examples and start building your own webhooks.