最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Access azure计费API

IT培训 admin 2浏览 0评论

Access azure计费API

我想创建一个仪表板,其中包含有关我的天蓝色资源成本的图形(尽可能详细)。意思是,每月的发票清单是不够的(但是如果我能做到的话,我已经很高兴了!)

无论如何,我注意到的第一件事是,如果您找到一个示例,则端点URL看起来像这样

 /${subscriptionId}/resourcegroups?api-version=2016-09-01

检查网址2016-09-01的结尾,看起来不是很新。 This中篇文章是我能找到的最好的文章,但它也使用了这些URL。此外,我无法按照所描述的步骤进行操作,首先,它使用邮递员来检索access_token(对我来说不是很有用,因为我需要自动化),其次,在中间的某个位置检索到了access_token,但从未使用过。 >

所以,我找到了一个像[azure-arm-billing][2]这样的npm程序包,可以从其中编写以下程序(主要是复制粘贴):

const msRestAzure = require('ms-rest-azure');
const BillingManagement = require('azure-arm-billing')

const clientId = process.env['CLIENT_ID'];
const secret = process.env['APPLICATION_SECRET'];
const domain = process.env['DOMAIN']; 
const subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'];

// Retrieve access_token
const app = new msRestAzure.ApplicationTokenCredentials(clientId, domain, secret);
app.getToken((err, token) => {
    console.log(token.accessToken);
});

// =======
msRestAzure
  .interactiveLogin( { domain }) // The argument here is nowhere documented
  .then(credentials => {
      console.log(credentials);
      let client = new BillingManagement(credentials, subscriptionId);
      return client.invoices.list();
  })
  .then(invoices => {
      console.log('List of invoices:');
      console.dir(invoices, { depth: null, colors: true });
  });

运行此命令会显示一个不错的access_token和发票

...
List of invoices:
[
  {
    id: '/subscriptions/../providers/Microsoft.Billing/invoices/....',
    name: '...',
    type: 'Microsoft.Billing/invoices',
    invoicePeriodStartDate: 2019-08-25T00:00:00.000Z,
    invoicePeriodEndDate: 2019-09-24T00:00:00.000Z,
    billingPeriodIds: [
      '/subscriptions/.../pr..s/Micro..ing/bill..ods/201910-1'
    ]
  },
  {
    id: '/subscriptions/9ea...3d/providers/Microsoft.Billing/invoices/201909-...',
    name: '....',
    type: 'Microsoft.Billing/invoices',
    invoicePeriodStartDate: 2019-07-25T00:00:00.000Z,
    invoicePeriodEndDate: 2019-08-24T00:00:00.000Z,
    billingPeriodIds: [
      '/subscriptions/..../providers/Microsoft.Billing/billingPeriods/201909-1...'
    ]
  }
]

尽管我有发票,但没有数字。我想索取每种资源的费用。

所以该文档似乎已经过时了,因为我想要的(看起来)不存在。我的问题是,是否有人能够像这样检索信息?我真的很想知道!

我想创建一个仪表板,其中包含有关我的天蓝色资源成本的图形(尽可能详细)。意思是,每月的发票清单还不够(但是如果我... ... >>

回答如下:

[如果您正在寻找资源成本,建议您查看Consumption API - List Usage Details。这将使您消耗所有资源。

您将需要安装Consumption API - List Usage Details软件包。

Access azure计费API

我想创建一个仪表板,其中包含有关我的天蓝色资源成本的图形(尽可能详细)。意思是,每月的发票清单是不够的(但是如果我能做到的话,我已经很高兴了!)

无论如何,我注意到的第一件事是,如果您找到一个示例,则端点URL看起来像这样

 /${subscriptionId}/resourcegroups?api-version=2016-09-01

检查网址2016-09-01的结尾,看起来不是很新。 This中篇文章是我能找到的最好的文章,但它也使用了这些URL。此外,我无法按照所描述的步骤进行操作,首先,它使用邮递员来检索access_token(对我来说不是很有用,因为我需要自动化),其次,在中间的某个位置检索到了access_token,但从未使用过。 >

所以,我找到了一个像[azure-arm-billing][2]这样的npm程序包,可以从其中编写以下程序(主要是复制粘贴):

const msRestAzure = require('ms-rest-azure');
const BillingManagement = require('azure-arm-billing')

const clientId = process.env['CLIENT_ID'];
const secret = process.env['APPLICATION_SECRET'];
const domain = process.env['DOMAIN']; 
const subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'];

// Retrieve access_token
const app = new msRestAzure.ApplicationTokenCredentials(clientId, domain, secret);
app.getToken((err, token) => {
    console.log(token.accessToken);
});

// =======
msRestAzure
  .interactiveLogin( { domain }) // The argument here is nowhere documented
  .then(credentials => {
      console.log(credentials);
      let client = new BillingManagement(credentials, subscriptionId);
      return client.invoices.list();
  })
  .then(invoices => {
      console.log('List of invoices:');
      console.dir(invoices, { depth: null, colors: true });
  });

运行此命令会显示一个不错的access_token和发票

...
List of invoices:
[
  {
    id: '/subscriptions/../providers/Microsoft.Billing/invoices/....',
    name: '...',
    type: 'Microsoft.Billing/invoices',
    invoicePeriodStartDate: 2019-08-25T00:00:00.000Z,
    invoicePeriodEndDate: 2019-09-24T00:00:00.000Z,
    billingPeriodIds: [
      '/subscriptions/.../pr..s/Micro..ing/bill..ods/201910-1'
    ]
  },
  {
    id: '/subscriptions/9ea...3d/providers/Microsoft.Billing/invoices/201909-...',
    name: '....',
    type: 'Microsoft.Billing/invoices',
    invoicePeriodStartDate: 2019-07-25T00:00:00.000Z,
    invoicePeriodEndDate: 2019-08-24T00:00:00.000Z,
    billingPeriodIds: [
      '/subscriptions/..../providers/Microsoft.Billing/billingPeriods/201909-1...'
    ]
  }
]

尽管我有发票,但没有数字。我想索取每种资源的费用。

所以该文档似乎已经过时了,因为我想要的(看起来)不存在。我的问题是,是否有人能够像这样检索信息?我真的很想知道!

我想创建一个仪表板,其中包含有关我的天蓝色资源成本的图形(尽可能详细)。意思是,每月的发票清单还不够(但是如果我... ... >>

回答如下:

[如果您正在寻找资源成本,建议您查看Consumption API - List Usage Details。这将使您消耗所有资源。

您将需要安装Consumption API - List Usage Details软件包。

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论