Create azure metric alert PowerShell

Copper Contributor

Hi, I have following situation.

I have  several VMs.

I would like to activate Metric alert and some log alert. I have done it manually and it works ok…

I have to do this  50 times, so I do not  want to do it manual…

I have following issue :

###

# Import-Module -Name Az.Resources

$VMScopID = $null

$VMScopID = (Get-AzVM -Name "VMAz1001").id

$actionGroup = $null

$actionGroup = Get-AzActionGroup -ResourceGroupName $RGwest -Name "freshservice  integration"

$newActionGroup = $null

$newActionGroup = New-AzActivityLogAlertActionGroupObject -Id $actionGroup.Id -WebhookProperty @{'tag1'='Teg10';'Teg2'=Teg20;'Vmname'='VMAz1001';'metricName'='Network In Total';'Tag4'='Tag40'}

# | ConvertTo-Json

$Criteria = $null

$Criteria = New-AzMetricAlertRuleV2Criteria -MetricName "Network In Total" -MetricNameSpace "Microsoft.Compute/virtualMachines" -TimeAggregation Total -Operator GreaterThan -Threshold 4000000000

Add-AzMetricAlertRuleV2 -Name "Network In Total - VMAz1001" -Description "Network In Total - VMAz1001" -ResourceGroupName $RGwest -WindowSize 00:30:00 -Frequency 00:30:00 -Condition $Criteria -ActionGroup $newActionGroup -Severity 2 -TargetResourceScope $VMScopID

 

Error that I get is following :

Add-AzMetricAlertRuleV2: Cannot bind parameter 'ActionGroup'. Cannot convert the "{

  "actionGroupId": "/subscriptions/A****

    }

}" value of type "Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.ActionGroup" to type "Microsoft.Azure.Management.Monitor.Management.Models.ActivityLogAlertActionGroup".

 

I also try without Tags.

I’m sort of stuck…

 

I have also try command :

New-AzActionGroup: The term 'New-AzActionGroup' is not recognized as a name of a cmdlet, function, script file, or executable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

 

Action Group is webhook.

 

Az Module is version 10.3.0

Az.Monitor is version  4.6.0

 

 

Second question is how, can I set Tag on Alert rule. Add-AzMetricAlertRuleV2 has no option setting tags

3 Replies

@Kidd_Ip 

Dont know..  script that i use i published...

I have following issue

Mali_Stane_0-1695640030172.png

 

does anyone hev a solution
Error that I get is following :

Add-AzMetricAlertRuleV2: Cannot bind parameter 'ActionGroup'. Cannot convert the "{

"actionGroupId": "/subscriptions/A****

}

}" value of type "Microsoft.Azure.PowerShell.Cmdlets.Monitor.ActivityLogAlert.Models.Api20201001.ActionGroup" to type "Microsoft.Azure.Management.Monitor.Management.Models.ActivityLogAlertActionGroup".