针对Azure中VM的自定义指标

时间:2019-04-04 20:51:42

标签: azure active-directory azure-active-directory

我在'Microsoft.Insights / Metrics / write'上遇到授权错误

我有一个虚拟机资源和一个具有贡献者角色的服务原则。我正在尝试针对虚拟机资源发出指标。请按照此处的指南进行操作:https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-store-custom-rest-api

但是我收到此错误:

{“错误”:{“代码”:“ AuthenticationFailed”,“消息”:“ Azure AD对象'0f6a81eb-8950-43eb-989a-f715fb84e4e2'无权执行操作'Microsoft.Insights / Metrics / write'作用域'/subscriptions/ba0583bb-4130-4d7b-bfe4-0c7597857323/resourceGroups/sample-PM-LA-resourceGrp/providers/Microsoft.Compute/virtualMachines/sample-PM-virtualMachine'。"}}

这是我在做什么:

curl -X POST https://westus2.monitoring.azure.com/subscriptions/ba0583bb-4130-4d7b-bfe4-0c7597857323/resourceGroups/sample-PM-LA-resourceGrp/providers/Microsoft.Compute/virtualMachines/sample-PM-virtualMachine/metrics -H "Content-Type: application/json" -H "Authorization: Bearer <auth-code>" -d @custommetric.json

和我得到的错误:

{"error":{"code":"AuthenticationFailed","message":"The Azure AD object '0f6a81eb-8950-43eb-989a-f715fb84e4e2' does not have permissions to perform action 'Microsoft.Insights/Metrics/write' over scope '/subscriptions/ba0583bb-4130-4d7b-bfe4-0c7597857323/resourceGroups/sample-PM-LA-resourceGrp/providers/Microsoft.Compute/virtualMachines/sample-PM-virtualMachine'. "}}

有人知道为什么会这样吗?我具有必需的权限,并且服务原理也已获得权限。

1 个答案:

答案 0 :(得分:0)

我看到您提到创建的服务主体具有Contributor角色。

Microsoft Documentation特别要求服务主体具有Monitoring Metrics Publisher角色。

enter image description here

此外,我看到此GitHub thread与您的问题非常相似,即使资源的Owner角色也没有此特定权限,因此可能不是很直观。

因此,请尝试为服务主体添加Monitoring Metrics Publisher角色