azure 无法使用Add-AzMetricAlertRuleV 2创建MetricAlert

30byixjq  于 10个月前  发布在  其他
关注(0)|答案(1)|浏览(122)

我正在尝试使用以下脚本创建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



不承认新阿兹卡班集团。
我有AZ.Monitor 4.5版本,AZ模块版本10.0.0和Windows PS版本5.1在阅读更多的博客,很明显,新的Aztagger组是不可用的AZ.Monitor 4.5,只有到版本3.1.0。我试图强制安装3.1.0使用

Install-Module -Name Az.Monitor -RequiredVersion 3.0.1 -Force


但它也没有安装3.0.1。

v9tzhpje

v9tzhpje1#

首先,使用以下命令检查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





或者,您也可以在Azure bash中使用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


相关问题