Exemplo n.º 1
0
        private async Task <HealthProbeResult> ProbeSubscriptionAsync(string query, string subscription)
        {
            try
            {
                await _azureResourceGraph.QueryForResourcesAsync($"health-probe-{subscription}", query, new List <string> {
                    subscription
                });

                return(new HealthProbeResult(subscription, isSuccessful: true, "Successfully queried resources via Azure Resource Graph"));
            }
            catch (UnauthorizedException unauthorizedException)
            {
                return(HandleFailedHealthProbe(subscription, unauthorizedException, unauthorizedException.Message));
            }
            catch (QueryContainsInvalidSubscriptionException queryContainsInvalidSubscriptionException)
            {
                return(HandleFailedHealthProbe(subscription, queryContainsInvalidSubscriptionException, queryContainsInvalidSubscriptionException.Message));
            }
            catch (Exception exception)
            {
                var message = $"Unable to discover resources due to an unexpected exception: {exception.Message}";

                return(HandleFailedHealthProbe(subscription, exception, message));
            }
        }
        public async Task <List <Resource> > QueryForResourcesAsync(string queryName, string query, List <string> targetSubscriptions, int pageSize, int currentPage, bool skipCache = false)
        {
            if (skipCache == false && _memoryCache.TryGetValue(queryName, out List <Resource> cachedResources))
            {
                return(cachedResources);
            }

            var queryResult = await _azureResourceGraph.QueryForResourcesAsync(queryName, query, targetSubscriptions, pageSize, currentPage);

            AddCacheEntry(queryName, queryResult);

            return(queryResult);
        }