consumption
I want to extract all the resources, resource type(storage/vm/any else) and its consumed price using python. I've tried to get it through billing but didn't get results as expected.
Code: import datetime import azure.mgmt.consumption import azure.mgmt.consumption.models from azure.mgmt.consumption.models import UsageDetailPaged from azure.mgmt.consumption.consumption_management_client import ConsumptionManagementClientConfiguration,ConsumptionManagementClient from msrest.paging import Paged #All credentials are added appropriately for security reasons those are not added in this query. from azure.common.credentials import ServicePrincipalCredentials from azure.mgmt.billing import BillingManagementClient try1 = ConsumptionManagementClient(credentials,subscription_id) billing_client = BillingManagementClient(credentials, subscription_id) print(billing_client.invoices.list())
@vsnarkhede13 thanks for the feedback, looping the right team to take a look at it //cc: @nickzhums
If there is a sample of results, it will be better. Thank you
If there is a sample of results, it will be better. Thank you
{ "accountName": null, "additionalProperties": null, "billableQuantity": "None", "billingPeriodId": "", "consumedService": "Microsoft.Storage", "costCenter": null, "currency": "INR", "departmentName": null, "id": "", "instanceId": "", "instanceLocation": "IN West", "instanceName": "(instance name)", "invoiceId": null, "isEstimated": true, "meterDetails": null, "meterId": "", "name": "", "pretaxCost": "0.0034", "product": "", "subscriptionGuid": "**", "subscriptionName": "(subscription type)", "tags": null, "type": "Microsoft.Consumption/usageDetails", "usageEnd": "(end details)", "usageQuantity": "0.144", "usageStart": "(Start details)" }
The result is gotten from billing service and we need help from billing service team.
Hi @vsnarkhede13 , You can use service commerce to extract all the resources, resource type(storage/vm/any else) and its consumed price ,and please install package azure-mgmt-commerce.
The detailed code is shown below (here is the official document for your reference):
from azure.mgmt.commerce import UsageManagementClient
from datetime import date, timedelta
from azure.common.credentials import ServicePrincipalCredentials
subscription_id='<Your Subscription ID>'
credentials = ServicePrincipalCredentials(
client_id='<Your service principal App ID>',
secret='<Your service principal password>',
tenant='<Your tenant ID>'
)
commerce_client = UsageManagementClient(credentials, subscription_id)
aggregate_data = commerce_client.usage_aggregates.list(
str(date.today() - timedelta(days=1))+'T00:00:00Z',
str(date.today())+'T00:00:00Z'
)
@jongio
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ms-premp.
please try this.
https://github.com/ms-premp/AzureConsumptionSamples/blob/master/Python_sdk/usage_details_list_python_sdk_example.py
Closing this issue based on the recommendations given by Prem. Please feel free to re-open this issue if needed, after reviewing the sample shared.