Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How can I set up notifications for VM shutdowns across multiple subscriptions


How can I set up notifications for VM shutdowns across multiple subscriptions


To set up notifications for VM shutdowns across multiple Azure subscriptions, you can leverage Azure Monitor and Azure Activity Logs. Here’s a step-by-step guide:

1. Use Azure Activity Logs: Azure Activity Logs provide a centralized way to track events across your subscriptions. You can use these logs to monitor VM shutdown events.

2. Create an Alert Rule:
- Go to Azure Monitor and select "Alerts."
- Create a new alert rule using Azure Activity Logs as the signal source.
- Use a Kusto Query Language (KQL) query to filter for VM shutdown events. For example:

kql
     AzureActivity
     | where OperationNameValue == "Microsoft.Compute/virtualMachines/deallocate/action"
     | where ActivityStatusValue == "Succeeded"
     

- Configure the alert to notify you via email or other preferred methods.

3. Apply Across Multiple Subscriptions:
- Ensure your Azure Activity Logs are being sent to a Log Analytics workspace that can collect data from multiple subscriptions.
- Use Azure Monitor to create alert rules that apply across all subscriptions by selecting the appropriate scope during rule creation.

4. Automation and Notifications:
- For automated actions like sending notifications or triggering further automation, consider integrating with tools like Azure Logic Apps or Azure Functions. These can handle custom logic and notifications based on the alert triggers.

5. Alert Processing Rules:
- If you need to suppress notifications during maintenance periods, use Alert Processing Rules to manage how alerts are processed across different subscriptions.

By following these steps, you can effectively monitor and receive notifications for VM shutdowns across multiple Azure subscriptions.

Citations:
[1] https://techcommunity.microsoft.com/blog/startupsatmicrosoftblog/how-to-automatically-shut-down-idle-vms-in-azure/4376055
[2] https://learn.microsoft.com/en-us/azure/devtest-labs/devtest-lab-auto-shutdown
[3] https://serverfault.com/questions/747712/azure-script-to-start-or-shut-down-multiple-vms
[4] https://stackoverflow.com/questions/79047436/how-to-create-an-alert-for-data-collection-rule-deletion-across-all-vms-in-a-sub
[5] https://stackoverflow.com/questions/69839258/azure-monitor-alert-multiple-subscriptions
[6] https://www.reddit.com/r/AZURE/comments/1er2v8t/alert_when_a_vm_goes_offline/
[7] https://learn.microsoft.com/en-us/answers/questions/1382320/alert-processing-rule-in-different-subscriptions
[8] https://techcommunity.microsoft.com/discussions/azureobservability/azure-alert-on-multipel-subscriptions/4172366