1

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 Answer 1

0

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)
Sign up to request clarification or add additional context in comments.

5 Comments

Many thanks, works like I want when I add -ResourceGroup and specify it
But then I understand is as that there is no specific function to get the "new" alerts without using this generic way?
No problem. Even though the REST API endpoint uses Microsoft.Insights/metricAlerts, the resource type shows Microsoft.Insights/alertRules after creating a metric rule using Add-AzureRmMetricAlertRule.
@KungWaz I believe you can use Get-AzureRmAlertHistory to retrieve the actual alerts for a specific rule, in a specific time window.
Ok, might be stuck anyways, I don't think I can get -DetailedOutput through Get-AzureRmResource. And the Get-AzureRmAlertHistory does not seem to yield any output, so I guess that also only covers "classic" alerts :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.