用于获取Azure监视器警报规则的Powershell命令无效

问题描述 投票:0回答:2

我创建了一个警报规则并将其与VM关联。现在尝试通过Powershell获取警报规则,但是获取null。这段代码出了什么问题?

Get-AzAlertRule -ResourceGroupName'appbldnew'

see the alert rule powershell code returning null

azure azure-application-insights monitor
2个回答
0
投票

这只是一个警告。该命令应该有效,确保警报规则存在。

enter image description here

UPDATE1:

尝试下面的命令来获得你想要的。

enter image description here

Get-AzResource -ResourceGroupName joywebapp -ResourceType microsoft.insights/metricAlerts 

enter image description here

UPDATE2:

如果您想获取详细信息,请尝试以下脚本。

$names = (Get-AzResource -ResourceGroupName joywebapp -ResourceType microsoft.insights/metricAlerts).Name
foreach($name in $names){
    Get-AzResource -ResourceGroupName joywebapp -Name $name -ResourceType microsoft.insights/metricAlerts | ConvertTo-Json
}

enter image description here


0
投票

对于cmdlet应该仍然​​执行的方式,Joy是正确的,因为您看到的只是一个警告。然而,这可能会发生,因为Powershell对新的度量警报的支持仍然在官方docs中提到的工作中。

此外,作为替代方案,如果它有帮助,您可以将Azure CLI用于list newer Metric Alerts,因为它现在支持获取属于Microsoft.Insights / metricAlerts资源类型的查询的精细结果。

例如:

az monitor metrics alert list -g <Resource group name> --output yaml

结果看起来像这样:

Az CLI get Metric Alert

您还可以选择Az CLI提供的许多output formats(json,jsonc,yaml,table,tsv)。

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.