Trigger Azure Function from Azure Monitor alerts
Azure Monitor alerts are a great way of getting notified of any threshold breach of your resource metrics and helps to keep a tab on the health of the Azure resources in a timely manner. Wouldn’t it be great if the follow-up action for the alert is also taken care of !!? Oh yes, keep reading on please…
Azure Monitor alerts gives us the option of triggering an Azure Function as a follow-up action.
For illustration purposes let us consider setting up a ‘Heartbeat’ alert for an Azure Virtual Machine (VM). Heartbeat is a great way to know if your Virtual machine is ‘alive’ , you would have a Heartbeat entry in your Log Analytics workspace every minute or so.
Steps
- Go to your VM resource and enable ‘Insights’ from the portal to flow through to the Log Analytics workspace
- Browse to Azure Monitor → Alerts → +New Alert Rule
- Select a specific scope of alert, in this case Log analytics workspace/VM
- Search for the “Heartbeat” metric and set the Alert logic as required
5. Create a new action group to trigger the Azure Function app. It is ideal to use a dedicated Service Principal in your Function for authenticating into Azure.