如何使用 PowerShell 在 Azure 中列出指标警报
How to list metric alerts in Azure with PowerShell
是否可以使用 PowerShell 在 Azure 中列出指标警报?
我只能找到:
Get-AzureRmAlertRule
但这只给我 "classic" 警报,而不是我在门户中的指标警报。
我可以使用 metricalerts/listbyresourcegroup 端点通过 API 获取所有指标警报。
有人知道是否可以通过 PowerShell 脚本获取它们吗?
您可以尝试使用带有资源类型过滤器的通用 Get-AzureRmResource
cmdlet,例如
# 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)
是否可以使用 PowerShell 在 Azure 中列出指标警报? 我只能找到:
Get-AzureRmAlertRule
但这只给我 "classic" 警报,而不是我在门户中的指标警报。
我可以使用 metricalerts/listbyresourcegroup 端点通过 API 获取所有指标警报。
有人知道是否可以通过 PowerShell 脚本获取它们吗?
您可以尝试使用带有资源类型过滤器的通用 Get-AzureRmResource
cmdlet,例如
# 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)