I'm trying to create alerts in LogAnlytics in azure portal, need to create 6 alerts for 5 db's, so have to create 30 alerts manually and is time consuming.
Hence would require an automated approach.
Tried to create via Creating Alerts Using Azure PowerShell, but this creates the alerts in the Alerts Classic under Monitor but this is not what is required, require it to be created in Log Analytics.
Next approach was via Create a metric alert with a Resource Manager template but this was metric alert and not LogAnalytics alert
At last tried Create and manage alert rules in Log Analytics with REST API, but this is a tedious process need to get the search id, schedule id, threshold id and action id. Even after trying to create the threshold id or action id the error I'm facing is "404 - File or directory not found." (as in the image).
Could someone please suggest me on how should this be proceeded, or is there any other way to create alerts apart from the manual creation?
If you use the Add activity log alert
to add a rule, you will find it in the Alerts of Log Analytics in the portal.
Please refer to the Log Analytics Documentation,
Alerts are created by alert rules in Azure Monitor and can automatically run saved queries or custom log searches at regular intervals.
Update:
Please refer to my test screenshots, I think you should check the specific resource group or other things, etc.
Even so, activity log alert belongs to the alerts(classic), alerts is a new metric alert type. You could check the link new metric alert type
in this article, it points the alerts. it is not supported by powershell and CLI currently.
Please refer to:
1.Use PowerShell to create alerts for Azure services
2.Use the cross-platform Azure CLI to create classic metric alerts in Azure Monitor for Azure services
As mentioned in the two articles:
This article describes how to create older classic metric alerts. Azure Monitor now supports newer, better metric alerts. These alerts can monitor multiple metrics and allow for alerting on dimensional metrics. PowerShell support for newer metric alerts is coming soon.
This article describes how to create older classic metric alerts. Azure Monitor now supports newer, better metric alerts. These alerts can monitor multiple metrics and allow for alerting on dimensional metrics. Azure CLI support for newer metric alerts is coming soon.
@Shashikiran : You can use the script published in the GITHUB https://github.com/microsoft/manageability-toolkits/tree/master/Alert%20Toolkit
This can create a few sample alerts. For now we have included some sample core machine monitoring alerts like CPU , hardware failures , SQL , etc... Also these are only the log alerts. You can use this as a sample code and come up with your code.