joe huang
joe huang

Reputation: 59

Azure-alert: Unable to create azure alert in gov subscription

Call the api to create an alert in Gov subscription:

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);

But throws an error:

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."

enter image description here

The same code works fine for others subscriptions, did I missed some configuration in the gov subscription?

Upvotes: 1

Views: 94

Answers (1)

Marilee Turscak - MSFT
Marilee Turscak - MSFT

Reputation: 7720

This appears to be a known issue with enabling microsoft.insights in Azure Government. The only way to enable Application Insights via the traditional Add Application Insights Telemetry button in Visual Studio requires a small manual workaround. If you do not use this workaround you will get the error you described.

To mitigate the issue, you must perform these steps:

  1. Switch Visual Studio to target the Azure Government cloud.

  2. Create (or if already existing set) the User Environment variable for AzureGraphApiVersion as follows: (To create a User Environment variable go to Control Panel > System > Advanced system settings > Advanced > Environment Variables.)

    Variable name: AzureGraphApiVersion Variable value: 2014-04-01

  3. Make the appropriate Application Insights SDK endpoint modifications for either ASP.NET or ASP.NET Core depending on your project type.

Source: https://learn.microsoft.com/en-us/azure/azure-government/documentation-government-services-monitoringandmanagement

Upvotes: 1

Related Questions