![](/img/trans.png)
[英]How can I get the cost of an Azure Resource group from the Azure api?
[英]How to get Azure Resource Health from API using ResourcesManagementClient?
我特别想获取此处描述的信息: https://docs.microsoft.com/en-us/rest/api/resourcehealth/availabilitystatuses/listbysubscriptionid
ResourcesManagementClient
是通往 go 的方式吗?
如果是这样,我如何使用它从Microsoft.ResourceHealth提供程序获取可用性状态?
关于这个问题,请参考以下步骤
创建服务主体并将 Azure RBAC 角色分配给 sp
安装 sdk
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.13.0-preview" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.30.1" />
var app = ConfidentialClientApplicationBuilder.Create(clientId)
.WithClientSecret(clientSecret)
.WithAuthority(String.Format(CultureInfo.InvariantCulture, "https://login.microsoftonline.com/{0}", tenantDomain))
.Build();
string[] scopes = new string[] { "https://management.azure.com/.default" };
var result = await app.AcquireTokenForClient(scopes)
.ExecuteAsync();
var cred = new TokenCredentials(result.AccessToken);
ResourceManagementClient resourceManagementClient = new ResourceManagementClient(cred);
resourceManagementClient.SubscriptionId = subscription;
///For example
///var resource = await resourceManagementClient.Resources.GetAsync(
/// "testdata",
/// "Microsoft.Compute",
/// "virtualMachines/testdocker" + "/providers/Microsoft.ResourceHealth",
/// "availabilityStatuses",
/// "current",
/// "2020-05-01"
/// );
///
///
///
var resource = await resourceManagementClient.Resources.GetAsync(
"<the resource group of the resource your want to>",
"<the namesapce of the resource your want to>",
"<the resource path of the resource your want to>" + "/providers/Microsoft.ResourceHealth",
"availabilityStatuses",
"current",
"2020-05-01"
);
Console.WriteLine(resource.Properties);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.