Forum Discussion
Custom JSON Webhook for Teams showing search results
MemK1 I've done this as follows: Create a PowerShell script in an Azure Automation account that reads out data from the alert, then create a https://docs.microsoft.com/en-us/azure/automation/automation-webhooks for this runbook (technically this script could also be in an Azure function). Create an Action Group with a Webhook as action, pointing the webhook of the runbook you've created. Make sure you have "https://docs.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-common-schema-definitions" enabled in the Action Group, otherwise you go nuts trying to process the different alerts. At the end of the PowerShell script once you've processed the json payload, use the https://evotec.xyz/hub/scripts/psteams-powershell-module/ module to send your alert to Teams (I've even gone so far as to check the severity of the alert, and severity 0 goes to an on-call phone with more detailed info than what the normal SMS alerts give). Last but not least of course, set up your alert and set the Action Group as the target.
In order to process the json payload, I've used https://webhook.site/ to make more sense of what alert gives what type of output. If you set the URL given by webhook.site in the Action Group, whenever an alert triggers, the webhook data will be sent to that website and you're able to see a full example for different types of alerts.
I can't give you actual code, but let's just say to begin with this as code:
param
(
[object] $WebhookData
)
$WebhookBody = ConvertFrom-Json -InputObject $WebhookData
I hope this helps.