2019-02-09 17:23:12 -06:00
|
|
|
package azuremonitor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2019-02-11 06:27:08 -06:00
|
|
|
// urlBuilder builds the URL for calling the Azure Monitor API
|
|
|
|
type urlBuilder struct {
|
2019-05-21 05:28:30 -05:00
|
|
|
DefaultSubscription string
|
|
|
|
Subscription string
|
|
|
|
ResourceGroup string
|
|
|
|
MetricDefinition string
|
|
|
|
ResourceName string
|
2019-02-09 17:23:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build checks the metric definition property to see which form of the url
|
|
|
|
// should be returned
|
2019-02-11 06:27:08 -06:00
|
|
|
func (ub *urlBuilder) Build() string {
|
2019-05-21 05:28:30 -05:00
|
|
|
subscription := ub.Subscription
|
|
|
|
|
|
|
|
if ub.Subscription == "" {
|
|
|
|
subscription = ub.DefaultSubscription
|
|
|
|
}
|
|
|
|
|
2021-06-21 07:05:13 -05:00
|
|
|
metricDefinitionArray := strings.Split(ub.MetricDefinition, "/")
|
|
|
|
resourceNameArray := strings.Split(ub.ResourceName, "/")
|
|
|
|
provider := metricDefinitionArray[0]
|
|
|
|
metricDefinitionArray = metricDefinitionArray[1:]
|
|
|
|
|
|
|
|
urlArray := []string{subscription, "resourceGroups", ub.ResourceGroup, "providers", provider}
|
|
|
|
|
|
|
|
for i := range metricDefinitionArray {
|
|
|
|
urlArray = append(urlArray, metricDefinitionArray[i])
|
|
|
|
urlArray = append(urlArray, resourceNameArray[i])
|
2019-02-09 17:23:12 -06:00
|
|
|
}
|
|
|
|
|
2021-06-21 07:05:13 -05:00
|
|
|
return fmt.Sprintf("%s/providers/microsoft.insights/metrics", strings.Join(urlArray[:], "/"))
|
2019-02-09 17:23:12 -06:00
|
|
|
}
|