SOLVED

New V2 alert from PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-297958%22%20slang%3D%22en-US%22%3ENew%20V2%20alert%20from%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-297958%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20create%20alert%20using%20PowerShell%20and%20could%20certainly%20do%20this%20however%20I%20have%20three%20questions%3A%20-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E1-%3C%2FSTRONG%3E%20When%20I%20am%20using%20%22Add-AzureRmMetricAlertRule%22%20CMDlet%20to%20create%20alerts%20they%20are%20coming%20under%20classic%20alerts.%20Why%3F%20.%20And%20how%20I%20could%20create%20new%20alert%20using%20PowerShell%20not%20the%20classic%20ones.%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20script%20what%20I%20am%20using%20is%20as%20follows%3A%20-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EAdd-AzureRmMetricAlertRule%20-Location%20%22Canada%20East%22%20-MetricName%20%22Percentage%20CPU%22%20-Name%20%22GouravRHEL%20CPU%22%20-Operator%20GreaterThan%20-Threshold%2090%20-ResourceGroup%20%22GouravRHEL%22%20-TargetResourceId%20%22%2Fsubscriptions%2FXXXXXXXXXXXXXXXXXXXXX%2FresourceGroups%2FGouravRHEL%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2FGouravRHEL%22%20-TimeAggregationOperator%20Average%20-WindowSize%20%2202%3A00%3A00%22%20-Action%20%24action%20-Description%20%22This%20rule%20sends%20alert%20of%20CPU%22%3C%2FPRE%3E%3CP%3E%3CSTRONG%3E2-%3C%2FSTRONG%3E%26nbsp%3B%20In%20action%20I%20am%20adding%20mail%20ids%2C%20so%20the%20second%20question%20is%26nbsp%3Brelated%20to%20this%20only.%20How%20I%20could%20add%20action%20group%20during%20alert%20creation%20using%20powershell.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E3-%3C%2FSTRONG%3E%20My%20third%20and%20last%20question%20is%20there%20any%20possible%20way%20to%20use%20KQL%20in%20place%20of%20metric%20name.%20As%20we%20have%20some%20custom%20alert%20that%20are%20use%20KQL%20query%20to%20check%20condition%20in%20place%20of%20metric%20name.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-297958%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Log%20Analytics%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-482685%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20New%20V2%20alert%20from%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-482685%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F312539%22%20target%3D%22_blank%22%3E%40Pedro35%3C%2FA%3E%26nbsp%3B%2C%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F287544%22%20target%3D%22_blank%22%3E%40sarbis%3C%2FA%3E%26nbsp%3BCmdlets%20for%20new%20metric%20alerts%20are%20now%20available.%20Please%20see%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fazure%2Frelease-notes-azureps%3Fview%3Dazps-1.8.0%23azmonitor%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fazure%2Frelease-notes-azureps%3Fview%3Dazps-1.8.0%23azmonitor%3C%2FA%3E%26nbsp%3Band%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.monitor%2Fadd-azmetricalertrulev2%3Fview%3Dazps-1.8.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.monitor%2Fadd-azmetricalertrulev2%3Fview%3Dazps-1.8.0%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3ERegards%2C%3C%2FP%3E%0A%3CP%3ESnehith%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-392969%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20New%20V2%20alert%20from%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-392969%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F103580%22%20target%3D%22_blank%22%3E%40Snehith%20Muvva%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20there!%3C%2FP%3E%3CP%3EI%20just%20checked%20the%20site%20you%26nbsp%3Brecommended%20and%20still%20no%20news%20about%20PowerShell%20commands%20to%20support%20the%20new%20V2%20alerts..%3C%2FP%3E%3CP%3EBut%20yes%2C%20on%20the%2028th%20of%20March%20there%20was%20the%20%22%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fupdates%2Fclassic-alerting-migration%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ENew%20tool%20available%20to%20migrate%20from%20classic%20monitoring%20alerts%3C%2FA%3E%22%20announce.%3C%2FP%3E%3CP%3EJust%20waiting%20for%20this%2C%20to%20update%20my%20monitoring%20scripts.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%20Pedro.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-354090%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20New%20V2%20alert%20from%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-354090%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F287544%22%20target%3D%22_blank%22%3E%40sarbis%3C%2FA%3E%2C%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20expect%20PowerShell%20cmdlets%20for%20newer%20metric%20alerts%20to%20be%20available%20by%20end%20of%20March.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20subscribe%20to%26nbsp%3B%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fupdates%2F%3Fupdatetype%3Dmanagement%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fupdates%2F%3Fupdatetype%3Dmanagement%3C%2FA%3E%20or%20keep%20an%20eye%20out%20on%20What's%20new%20tab%20in%20Azure%20Monitor%20to%20get%20notified%20when%20we%20release%20this.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERegards%2C%3CBR%20%2F%3ESnehith%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353882%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20New%20V2%20alert%20from%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353882%22%20slang%3D%22en-US%22%3EHi%20Snehith%2C%3CBR%20%2F%3E%3CBR%20%2F%3EDo%20you%20have%20any%20EDT%20on%20the%20Powershell%20cmdlets%20for%20the%20new%20metric%20alerts%3F%20Or%20is%20there%20maybe%20any%20reference%20of%20a%20related%20issue%20%2F%20ticket%20which%20we%20could%20subscribe%20to%3F%3CBR%20%2F%3E%3CBR%20%2F%3EIt%20seems%20kind%20of%20inconvenient%20situation%20when%20we're%20getting%20notifications%20in%20portal%20about%20classic%20alerts%20being%20retired%20soon%20and%20suggestion%20to%20use%20new%20ones.%20We%20would%20be%20happy%20to%20do%20that.%20At%20the%20same%20time%20we%20don't%20have%20an%20alternative%20for%20Powershell%20cmdlets%20which%20we%20are%20using%20for%20classic%20alerts%20at%20the%20moment.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-298297%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20New%20V2%20alert%20from%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-298297%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20the%20response%2C%20I%20am%20working%20with%20ARM%20now.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-298219%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20New%20V2%20alert%20from%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-298219%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Gourav%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20cmdlet%20you%20are%20using%20is%20for%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmonitoring-and-diagnostics%2Falert-metric-classic%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eclassic%20metric%20alerts%20in%20Azure%20Monitor%3C%2FA%3E.%20Classic%20metric%20alerts%20didn't%20support%20action%20groups%20and%20used%20a%20custom%20notification%20mechanism.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EWe%20don't%20yet%20have%20PowerShell%20cmdlets%20for%20newer%20metric%20alerts.%20We%20are%20actively%20working%20on%20those%20and%20will%20provide%20an%20announcement%20once%20they%20are%20ready.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20meanwhile%2C%20if%20you%20are%20trying%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmonitoring-and-diagnostics%2Falert-metric%3Ftoc%3D%2Fazure%2Fazure-monitor%2Ftoc.json%23with-azure-cli%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ecreate%20metric%20alerts%3C%2FA%3E%2C%20you%20can%20use%20Azure%20CLI%20to%20automate%20creating%20alerts.%20You%20can%20also%20create%20action%20groups%20through%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcli%2Fazure%2Fmonitor%2Faction-group%3Fview%3Dazure-cli-latest%23az-monitor-action-group-create%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECLI%20%3C%2FA%3Eas%20well.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20trying%20to%20create%20log%20alerts%20based%20on%20Kusto%20queries%2C%20today%20the%20only%20way%20to%20automate%20it%20is%20through%20ARM%20templates.%20The%20PS%20cmdlets%20and%20CLI%20are%20being%20worked%26nbsp%3B%20on%2C%20but%20are%20not%20available%20yet.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERegards%2C%3CBR%20%2F%3ESnehith%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-298003%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20New%20V2%20alert%20from%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-298003%22%20slang%3D%22en-US%22%3EThanks%20Noa%2C%20Please%20keep%20me%20posted%20about%20progress.%3CBR%20%2F%3E%3CBR%20%2F%3Ecould%20you%20please%20let%20me%20know%20if%20we%20have%20any%20particular%20forum%20for%20Azure%20Monitors.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-297965%22%20slang%3D%22en-US%22%3ERE%3A%20New%20V2%20alert%20from%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-297965%22%20slang%3D%22en-US%22%3EHi%2C%20This%20community%20space%20is%20mainly%20about%20Log%20Analytics%20and%20not%20alerts%2C%20but%20I've%20sent%20your%20message%20to%20the%20alerting%20team.%20They%20will%20reply%20here%20or%20send%20me%20their%20answer%20and%20I'll%20post%20it.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-487076%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20New%20V2%20alert%20from%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-487076%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F103580%22%20target%3D%22_blank%22%3E%40Snehith%20Muvva%3C%2FA%3E%26nbsp%3B%20Thanks%20for%20the%20update%2C%20Good%20to%20hear%20this%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

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.

9 Replies
Highlighted
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.
Highlighted
Thanks Noa, Please keep me posted about progress.

could you please let me know if we have any particular forum for Azure Monitors.
Highlighted
Solution

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

 

 

Highlighted

Thanks for the response, I am working with ARM now.

Highlighted
Hi Snehith,

Do you have any EDT on the Powershell cmdlets for the new metric alerts? Or is there maybe any reference of a related issue / ticket which we could subscribe to?

It seems kind of inconvenient situation when we're getting notifications in portal about classic alerts being retired soon and suggestion to use new ones. We would be happy to do that. At the same time we don't have an alternative for Powershell cmdlets which we are using for classic alerts at the moment.
Highlighted

Hi @sarbis

 

We expect PowerShell cmdlets for newer metric alerts to be available by end of March.

 

Please subscribe to https://azure.microsoft.com/en-us/updates/?updatetype=management or keep an eye out on What's new tab in Azure Monitor to get notified when we release this.

 

Regards,
Snehith

Highlighted

@Snehith Muvva 

Hi there!

I just checked the site you recommended and still no news about PowerShell commands to support the new V2 alerts..

But yes, on the 28th of March there was the "New tool available to migrate from classic monitoring alerts" announce.

Just waiting for this, to update my monitoring scripts.

 

Regards, Pedro.

Highlighted

@Snehith Muvva  Thanks for the update, Good to hear this