1 package insights
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/tracing"
14 "net/http"
15 )
16
17
18 type BaselinesClient struct {
19 BaseClient
20 }
21
22
23 func NewBaselinesClient(subscriptionID string) BaselinesClient {
24 return NewBaselinesClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29 func NewBaselinesClientWithBaseURI(baseURI string, subscriptionID string) BaselinesClient {
30 return BaselinesClient{NewWithBaseURI(baseURI, subscriptionID)}
31 }
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 func (client BaselinesClient) List(ctx context.Context, resourceURI string, metricnames string, metricnamespace string, timespan string, interval *string, aggregation string, sensitivities string, filter string, resultType ResultType) (result MetricBaselinesResponse, err error) {
52 if tracing.IsEnabled() {
53 ctx = tracing.StartSpan(ctx, fqdn+"/BaselinesClient.List")
54 defer func() {
55 sc := -1
56 if result.Response.Response != nil {
57 sc = result.Response.Response.StatusCode
58 }
59 tracing.EndSpan(ctx, sc, err)
60 }()
61 }
62 req, err := client.ListPreparer(ctx, resourceURI, metricnames, metricnamespace, timespan, interval, aggregation, sensitivities, filter, resultType)
63 if err != nil {
64 err = autorest.NewErrorWithError(err, "insights.BaselinesClient", "List", nil, "Failure preparing request")
65 return
66 }
67
68 resp, err := client.ListSender(req)
69 if err != nil {
70 result.Response = autorest.Response{Response: resp}
71 err = autorest.NewErrorWithError(err, "insights.BaselinesClient", "List", resp, "Failure sending request")
72 return
73 }
74
75 result, err = client.ListResponder(resp)
76 if err != nil {
77 err = autorest.NewErrorWithError(err, "insights.BaselinesClient", "List", resp, "Failure responding to request")
78 return
79 }
80
81 return
82 }
83
84
85 func (client BaselinesClient) ListPreparer(ctx context.Context, resourceURI string, metricnames string, metricnamespace string, timespan string, interval *string, aggregation string, sensitivities string, filter string, resultType ResultType) (*http.Request, error) {
86 pathParameters := map[string]interface{}{
87 "resourceUri": resourceURI,
88 }
89
90 const APIVersion = "2019-03-01"
91 queryParameters := map[string]interface{}{
92 "api-version": APIVersion,
93 }
94 if len(metricnames) > 0 {
95 queryParameters["metricnames"] = autorest.Encode("query", metricnames)
96 }
97 if len(metricnamespace) > 0 {
98 queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
99 }
100 if len(timespan) > 0 {
101 queryParameters["timespan"] = autorest.Encode("query", timespan)
102 }
103 if interval != nil {
104 queryParameters["interval"] = autorest.Encode("query", *interval)
105 }
106 if len(aggregation) > 0 {
107 queryParameters["aggregation"] = autorest.Encode("query", aggregation)
108 }
109 if len(sensitivities) > 0 {
110 queryParameters["sensitivities"] = autorest.Encode("query", sensitivities)
111 }
112 if len(filter) > 0 {
113 queryParameters["$filter"] = autorest.Encode("query", filter)
114 }
115 if len(string(resultType)) > 0 {
116 queryParameters["resultType"] = autorest.Encode("query", resultType)
117 }
118
119 preparer := autorest.CreatePreparer(
120 autorest.AsGet(),
121 autorest.WithBaseURL(client.BaseURI),
122 autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/metricBaselines", pathParameters),
123 autorest.WithQueryParameters(queryParameters))
124 return preparer.Prepare((&http.Request{}).WithContext(ctx))
125 }
126
127
128
129 func (client BaselinesClient) ListSender(req *http.Request) (*http.Response, error) {
130 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
131 }
132
133
134
135 func (client BaselinesClient) ListResponder(resp *http.Response) (result MetricBaselinesResponse, err error) {
136 err = autorest.Respond(
137 resp,
138 azure.WithErrorUnlessStatusCode(http.StatusOK),
139 autorest.ByUnmarshallingJSON(&result),
140 autorest.ByClosing())
141 result.Response = autorest.Response{Response: resp}
142 return
143 }
144
View as plain text