question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The resource type 'alerts' could not be found in the namespace 'Microsoft.CostManagement' for api version '2019-11-01'

See original GitHub issue
  • Package Name: azure-mgmt-costmanagement
  • Package Version: 3.0.0
  • Operating System: Windows 10 21H2 (OS Build 19044.2130)
  • Python Version: 3.10.8

Describe the bug Failed to call CostManagementClient().alerts.list(scope=scope)

I am playing with azure-mgmt-* packages for checking the readiness of these python packages. ConsumptionManagementClient().usage_details.list() is working for me. But it looks like I need to migrate to Cost Management APIs. https://learn.microsoft.com/en-us/azure/cost-management-billing/automate/migrate-ea-reporting-arm-apis-overview

But here are the error messages:

azure.core.exceptions.ResourceNotFoundError: (InvalidResourceType) The resource type 'alerts' could not be found in the namespace 'Microsoft.CostManagement' for api version '2019-11-01'. The supported api-versions are '2018-08-01-preview,2019-10-01,2021-10-01,2022-10-01'.
Code: InvalidResourceType
Message: The resource type 'alerts' could not be found in the namespace 'Microsoft.CostManagement' for api version '2019-11-01'. The supported api-versions are '2018-08-01-preview,2019-10-01,2021-10-01,2022-10-01'. 

To Reproduce Steps to reproduce the behavior:

  1. Create a python click project and define some commands. Not mandatory
  2. Define a mixin to handle the authentication
import os
from pathlib import Path

from azure.identity import ClientSecretCredential, CertificateCredential
from azure.mgmt.billing import BillingManagementClient
from azure.mgmt.consumption import ConsumptionManagementClient
from azure.mgmt.costmanagement import CostManagementClient
from loguru import logger

from .envs import *


class ClientMixin:

    def __init__(self, **kwargs):
        cred_kwargs = {
            'tenant_id': AAD_GLOBAL_TENANT_ID,
            'client_id': AAD_GLOBAL_CLIENT_ID,
        }
        if AAD_GLOBAL_CLIENT_SECRET:
            cred_kwargs['client_secret'] = AAD_GLOBAL_CLIENT_SECRET
            credential = ClientSecretCredential(**cred_kwargs)
        else:
            cert_path = os.path.join(
                Path(__file__).parent.parent.parent.parent, 'certs/a_cert.pfx')
            cred_kwargs['certificate_path'] = cert_path
            cred_kwargs['password'] = AAD_GLOBAL_CERT_PASSWORD
            credential = CertificateCredential(**cred_kwargs)

        super().__init__(credential=credential, subscription_id=AAD_GLOBAL_SUBSCRIPTION_ID)


class AzureGlobalBillingClient(ClientMixin, BillingManagementClient):
    pass


class AzureGlobalConsumptionClient(ClientMixin, ConsumptionManagementClient):
    pass


class AzureGlobalCostManagementClient(ClientMixin, CostManagementClient):
    pass
  1. Call the api
    with AzureGlobalCostManagementClient() as client:
        scope = f'/providers/Microsoft.Billing/billingAccounts/{AAD_GLOBAL_BILLING_ACCOUNT_ID}'
        results = client.alerts.list(scope=scope)
        click.secho(results)

Expected behavior A successful call to CostManagementClient().[whatever].list(scope=scope)

ConsumptionManagementClient().usage_details.list(scope=scope) is working.

    with AzureGlobalConsumptionClient() as client:
        # for billing account id, go to Azure Portal, Search Cost Management + Billing, click Settings > Properties
        scope = f'/providers/Microsoft.Billing/billingAccounts/{AAD_GLOBAL_BILLING_ACCOUNT_ID}'
        details = [x.as_dict() for x in list(client.usage_details.list(scope=scope))]
        df = pd.DataFrame.from_records(details)
        click.secho(df.tail())
D:\repos\[a python project]\src (main -> origin) 
(env) $ python main.py azure get
                                                    id  ... cost_allocation_rule_name
351  /providers/Microsoft.Billing/billingAccounts/5...  ...
352  /providers/Microsoft.Billing/billingAccounts/5...  ...
353  /providers/Microsoft.Billing/billingAccounts/5...  ...
354  /providers/Microsoft.Billing/billingAccounts/5...  ...
355  /providers/Microsoft.Billing/billingAccounts/5...  ...

[5 rows x 76 columns]

Screenshots not needed

Additional context Will the API version not be hardcoded in future version? Just like the change in this pull request? https://github.com/Azure/azure-sdk-for-python/pull/23167

Exceptions

  File "D:\repos\[A python project]\src\commands\clouds\azure.py", line 49, in get
    results = client.alerts.list(scope=scope)
  File "D:\repos\[A python project]\env\lib\site-packages\azure\mgmt\costmanagement\operations\_alerts_operations.py", line 105, in list
    map_error(status_code=response.status_code, response=response, error_map=error_map)
  File "D:\repos\[A python project]\env\lib\site-packages\azure\core\exceptions.py", line 107, in map_error      
    raise error
azure.core.exceptions.ResourceNotFoundError: (InvalidResourceType) The resource type 'alerts' could not be found in the namespace 'Microsoft.CostManagement' for api version '2019-11-01'. The supported api-versions are '2018-08-01-preview,2019-10-01,2021-10-01,2022-10-01'.
Code: InvalidResourceType
Message: The resource type 'alerts' could not be found in the namespace 'Microsoft.CostManagement' for api version '2019-11-01'. The supported api-versions are '2018-08-01-preview,2019-10-01,2021-10-01,2022-10-01'. 

Line 81 - 83 in [A python project]\env\Lib\site-packages\azure\mgmt\costmanagement\operations_alerts_operations.py

error_map.update(kwargs.pop('error_map', {}))
api_version = "2019-11-01"
accept = "application/json"

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
guhuajuncommented, Nov 9, 2022

Hello @Wzb123456789,

I can confirm the 4.0.0b1 package is working, thanks for updating the package. Let me keep on playing with the azure-mgmt-costmanagement package.

D:\repos\[a python project]\src (main -> origin) 
(env) $ pip list | grep azure-mgmt-costmanagement
azure-mgmt-costmanagement  4.0.0b1

D:\repos\[a python project]\src (main -> origin) 
(env) $ python main.py azure cost get
{'additional_properties': {}, 'value': [], 'next_link': None}
1reaction
Wzb123456789commented, Nov 9, 2022

Hi @guhuajun

We have updated the version about azure-mgmt-costmanagement, please update the package version to 4.0.0b1, and try to run the code again. https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/costmanagement/azure-mgmt-costmanagement/azure/mgmt/costmanagement/operations/_alerts_operations.py#L173-L242

Read more comments on GitHub >

github_iconTop Results From Across the Web

The resource type 'Query' could not be found in the ... - GitHub
The resource type 'Query' could not be found in the namespace 'Microsoft.CostManagement' for api version '2020-06-01' #16102.
Read more >
The resource type could not be found in the ... - MSDN
The resource type could not be found in the namespace 'Microsoft.WindowsESU' for api version '2019-09-16-preview' RRS feed.
Read more >
azure - "The resource type 'locks' could not be found in the ...
"The resource type 'locks' could not be found in the namespace 'Microsoft.Authorization' for api version '2020-05-01' · azure · azure-sdk.
Read more >
Using the Azure Cost Management API to Cut Your Cloud Costs
We walk through using the Azure Cost Management API to optimize your cloud workloads on Azure, showcasing sample commands to use.
Read more >
The resource type could not be found in the namespace ...
Currently, my team trying to automate ExpressRoute provisioning and configuration using Azure Management API and we are experiencing the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found