未找到位置“eastus2”的注册资源提供程序和类型“storageAccounts/blobServices”的 API 版本“2018-01-01”

问题描述 投票:0回答:1

我尝试了 Java SDK 和 API,并在尝试为 eastus2 上的容器创建警报规则时出现以下错误。我无法弄清楚“API 版本‘2018-01-01’”来自哪里,在 API 调用中,我使用的是不同的 API 版本 (2018-03-01)。 我认为有些东西正在后台执行此 API 调用(可能与容器有关,因为它的区域是 eastus2,我真的不知道)。如果有人提供帮助,我将非常感激。

{

"code": "ResourceNotFound",

"message": "No registered resource provider found for location 'eastus2' and API version '2018-01-01' for type 'storageAccounts/blobServices'. The supported api-versions are '2023-05-01, 2023-04-01, 2023-01-01, 2022-09-01, 2022-05-01, 2021-09-01, 2021-08-01, 2021-06-01, 2021-05-01, 2021-04-01, 2021-02-01, 2021-01-01, 2020-08-01-preview, 2019-06-01, 2019-04-01, 2018-11-01, 2018-07-01, 2018-03-01-preview, 2018-02-01, 2017-10-01, 2017-06-01, 2016-12-01, 2016-05-01'. The supported locations are 'eastus, eastus2, westus, westeurope, eastasia, southeastasia, japaneast, japanwest, northcentralus, southcentralus, centralus, northeurope, brazilsouth, australiaeast, australiasoutheast, southindia, centralindia, westindia, canadaeast, canadacentral, westus2, westcentralus, uksouth, ukwest, koreacentral, koreasouth, francecentral, australiacentral, southafricanorth, uaenorth, switzerlandnorth, germanywestcentral, norwayeast, westus3, jioindiawest, swedencentral, qatarcentral, polandcentral, italynorth, israelcentral'. Activity ID: c379a2e1-9633-48b7-9b5a-4c9d7199a8dd."

}

我尝试了 Java SDK 和 API,都出现了与上述相同的错误。我希望通过其中任何一个来创建警报。

请参阅下面的代码块:

Response orUpdateWithResponse
= azureResourceManager.diagnosticSettings()
.manager()
.serviceClient()
.getMetricAlerts()
.createOrUpdateWithResponse(storageResourceGroup, dto.getName(),
new MetricAlertResourceInner().withLocation(region)
.withDescription(dto.getDescription())
.withSeverity(3)
.withEnabled(true)
.withScopes(List.of("/subscriptions/" + subscriptionId + "/resourceGroups/"
+ storageResourceGroup + "/providers/Microsoft"
+ ".Storage/storageAccounts/" + accountName
+ "/blobServices/default/containers" + dto.getMetricOf()))
.withEvaluationFrequency(Duration.parse(dto.getEvaluationFrequency()))
.withWindowSize(Duration.parse(dto.getWindowSize()))
.withCriteria(new MetricAlertSingleResourceMultipleMetricCriteria().withAllOf(
List.of(new MetricCriteria().withName(dto.getName())
.withMetricName(dto.getMetricName())
.withTimeAggregation(
AggregationTypeEnum.fromString(dto.getTimeAggregation()))
.withOperator(operator)
.withThreshold(dto.getAlarmConditionThreshold()))))
.withActions(
azureActionsService.handleActions(subscriptionId, storageResourceGroup,
dto.getTopicName(), region, dto.getSendTo(), azureCredentials)),
Context.NONE);

java azure sdk
1个回答
0
投票

您收到错误:

"code": "ResourceNotFound",

因为你的范围值不正确。

  • 如果您尝试在范围级别创建警报到
    Storage account
    ,您的范围值应该是:
"/subscriptions/"+subscriptionId+"/resourceGroups/"+resourceGroupName+"/providers/Microsoft.Storage/storageAccounts/alertcreation
  • 如果您尝试在范围级别创建警报到
    Container(Blob)
    ,您的范围值应该是:
"/subscriptions/"+subscriptionId+"/resourceGroups/"+resourceGroupName+"/providers/Microsoft.Storage/storageAccounts/alertcreation/blobservices/default"

这对我有用:

package com.example;

import com.azure.core.credential.TokenCredential;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.profile.AzureProfile;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.resourcemanager.monitor.fluent.models.MetricAlertResourceInner;
import com.azure.resourcemanager.monitor.models.AggregationTypeEnum;
import com.azure.resourcemanager.monitor.models.MetricAlertSingleResourceMultipleMetricCriteria;
import com.azure.resourcemanager.monitor.models.MetricCriteria;
import com.azure.resourcemanager.monitor.models.Operator;
import java.util.*;
import java.time.*;

public class App {
    public static void main(String[] args) {
        String subscriptionId = "xxxxxxxxxxxxxxxxx";

        String resourceGroupName = "xxxxxxxxxxxxx";

        String tenantId = "xxxxxxxxxxxxxxxxxxxxxx";

        TokenCredential credential= new DefaultAzureCredentialBuilder()
            .build();

        AzureProfile profile = new AzureProfile(tenantId, subscriptionId, AzureEnvironment.AZURE);

        AzureResourceManager resourcemanager = AzureResourceManager
            .configure()
            .authenticate(credential, profile)
            .withDefaultSubscription();

        resourcemanager.diagnosticSettings()
            .manager()
            .serviceClient()
            .getMetricAlerts()
            .createOrUpdateWithResponse(resourceGroupName, "testrule_by_java", 
                new MetricAlertResourceInner().withLocation("global")
                    .withDescription("")
                    .withSeverity(3)
                    .withEnabled(true)
                    .withScopes(Arrays.asList("/subscriptions/"+subscriptionId+"/resourceGroups/"+resourceGroupName+"/providers/Microsoft.Storage/storageAccounts/alertcreation/blobservices/default"))
                    .withEvaluationFrequency(Duration.parse("PT1M"))
                    .withWindowSize(Duration.parse("PT1H"))
                    .withCriteria(new MetricAlertSingleResourceMultipleMetricCriteria().withAllOf(Arrays.asList(
                        new MetricCriteria()
                            .withName("Blob Capacity")
                            .withMetricName("BlobCapacity")
                            .withTimeAggregation(AggregationTypeEnum.AVERAGE)
                            .withOperator(Operator.GREATER_THAN)
                            .withThreshold(3435343))))
                .withAutoMitigate(true), com.azure.core.util.Context.NONE);
        


        System.out.println("Alert created successfully.");
    }
}

OUTPUT

© www.soinside.com 2019 - 2024. All rights reserved.