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