我正在尝试使用以下脚本创建 MetricAlert
Set-AzContext -Subscription "f0bXXXXXXX"
$action = Get-AzActionGroup -ResourceGroupName gze-actgrp-pd-rgp-001 -Name UWDevOps_PD
$actionID = New-AzActionGroup -ActionGroupId $action.id
#Get-AzMetricDefinition -ResourceId "/subscriptions/9ca95ff2-f1fd-447d-9130-9081d2ba12be/resourcegroups/gze-pdi203-pd1-rgp-001/providers/Microsoft.ContainerService/managedClusters/gze-pdi203-pd1-aks-isostr-001"
#set alert dim to pick the right options
$dim = New-AzMetricAlertRuleV2DimensionSelection -DimensionName "Name of the nodepool" -ValuesToInclude "pdi203pd101"
$severity = 1
$RGObject = "gze-pdi203-pd1-rgp-001"
$ResourceId = "/subscriptions/9caXXXXXXX/resourcegroups/gze-pdi203-pd1-rgp-001/providers/Microsoft.ContainerService/managedClusters/gze-pdi203-pd1-aks-isostr-001"
#set alert criteria and counter % Processor Time
$criteria = New-AzMetricAlertRuleV2Criteria -MetricName "node_disk_usage_percentage" -DimensionSelection $dim
-TimeAggregation average -Operator GreaterThan
-Threshold 90
Add-AzMetricAlertRuleV2 -Name "UWS-AKS203-ISOSTR-PD1-[Sev1-Error]-Cluster-DiskUtilization_Morethan90Percnt-V2-CT" -ResourceGroupName $RGObject
-WindowSize 01:00:00 -Frequency 01:00:00
-TargetResourceId $ResourceId -Condition $criteria
-ActionGroup $action.Id `
-Severity $severity
但是这里失败了
$actionID = New-AzActionGroup -ActionGroupId $action.id
这么说
New-AzActionGroup 无法识别。
我有 Az.Monitor 4.5 版、AZ 模块 10.0.0 版和 Windows PS 5.1 版 在阅读更多博客后,我们发现 New-AzActionGroup 在 Az.MOnitor 4.5 中不可用,直到版本 3.1.0 才可用。我尝试使用
强制安装3.1.0Install-Module -Name Az.Monitor -RequiredVersion 3.0.1 -Force
但是也没有安装3.0.1。
首先,使用以下命令检查
Az.Monitor
安装的模块的当前版本。
Get-InstalledModule -NAme "Az.Monitor"
无论如何,如果您想使用与现在安装的版本不同的版本运行脚本,则必须首先使用
Remove-Module
命令卸载模块,然后使用
uninstall-module
命令。
您现在可以通过使用
Install-Module -Name xxxx -Requiredversion xxxx
重新安装该模块来使用该模块的其他版本。
关于您的问题,经过解决方法后,我通过安装
Az.Resources
模块找到了替代方案。 Az.Resources
模块是所有 Azure 资源的可访问模块,包含
New-AzActionGroup
命令。
在 PowerShell 中使用以下命令安装并导入
Az.Resources
模块。
Install-Module -Name Az.Resources -Force
Import-Module -Name Az.Resources
完成后,我尝试执行以下与创建操作组相关的命令,并成功,如图所示。
$action = Get-Azactiongroup -ResourceGroupName xxxx -Name actionadd
New-AzActionGroup -ActionGroupId $action.Id
az monitor action-group create
CLI 命令来实现您的要求,而不会有任何冲突。
az monitor action-group create --action webhook MyAction https://alerts.xxxx.comxxx type=HighCPU --name jahact --resource-group xxxx