4
votes

I have created Azure Log Analytics (Monitor) Alert to monitor the Logic App Failures and I have done this using Azure portal. I would like to know how can we export the Alert created from Azure Portal as an ARM template? Anyone know how we can achieve it.

Thanks enter image description here

enter image description here

2

2 Answers

9
votes

If you want to export the ARM template of the alert in the portal, please follow the steps below.

1.In the portal, navigate to the resource group which the alert located in(Note: It is the group of the alert, not the group of the alert's target resource), select the Show hidden types option -> find your alert and select it -> click Export Template.

enter image description here

2.Click the Download like below, then it will download the template as a compressed file which includes the template.json and parameters.json to local.

enter image description here

Update:

What you are using is legacy Log Analytics Alert, from June 1, 2019, it automatically use new scheduledQueryRules by default in Azure portal, its resource type is microsoft.insights/scheduledqueryrules.

In your case, you could follow this link to switch from the old alert to new one.

Or create a new alert in the portal, navigate to the Log Analytics workspace in the portal -> New alert rule -> Add Custom log search and create it.

enter image description here

Ater create it, in the resource group, select the Show hidden types option, you will find the alert like below, then you can export the template.

enter image description here

0
votes

You are using the legacy log analytics API and this doesn't support export for templates as they are not ARM tracked resources. The definition for those would be on the workspace itself (under savedsearch => schedule => action). If you want to be able to export more easily, please consider using the newer ScheduledQueryRules API. Learn more on how to switch here: https://docs.microsoft.com/azure/azure-monitor/platform/alerts-log-api-switch#process-of-switching-from-legacy-log-alerts-api

Please note this could be a big change due to API change, please review the complete article to understand what will happen after the switch.