From 6add84eb2597b04ffc109d7ac1edb053a93eeebc Mon Sep 17 00:00:00 2001 From: Andrew Ernst Date: Wed, 20 Feb 2019 15:16:23 -0800 Subject: [PATCH] Support Azure Sovereign Environments with endpoint_url option (#5453) --- plugins/outputs/azure_monitor/README.md | 5 +++++ .../outputs/azure_monitor/azure_monitor.go | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/plugins/outputs/azure_monitor/README.md b/plugins/outputs/azure_monitor/README.md index 28bb66af6..fbb493586 100644 --- a/plugins/outputs/azure_monitor/README.md +++ b/plugins/outputs/azure_monitor/README.md @@ -40,6 +40,11 @@ written as a dimension on each Azure Monitor metric. ## The Azure Resource ID against which metric will be logged, e.g. ## ex: resource_id = "/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/" # resource_id = "" + + ## Optionally, if in Azure US Government, China, or other sovereign + ## cloud environment, set the appropriate REST endpoint for receiving + ## metrics. (Note: region may be unused in this context) + # endpoint_url = "https://monitoring.core.usgovcloudapi.net" ``` ### Setup diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index e52d66b99..408976c53 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -31,6 +31,7 @@ type AzureMonitor struct { StringsAsDimensions bool `toml:"strings_as_dimensions"` Region string ResourceID string `toml:"resource_id"` + EndpointUrl string `toml:"endpoint_url"` url string auth autorest.Authorizer @@ -65,6 +66,7 @@ const ( vmInstanceMetadataURL = "http://169.254.169.254/metadata/instance?api-version=2017-12-01" resourceIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s" urlTemplate = "https://%s.monitoring.azure.com%s/metrics" + urlOverrideTemplate = "%s%s/metrics" maxRequestBodySize = 4000000 ) @@ -91,6 +93,11 @@ var sampleConfig = ` ## The Azure Resource ID against which metric will be logged, e.g. ## ex: resource_id = "/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/" # resource_id = "" + + ## Optionally, if in Azure US Government, China or other sovereign + ## cloud environment, set appropriate REST endpoint for receiving + ## metrics. (Note: region may be unused in this context) + # endpoint_url = "https://monitoring.core.usgovcloudapi.net" ` // Description provides a description of the plugin @@ -125,6 +132,8 @@ func (a *AzureMonitor) Connect() error { var err error var region string var resourceID string + var endpointUrl string + if a.Region == "" || a.ResourceID == "" { // Pull region and resource identifier region, resourceID, err = vmInstanceMetadata(a.client) @@ -138,13 +147,21 @@ func (a *AzureMonitor) Connect() error { if a.ResourceID != "" { resourceID = a.ResourceID } + if a.EndpointUrl != "" { + endpointUrl = a.EndpointUrl + } if resourceID == "" { return fmt.Errorf("no resource ID configured or available via VM instance metadata") } else if region == "" { return fmt.Errorf("no region configured or available via VM instance metadata") } - a.url = fmt.Sprintf(urlTemplate, region, resourceID) + + if endpointUrl == "" { + a.url = fmt.Sprintf(urlTemplate, region, resourceID) + } else { + a.url = fmt.Sprintf(urlOverrideTemplate, endpointUrl, resourceID) + } log.Printf("D! Writing to Azure Monitor URL: %s", a.url)