/// <summary> /// Method that queries to obtain the full price sheet. /// </summary> /// <param name="consumptionClient"></param> static void GetFullPriceSheet(ConsumptionManagementClient consumptionClient) { Console.WriteLine("Querying the Consumption API to get the Price Sheet for you!"); Console.WriteLine(""); //Get price first price sheet result and put the properties into a list PriceSheetResult priceSheetResult = consumptionClient.PriceSheet.Get(); foreach (PriceSheetProperties properties in priceSheetResult.Pricesheets) { priceSheet.Add(properties); } //Process subsequest price sheet results while (priceSheetResult.NextLink != "") { Uri nextPriceSheetLink = new Uri(priceSheetResult.NextLink); var query = HttpUtility.ParseQueryString(nextPriceSheetLink.Query); string skipToken = query.Get("$skiptoken"); priceSheetResult = consumptionClient.PriceSheet.Get(null, skipToken); foreach (PriceSheetProperties properties in priceSheetResult.Pricesheets) { priceSheet.Add(properties); } } Console.WriteLine("Obtained the price sheet! There are currently " + priceSheet.Count + " different meter rates!"); Console.WriteLine(""); }
static void Main(string[] args) { //Login with ARM using ARMClient.Authorization dll TokenCredentials creds = GetTokenCredentialsWithARMClient(); // Create the consumption client and obtain data for the configured subscription using (ConsumptionManagementClient consumptionClient = new ConsumptionManagementClient(creds)) { consumptionClient.SubscriptionId = ConfigurationManager.AppSettings["SubscriptionId"]; //Get usage details and perform some basic processing ProcessUsageDetails(consumptionClient); //Sum the cost of one of your resources based on usage detail cost info //// SumTotalCostOfAResource(); /j.a //Get the full price sheet //// GetFullPriceSheet(consumptionClient); /j.a //Create a new sample budget //// CreateTestBudget(consumptionClient); /j.a } //Console.WriteLine("Hello World! We hope you enjoy using the Azure Consumption APIs."); Console.ReadKey(); }
public ConsumptionProvider(ServiceClientCredentials credentials, string subscriptionId) { _subscriptionId = subscriptionId; _client = new ConsumptionManagementClient(credentials) { SubscriptionId = _subscriptionId }; }
protected void SetupManagementClients(MockContext context) { ResourceClient = GetResourceClient(context); ConsumptionManagementClient = GetConsumptionManagementClient(context); _helper.SetupManagementClients( ResourceClient, ConsumptionManagementClient); }
public void Connect(string subscriptionId = "62039fdb-ccaa-41fd-9766-7fa224b2268f") { var filePath = Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION"); var credentials = SdkContext.AzureCredentialsFactory.FromFile(filePath); _consumtionClient = new ConsumptionManagementClient(credentials); _consumtionClient.SubscriptionId = subscriptionId; _azure = Microsoft.Azure.Management.Fluent.Azure.Authenticate(credentials).WithDefaultSubscription(); }
/// <summary> /// Method that creates a test budget /// </summary> /// <param name="consumptionClient"></param> static void CreateTestBudget(ConsumptionManagementClient consumptionClient) { Console.WriteLine("Querying the Consumption API to create a sample budget for you!"); Console.WriteLine(""); //Create a new budget object with the calculated cost above Budget newBudget = new Budget { Amount = (decimal)sumCost, Category = "Cost", Filters = new Filters { Resources = new List <string> { usageDetails.First().InstanceId } }, TimeGrain = "Monthly", TimePeriod = new BudgetTimePeriod { StartDate = DateTime.UtcNow.AddDays(-DateTime.UtcNow.Day + 1), EndDate = DateTime.UtcNow.AddMonths(2) } /* Notifications for this budget can also be configured, uncomment the code below to add one * ,Notifications = new Dictionary<string, Notification>() * { * { * "NotificationName", new Notification * { * Enabled = true, * Threshold = (decimal)0.90, * ContactEmails = new List<string> { "*****@*****.**"}, * ContactGroups = null, * ContactRoles = null, * OperatorProperty = "GreaterThan" * } * } * } */ }; Console.WriteLine("What would you like your budget to be named? Please type your response below: "); string budgetName = Console.ReadLine(); //Create the budget consumptionClient.Budgets.CreateOrUpdate( budgetName, newBudget); Console.WriteLine(""); Console.WriteLine("New budget created named " + budgetName + "!"); Console.WriteLine(""); }
public async Task <ActionResult> GetUsage(string subscriptionId) { var accessToken = await GetAccessToken(); var token = new TokenCredentials(accessToken); var costClient = new ConsumptionManagementClient(token) { SubscriptionId = subscriptionId }; var usage = await costClient.UsageDetails.ListAsync("properties/additionalProperties"); return(Ok(usage)); }
private static async Task <IList <UsageDetail> > QueryUsageDetails(ILogger log, string subscriptionId) { // https://docs.microsoft.com/ja-jp/rest/api/consumption/ string token = await authentication.AcquireTokenAsync(log); var consumptionClient = new ConsumptionManagementClient(new TokenCredentials(token)) { SubscriptionId = subscriptionId, }; var usageDetailList = (await consumptionClient.UsageDetails.ListAsync()) .AsContinuousCollection(x => Extensions.Synchronize(() => consumptionClient.UsageDetails.ListNextAsync(x))); return(usageDetailList.ToList()); }
/// <summary> /// Method that queries and processes usage details. /// </summary> /// <param name="consumptionClient">The Consumption client.</param> static void ProcessUsageDetails(ConsumptionManagementClient consumptionClient) { //Console.WriteLine("Querying the Consumption API to get Usage Details."); //Console.WriteLine(""); //Grab the usage details for this month IPage <UsageDetail> usagePage = consumptionClient.UsageDetails.List("properties/meterDetails"); ProcessUsagePage(usagePage); //Handle subsequent pages string nextPageLink = usagePage.NextPageLink; while (nextPageLink != null) { IPage <UsageDetail> nextUsagePage = consumptionClient.UsageDetails.ListNext(nextPageLink); ProcessUsagePage(nextUsagePage); nextPageLink = nextUsagePage.NextPageLink; } //Console.WriteLine(usageDetails.Count + " usage detail records have been found! Placing them into a generic list" + // " and a dictionary by instanceid"); //Console.WriteLine(""); }