private async Task <List <IHealthEvent> > GetAzureSubscriptionHealthAsync(string customerId, string subscriptionId)
        {
            AuthenticationResult token;

            if (string.IsNullOrEmpty(customerId))
            {
                throw new ArgumentNullException(nameof(customerId));
            }
            if (string.IsNullOrEmpty(subscriptionId))
            {
                throw new ArgumentNullException(nameof(subscriptionId));
            }

            try
            {
                token = await TokenContext.GetAADTokenAsync(
                    $"{AppConfig.Authority}/{customerId}",
                    AppConfig.ManagementUri
                    );

                using (Insights insights = new Insights(
                           subscriptionId,
                           token.AccessToken
                           ))
                {
                    return(await insights.GetHealthEventsAsync());
                }
            }
            finally
            {
                token = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets a list of health events for the specified Azure subscription.
        /// </summary>
        /// <param name="customerId">Identifier of the customer.</param>
        /// <param name="subscriptionId">Identifier of the subscription.</param>
        /// <returns>A list of health events for the Azure subscription.</returns>
        /// <exception cref="ArgumentException">
        /// <paramref name="customerId"/> is empty or null.
        /// or
        /// <paramref name="subscriptionId"/> is empty or null.
        /// </exception>
        private async Task <List <IHealthEvent> > GetAzureSubscriptionHealthAsync(string customerId, string subscriptionId)
        {
            AuthenticationToken token;

            customerId.AssertNotEmpty(nameof(customerId));
            subscriptionId.AssertNotEmpty(nameof(subscriptionId));

            try
            {
                token = await this.Service.TokenManagement.GetAppPlusUserTokenAsync(
                    $"{this.Service.Configuration.ActiveDirectoryEndpoint}/{customerId}",
                    this.Service.Configuration.AzureResourceManagerEndpoint);

                using (Insights insights = new Insights(subscriptionId, token.Token))
                {
                    return(await insights.GetHealthEventsAsync());
                }
            }
            finally
            {
                token = null;
            }
        }