-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot create custom metric alert via azure cli. #9640
Comments
The command returns whatever the service does. Will pass along to the service for comment on whether this is the expected behavior or not. |
To provide additional context: I created a metric alert via azure portal, using my custom metric. When I viewed it like this: It had entry like
Observe the However, all the metrics returned by Once I created a metric (via az cli) using one of the available ones, it has shown:
So perhaps the issue is the command doesn't recognize custom namespaces, which are there? |
I have a "diff repro" showing this works with Az PS1 module, but not with az CLI. Here it is working: $resourceGroup = "my-ai-rg"
$MyAIId = "/subscriptions/mySubId/resourceGroups/my-ai-rg/providers/microsoft.insights/components/my-ai-instance"
$actionGroupName = "myActionGroupName"
# https://docs.microsoft.com/en-us/cli/azure/monitor/action-group?view=azure-cli-latest#az-monitor-action-group-create
az monitor action-group create --name $actionGroupName --resource-group $resourceGroup
<# { (...)
"groupShortName": "...",
"id": "/subscriptions/mySubId/resourceGroups/my-ai-rg/providers/microsoft.insights/actionGroups/myActionGroupName",
"name": "myActionGroupName",
"resourceGroup": "my-ai-rg",
"type": "Microsoft.Insights/ActionGroups",
} #>
# https://docs.microsoft.com/en-us/powershell/module/az.monitor/get-azactiongroup?view=azps-2.2.0
$actionGroup = Get-AzActionGroup -ResourceGroupName $resourceGroup -Name $actionGroupName
# https://docs.microsoft.com/en-us/powershell/module/az.monitor/new-azactiongroup?view=azps-2.2.0
$actionGroupId = New-AzActionGroup -ActionGroupId $actionGroup.Id
# https://docs.microsoft.com/en-us/powershell/module/az.monitor/new-azmetricalertrulev2criteria?view=azps-2.2.0
$cond = New-AzMetricAlertRuleV2Criteria `
-MetricName "MyMetric" `
-MetricNamespace "MyNamespace/Foo" `
-TimeAggregation "Maximum" `
-Operator "GreaterThan" `
-Threshold "1000"
# https://docs.microsoft.com/en-us/powershell/module/az.monitor/add-azmetricalertrulev2?view=azps-2.2.0
Add-AzMetricAlertRuleV2 `
-Name "myalert" -ResourceGroupName $resourceGroup -TargetResourceId $MyAIId `
-Description "MyDesc" -Severity 4 -Condition $cond -ActionGroup $actionGroupId `
-WindowSize 0:5 -Frequency 0:5 while this fails az monitor metrics alert create -n "myalert" -g $resourceGroup --description "mydesc" --scopes $MyAIId `
--condition "max MyNamespace/Foo.MyMetric > 500" --disabled with |
Hey @tjprescott, do you have an estimate when I can expect some response about this? I understand it might take time, just want to set my expectations accordingly. I just discovered I cannot create dynamic threshold alerts via Az PS1 module either ("not yet supported"), so now I will have to fallback to ARM templates or REST API (ungh ;( ). |
Looks like ARM template client, both PS1 and Azure CLI, suffers from the same issue, e.g.: New-AzResourceGroupDeployment -ResourceGroupName "myresgroup" -TemplateFile "alert.json" -TemplateParameterFile "parameters.json"
(...)
New-AzResourceGroupDeployment : 7:45:42 PM - Resource Microsoft.Insights/metricAlerts 'myalertname' failed with message '{
"Code": "BadRequest",
"Message": "The metric names were not found MyCustomMetric."
}' |
@snehithm for comment. @konrad-jamrozik if you know the API structure, you could also use the generic |
@tjprescott I managed to create a dynamic threshold alert based on my custom metric using the raw REST API. Thus, I have a workaround, but it is not ideal, as using the REST API directly requires creating, securing and managing a service principal. The |
@konrad-jamrozik |
@tjprescott I made it to work!
For reference, I also made it to work via This means I am unblocked. Thank you so much! This issue is still technically not addressed, though. |
@konrad-jamrozik happy you are unblocked! I will keep this issue open to track the feature request. |
I'm having the same issue right now (custom application insights metric), and I think it's sad to have a custom REST call to create this alert when all my other alerts can be created with native methods :( |
Hi @konrad-jamrozik , @pajzo, thanks for reporting this. We are looking into this. |
If this is any help here is what i found out:
But in debug mode i can see that the namespace is wrong. The Azure CLI is setting [{
"location": "global",
"properties": {
"description": "Failed jobs",
"severity": 1,
"enabled": true,
"scopes": ["/subscriptions/xxxxx/resourceGroups/xxxxx/providers/microsoft.insights/components/xxxxx"],
"evaluationFrequency": "PT1M",
"windowSize": "PT1M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [{
"name": "cond0",
"metricName": "INPAXHangfireFailed",
"metricNamespace": "applicationinsights",
"operator": "GreaterThan",
"timeAggregation": "Maximum",
"threshold": 0.0,
"dimensions": []
}]
}
}
}] |
If you pass an empty string to -DynamicThreshold it lets you create the criteria unfortunatelly when you create the alert rule it comes with static "default" threshold.
|
@snehithm Hello. Any update about this issue? |
Hi @myronfanqiu , this issue should be fixed now based on #10108. @tjprescott can you confirm? |
Creating a metric alert rule on a custom metric is supported starting version 2.0.71 (released on Aug 13, 2019) |
Note: this pertains to
https://docs.microsoft.com/en-us/cli/azure/monitor/metrics?view=azure-cli-latest#az-monitor-metrics-list-definitions
and
https://docs.microsoft.com/en-us/cli/azure/monitor/metrics/alert?view=azure-cli-latest#az-monitor-metrics-alert-create
Describe the bug
I ran
and expected to see my custom metric definitions (in custom namespaces), but didn't found any custom metrics.
To Reproduce
Log a custom metric from the source code using ApplicationIsnights. Observe you can create an alert using it it via azure portal, or view it in metrics view in AI. However, it is not listed via
list-definitions
, nor you can create an alert via Azure CLI using it, as it is not found.Expected behavior
The custom metric (and its namespace) to be listed, and accepted when creating an alert with
az monitor metrics alert create
.Environment summary
Additional context
Confirmed the custom metrics also cannot be found via
The text was updated successfully, but these errors were encountered: