首页 > 解决方案 > Azure 警报:无法在 gov 订阅中创建天蓝色警报

问题描述

调用 api 在 Gov 订阅中创建警报:

ret = await HttpHelper.PutAsync(
                            new Uri($"https://{app.AzureManagementBaseUri}/subscriptions/{alert["SubscriptionId"]}/" +
                                    $"resourcegroups/{alert["ResourceGroupName"]}/providers/microsoft.insights/" +
                                    $"metricAlerts/{alert["Name"]}?api-version=2017-09-01-preview"),
                            alertJson, app.AccessToken, cancellationToken).ConfigureAwait(false);

但是会抛出一个错误:

Error: 'Error while calling 'https://management.usgovcloudapi.net/subscriptions/subid/resourcegroups/ctxwsgs-appinsights/providers/microsoft.insights/alertrules/"alertName"'. StatusCode: BadRequest. Response: '{"code":"ResourceNotSupported","message":"The target resource id '/subscriptions/subid/resourceGroups/ not supported."

在此处输入图像描述

相同的代码适用于其他订阅,我是否错过了 gov 订阅中的一些配置?

标签: azureazure-active-directoryalerts

解决方案


这似乎是在 Azure Government 中启用 microsoft.insights 的一个已知问题。通过 Visual Studio 中传统的“添加 Application Insights 遥测”按钮启用 Application Insights 的唯一方法需要一个小的手动解决方法。如果您不使用此解决方法,您将收到您描述的错误。

要缓解此问题,您必须执行以下步骤:

  1. 切换 Visual Studio 以面向 Azure 政府云。

  2. 为 AzureGraphApiVersion 创建(或者如果已经存在设置)用户环境变量,如下所示:(要创建用户环境变量,请转到控制面板 > 系统 > 高级系统设置 > 高级 > 环境变量。)

    变量名:AzureGraphApiVersion 变量值:2014-04-01

  3. 根据您的项目类型,对 ASP.NET 或 ASP.NET Core 进行适当的 Application Insights SDK 端点修改。

来源:https ://docs.microsoft.com/en-us/azure/azure-government/documentation-government-services-monitoringandmanagement


推荐阅读