azure - 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 订阅中的一些配置?
解决方案
这似乎是在 Azure Government 中启用 microsoft.insights 的一个已知问题。通过 Visual Studio 中传统的“添加 Application Insights 遥测”按钮启用 Application Insights 的唯一方法需要一个小的手动解决方法。如果您不使用此解决方法,您将收到您描述的错误。
要缓解此问题,您必须执行以下步骤:
切换 Visual Studio 以面向 Azure 政府云。
为 AzureGraphApiVersion 创建(或者如果已经存在设置)用户环境变量,如下所示:(要创建用户环境变量,请转到控制面板 > 系统 > 高级系统设置 > 高级 > 环境变量。)
变量名:AzureGraphApiVersion 变量值:2014-04-01
根据您的项目类型,对 ASP.NET 或 ASP.NET Core 进行适当的 Application Insights SDK 端点修改。
推荐阅读
- python-3.x - Plotly dash - 动态显示 ndarray 图像
- shell - 从标准输入读取程序输出而不是使用 spawn
- dependency-injection - 某些服务无法使用库构建:NetCore.AutoRegisterDi
- javascript - Javascript:无法添加延迟和加载功能
- shell - 在ansible中执行curl命令
- python-3.x - 安装了 flask_sqlalchemy 模块,但仍然出现相同的错误 ModuleNotFoundError: No module named 'flask_sqlalchemy'
- php - 我如何使用 foreach 循环从 api 中获取 imdb_id
- node.js - response.body 返回 null 并且 response.data 在我的 react+express 应用程序中返回 undefined
- git - 如何将 Terraform 与 GIT 集成到 AWS 服务中,例如用于版本控制的 lambda
- php - 为什么 Laravel 分页显示同一页面?