diff --git a/README.md b/README.md index fce7818..65e176a 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Application Options: -v, --verbose verbose mode [$VERBOSE] --log.json Switch log output to json format [$LOG_JSON] --azure-environment= Azure environment name (default: AZUREPUBLICCLOUD) [$AZURE_ENVIRONMENT] + --azure-ad-resource-url= Specifies the AAD resource ID to use. If not set, it defaults to ResourceManagerEndpoint for operations with Azure Resource Manager [$AZURE_AD_RESOURCE] --concurrency.subscription= Concurrent subscription fetches (default: 5) [$CONCURRENCY_SUBSCRIPTION] --concurrency.subscription.resource= Concurrent requests per resource (inside subscription requests) (default: 10) [$CONCURRENCY_SUBSCRIPTION_RESOURCE] diff --git a/azure_insights.go b/azure_insights.go index 9d261c9..ce93169 100644 --- a/azure_insights.go +++ b/azure_insights.go @@ -34,7 +34,7 @@ func (m *AzureInsightMetrics) MetricsClient(subscriptionId string) *insights.Met m.clientMutex.Lock() if _, ok := m.metricsClientCache[subscriptionId]; !ok { - client := insights.NewMetricsClient(subscriptionId) + client := insights.NewMetricsClientWithBaseURI(AzureAdResourceUrl, subscriptionId) client.Authorizer = AzureAuthorizer m.metricsClientCache[subscriptionId] = &client } @@ -49,7 +49,7 @@ func (m *AzureInsightMetrics) ResourcesClient(subscriptionId string) *resources. m.clientMutex.Lock() if _, ok := m.resourceClientCache[subscriptionId]; !ok { - client := resources.NewClient(subscriptionId) + client := resources.NewClientWithBaseURI(AzureAdResourceUrl, subscriptionId) client.Authorizer = AzureAuthorizer m.resourceClientCache[subscriptionId] = &client } diff --git a/config/opts.go b/config/opts.go index 5fc467f..083d680 100644 --- a/config/opts.go +++ b/config/opts.go @@ -16,7 +16,8 @@ type ( // azure Azure struct { - Environment *string `long:"azure-environment" env:"AZURE_ENVIRONMENT" description:"Azure environment name" default:"AZUREPUBLICCLOUD"` + Environment *string `long:"azure-environment" env:"AZURE_ENVIRONMENT" description:"Azure environment name" default:"AZUREPUBLICCLOUD"` + AdResourceUrl *string `long:"azure-ad-resource-url" env:"AZURE_AD_RESOURCE" description:"Specifies the AAD resource ID to use. If not set, it defaults to ResourceManagerEndpoint for operations with Azure Resource Manager"` } // Prober settings diff --git a/main.go b/main.go index 8b47657..8ac1c19 100644 --- a/main.go +++ b/main.go @@ -43,8 +43,9 @@ var ( argparser *flags.Parser opts config.Opts - AzureEnvironment azure.Environment - AzureAuthorizer autorest.Authorizer + AzureEnvironment azure.Environment + AzureAuthorizer autorest.Authorizer + AzureAdResourceUrl string prometheusCollectTime *prometheus.SummaryVec prometheusMetricRequests *prometheus.CounterVec @@ -132,6 +133,12 @@ func initAzureConnection() { log.Panic(err) } + if opts.Azure.AdResourceUrl == nil { + AzureAdResourceUrl = AzureEnvironment.ResourceManagerEndpoint + } else { + AzureAdResourceUrl = *opts.Azure.AdResourceUrl + } + // setup azure authorizer AzureAuthorizer, err = auth.NewAuthorizerFromEnvironment() if err != nil {