question

MDSaif-8182 avatar image
0 Votes"
MDSaif-8182 asked stan commented

How do I retrieve azure monitor metric alerts through Metric Alert - Get API?

I am using the below mentioned API to get the metric alerts (under Azure Monitor) that I created through Azure Portal.

"GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}?api-version=2018-03-01"

In the azure monitor section, under Alerts I can see there are 4 alerts, but I am not able to fetch their information through the API. It is giving me this error:

{
"error": {
"code": "AuthorizationFailed"
"message": "The client {client id} with object id {object id} does not have authorization to perform action 'Microsoft.Insights/metricAlerts/read' over scope '/subscriptions/{SubscriptionID}/resourceGroups/{Resource Group name}/providers/Microsoft.Insights/metricAlerts/{rule name}' or the scope is invalid. If access was recently granted, please refresh your credentials."
}
}


Also can you please let me know if there is a latency in getting the metric alert data through the API?

azure-monitor
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

stan avatar image
0 Votes"
stan answered stan commented

Hi,
Seems you have authorization problem. Are you sure that the account you have logged to execute that get operation has read permissions for the scope?

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

Now I have Monitor reader access but I am still getting the same error as above.

Also when I am using this API (GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Insights/metricAlerts?api-version=2018-03-01) to get the metric alert list by subscription, I am getting blank list as output.

I have created metric alerts and it is showing up on the azure monitor portal for the same scope.

0 Votes 0 ·

Hi,
I am not sure what could be the error for you. It is either how you authenticate, still not having enough permissions or not calling the API correctly. Here is results from the API when I use it via armclient tool and having Owner permissions on subscription level.

0 Votes 0 ·

PS C:\Users\stas> ARMClient.exe get /subscriptions/<sub id>/providers/Microsoft.Insights/metricAlerts?api-version=2018-03-01
{
"value": [
{
"id": "/subscriptions/<sub id>/resourceGroups/<resource group name>/providers/microsoft.insights/metricAlerts/test1",
"name": "test1",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"tags": {},
"properties": {
"description": "",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/<sub id>/resourceGroups/<resource group name>/providers/Microsoft.Storage/storageAccounts/<storage name>"
],
"evaluationFrequency": "PT1M",

0 Votes 0 ·