Forum Discussion
New V2 alert from PowerShell
Hi All,
I want to create alert using PowerShell and could certainly do this however I have three questions: -
1- When I am using "Add-AzureRmMetricAlertRule" CMDlet to create alerts they are coming under classic alerts. Why? . And how I could create new alert using PowerShell not the classic ones.
The script what I am using is as follows: -
Add-AzureRmMetricAlertRule -Location "Canada East" -MetricName "Percentage CPU" -Name "GouravRHEL CPU" -Operator GreaterThan -Threshold 90 -ResourceGroup "GouravRHEL" -TargetResourceId "/subscriptions/XXXXXXXXXXXXXXXXXXXXX/resourceGroups/GouravRHEL/providers/Microsoft.Compute/virtualMachines/GouravRHEL" -TimeAggregationOperator Average -WindowSize "02:00:00" -Action $action -Description "This rule sends alert of CPU"
2- In action I am adding mail ids, so the second question is related to this only. How I could add action group during alert creation using powershell.
3- My third and last question is there any possible way to use KQL in place of metric name. As we have some custom alert that are use KQL query to check condition in place of metric name.
Hi Gourav,
The cmdlet you are using is for classic metric alerts in Azure Monitor. Classic metric alerts didn't support action groups and used a custom notification mechanism.
We don't yet have PowerShell cmdlets for newer metric alerts. We are actively working on those and will provide an announcement once they are ready.In the meanwhile, if you are trying to create metric alerts, you can use Azure CLI to automate creating alerts. You can also create action groups through CLI as well.
If you trying to create log alerts based on Kusto queries, today the only way to automate it is through ARM templates. The PS cmdlets and CLI are being worked on, but are not available yet.
Regards,
Snehith
9 Replies
- Noa Kuperberg
Microsoft
Hi, This community space is mainly about Log Analytics and not alerts, but I've sent your message to the alerting team. They will reply here or send me their answer and I'll post it.- GouravINBrass ContributorThanks Noa, Please keep me posted about progress.
could you please let me know if we have any particular forum for Azure Monitors.- snehith
Microsoft
Hi Gourav,
The cmdlet you are using is for classic metric alerts in Azure Monitor. Classic metric alerts didn't support action groups and used a custom notification mechanism.
We don't yet have PowerShell cmdlets for newer metric alerts. We are actively working on those and will provide an announcement once they are ready.In the meanwhile, if you are trying to create metric alerts, you can use Azure CLI to automate creating alerts. You can also create action groups through CLI as well.
If you trying to create log alerts based on Kusto queries, today the only way to automate it is through ARM templates. The PS cmdlets and CLI are being worked on, but are not available yet.
Regards,
Snehith