How to list metric alerts in Azure with PowerShell

こ雲淡風輕ζ 提交于 2019-12-13 18:18:18

问题


Is it possible to list metric alerts in Azure with PowerShell? I could only find:

Get-AzureRmAlertRule

But that only gives me the "classic" alerts and not the metric alerts I have in the portal.

I can get all the metric alerts through the API by using the metricalerts/listbyresourcegroup end-point.

Anyone that has any idea on if it is possible to get them through a PowerShell script?


回答1:


You could try using the generic Get-AzureRmResource cmdlet with a resource type filter, e.g.

# Retrieve alert rule
$rule = Get-AzureRmResource -ResourceType Microsoft.Insights/alertRules -ResourceGroupName "myResourceGroup" -Name "my-rule";

# Retrieve alerts for this rule
Get-AzureRmAlertHistory -ResourceId $rule.ResourceId -StartTime (Get-Date).AddHours(-1) -EndTime (Get-Date)


来源:https://stackoverflow.com/questions/54533976/how-to-list-metric-alerts-in-azure-with-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!