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 MetricAlertsClient struct {
20 BaseClient
21 }
22
23
24 func NewMetricAlertsClient(subscriptionID string) MetricAlertsClient {
25 return NewMetricAlertsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewMetricAlertsClientWithBaseURI(baseURI string, subscriptionID string) MetricAlertsClient {
31 return MetricAlertsClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39 func (client MetricAlertsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, ruleName string, parameters MetricAlertResource) (result MetricAlertResource, err error) {
40 if tracing.IsEnabled() {
41 ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.CreateOrUpdate")
42 defer func() {
43 sc := -1
44 if result.Response.Response != nil {
45 sc = result.Response.Response.StatusCode
46 }
47 tracing.EndSpan(ctx, sc, err)
48 }()
49 }
50 if err := validation.Validate([]validation.Validation{
51 {TargetValue: parameters,
52 Constraints: []validation.Constraint{{Target: "parameters.MetricAlertProperties", Name: validation.Null, Rule: true,
53 Chain: []validation.Constraint{{Target: "parameters.MetricAlertProperties.Description", Name: validation.Null, Rule: true, Chain: nil},
54 {Target: "parameters.MetricAlertProperties.Severity", Name: validation.Null, Rule: true, Chain: nil},
55 {Target: "parameters.MetricAlertProperties.Enabled", Name: validation.Null, Rule: true, Chain: nil},
56 {Target: "parameters.MetricAlertProperties.EvaluationFrequency", Name: validation.Null, Rule: true, Chain: nil},
57 {Target: "parameters.MetricAlertProperties.WindowSize", Name: validation.Null, Rule: true, Chain: nil},
58 }}}}}); err != nil {
59 return result, validation.NewError("insights.MetricAlertsClient", "CreateOrUpdate", err.Error())
60 }
61
62 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, ruleName, parameters)
63 if err != nil {
64 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "CreateOrUpdate", nil, "Failure preparing request")
65 return
66 }
67
68 resp, err := client.CreateOrUpdateSender(req)
69 if err != nil {
70 result.Response = autorest.Response{Response: resp}
71 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "CreateOrUpdate", resp, "Failure sending request")
72 return
73 }
74
75 result, err = client.CreateOrUpdateResponder(resp)
76 if err != nil {
77 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "CreateOrUpdate", resp, "Failure responding to request")
78 return
79 }
80
81 return
82 }
83
84
85 func (client MetricAlertsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, ruleName string, parameters MetricAlertResource) (*http.Request, error) {
86 pathParameters := map[string]interface{}{
87 "resourceGroupName": autorest.Encode("path", resourceGroupName),
88 "ruleName": autorest.Encode("path", ruleName),
89 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
90 }
91
92 const APIVersion = "2018-03-01"
93 queryParameters := map[string]interface{}{
94 "api-version": APIVersion,
95 }
96
97 preparer := autorest.CreatePreparer(
98 autorest.AsContentType("application/json; charset=utf-8"),
99 autorest.AsPut(),
100 autorest.WithBaseURL(client.BaseURI),
101 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}", pathParameters),
102 autorest.WithJSON(parameters),
103 autorest.WithQueryParameters(queryParameters))
104 return preparer.Prepare((&http.Request{}).WithContext(ctx))
105 }
106
107
108
109 func (client MetricAlertsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
110 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
111 }
112
113
114
115 func (client MetricAlertsClient) CreateOrUpdateResponder(resp *http.Response) (result MetricAlertResource, err error) {
116 err = autorest.Respond(
117 resp,
118 azure.WithErrorUnlessStatusCode(http.StatusOK),
119 autorest.ByUnmarshallingJSON(&result),
120 autorest.ByClosing())
121 result.Response = autorest.Response{Response: resp}
122 return
123 }
124
125
126
127
128
129 func (client MetricAlertsClient) Delete(ctx context.Context, resourceGroupName string, ruleName string) (result autorest.Response, err error) {
130 if tracing.IsEnabled() {
131 ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.Delete")
132 defer func() {
133 sc := -1
134 if result.Response != nil {
135 sc = result.Response.StatusCode
136 }
137 tracing.EndSpan(ctx, sc, err)
138 }()
139 }
140 req, err := client.DeletePreparer(ctx, resourceGroupName, ruleName)
141 if err != nil {
142 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Delete", nil, "Failure preparing request")
143 return
144 }
145
146 resp, err := client.DeleteSender(req)
147 if err != nil {
148 result.Response = resp
149 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Delete", resp, "Failure sending request")
150 return
151 }
152
153 result, err = client.DeleteResponder(resp)
154 if err != nil {
155 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Delete", resp, "Failure responding to request")
156 return
157 }
158
159 return
160 }
161
162
163 func (client MetricAlertsClient) DeletePreparer(ctx context.Context, resourceGroupName string, ruleName string) (*http.Request, error) {
164 pathParameters := map[string]interface{}{
165 "resourceGroupName": autorest.Encode("path", resourceGroupName),
166 "ruleName": autorest.Encode("path", ruleName),
167 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
168 }
169
170 const APIVersion = "2018-03-01"
171 queryParameters := map[string]interface{}{
172 "api-version": APIVersion,
173 }
174
175 preparer := autorest.CreatePreparer(
176 autorest.AsDelete(),
177 autorest.WithBaseURL(client.BaseURI),
178 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}", pathParameters),
179 autorest.WithQueryParameters(queryParameters))
180 return preparer.Prepare((&http.Request{}).WithContext(ctx))
181 }
182
183
184
185 func (client MetricAlertsClient) DeleteSender(req *http.Request) (*http.Response, error) {
186 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
187 }
188
189
190
191 func (client MetricAlertsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
192 err = autorest.Respond(
193 resp,
194 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
195 autorest.ByClosing())
196 result.Response = resp
197 return
198 }
199
200
201
202
203
204 func (client MetricAlertsClient) Get(ctx context.Context, resourceGroupName string, ruleName string) (result MetricAlertResource, err error) {
205 if tracing.IsEnabled() {
206 ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.Get")
207 defer func() {
208 sc := -1
209 if result.Response.Response != nil {
210 sc = result.Response.Response.StatusCode
211 }
212 tracing.EndSpan(ctx, sc, err)
213 }()
214 }
215 req, err := client.GetPreparer(ctx, resourceGroupName, ruleName)
216 if err != nil {
217 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Get", nil, "Failure preparing request")
218 return
219 }
220
221 resp, err := client.GetSender(req)
222 if err != nil {
223 result.Response = autorest.Response{Response: resp}
224 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Get", resp, "Failure sending request")
225 return
226 }
227
228 result, err = client.GetResponder(resp)
229 if err != nil {
230 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Get", resp, "Failure responding to request")
231 return
232 }
233
234 return
235 }
236
237
238 func (client MetricAlertsClient) GetPreparer(ctx context.Context, resourceGroupName string, ruleName string) (*http.Request, error) {
239 pathParameters := map[string]interface{}{
240 "resourceGroupName": autorest.Encode("path", resourceGroupName),
241 "ruleName": autorest.Encode("path", ruleName),
242 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
243 }
244
245 const APIVersion = "2018-03-01"
246 queryParameters := map[string]interface{}{
247 "api-version": APIVersion,
248 }
249
250 preparer := autorest.CreatePreparer(
251 autorest.AsGet(),
252 autorest.WithBaseURL(client.BaseURI),
253 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}", pathParameters),
254 autorest.WithQueryParameters(queryParameters))
255 return preparer.Prepare((&http.Request{}).WithContext(ctx))
256 }
257
258
259
260 func (client MetricAlertsClient) GetSender(req *http.Request) (*http.Response, error) {
261 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
262 }
263
264
265
266 func (client MetricAlertsClient) GetResponder(resp *http.Response) (result MetricAlertResource, err error) {
267 err = autorest.Respond(
268 resp,
269 azure.WithErrorUnlessStatusCode(http.StatusOK),
270 autorest.ByUnmarshallingJSON(&result),
271 autorest.ByClosing())
272 result.Response = autorest.Response{Response: resp}
273 return
274 }
275
276
277
278
279 func (client MetricAlertsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result MetricAlertResourceCollection, err error) {
280 if tracing.IsEnabled() {
281 ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.ListByResourceGroup")
282 defer func() {
283 sc := -1
284 if result.Response.Response != nil {
285 sc = result.Response.Response.StatusCode
286 }
287 tracing.EndSpan(ctx, sc, err)
288 }()
289 }
290 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
291 if err != nil {
292 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListByResourceGroup", nil, "Failure preparing request")
293 return
294 }
295
296 resp, err := client.ListByResourceGroupSender(req)
297 if err != nil {
298 result.Response = autorest.Response{Response: resp}
299 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListByResourceGroup", resp, "Failure sending request")
300 return
301 }
302
303 result, err = client.ListByResourceGroupResponder(resp)
304 if err != nil {
305 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListByResourceGroup", resp, "Failure responding to request")
306 return
307 }
308
309 return
310 }
311
312
313 func (client MetricAlertsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
314 pathParameters := map[string]interface{}{
315 "resourceGroupName": autorest.Encode("path", resourceGroupName),
316 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
317 }
318
319 const APIVersion = "2018-03-01"
320 queryParameters := map[string]interface{}{
321 "api-version": APIVersion,
322 }
323
324 preparer := autorest.CreatePreparer(
325 autorest.AsGet(),
326 autorest.WithBaseURL(client.BaseURI),
327 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts", pathParameters),
328 autorest.WithQueryParameters(queryParameters))
329 return preparer.Prepare((&http.Request{}).WithContext(ctx))
330 }
331
332
333
334 func (client MetricAlertsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
335 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
336 }
337
338
339
340 func (client MetricAlertsClient) ListByResourceGroupResponder(resp *http.Response) (result MetricAlertResourceCollection, err error) {
341 err = autorest.Respond(
342 resp,
343 azure.WithErrorUnlessStatusCode(http.StatusOK),
344 autorest.ByUnmarshallingJSON(&result),
345 autorest.ByClosing())
346 result.Response = autorest.Response{Response: resp}
347 return
348 }
349
350
351 func (client MetricAlertsClient) ListBySubscription(ctx context.Context) (result MetricAlertResourceCollection, err error) {
352 if tracing.IsEnabled() {
353 ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.ListBySubscription")
354 defer func() {
355 sc := -1
356 if result.Response.Response != nil {
357 sc = result.Response.Response.StatusCode
358 }
359 tracing.EndSpan(ctx, sc, err)
360 }()
361 }
362 req, err := client.ListBySubscriptionPreparer(ctx)
363 if err != nil {
364 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListBySubscription", nil, "Failure preparing request")
365 return
366 }
367
368 resp, err := client.ListBySubscriptionSender(req)
369 if err != nil {
370 result.Response = autorest.Response{Response: resp}
371 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListBySubscription", resp, "Failure sending request")
372 return
373 }
374
375 result, err = client.ListBySubscriptionResponder(resp)
376 if err != nil {
377 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "ListBySubscription", resp, "Failure responding to request")
378 return
379 }
380
381 return
382 }
383
384
385 func (client MetricAlertsClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) {
386 pathParameters := map[string]interface{}{
387 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
388 }
389
390 const APIVersion = "2018-03-01"
391 queryParameters := map[string]interface{}{
392 "api-version": APIVersion,
393 }
394
395 preparer := autorest.CreatePreparer(
396 autorest.AsGet(),
397 autorest.WithBaseURL(client.BaseURI),
398 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Insights/metricAlerts", pathParameters),
399 autorest.WithQueryParameters(queryParameters))
400 return preparer.Prepare((&http.Request{}).WithContext(ctx))
401 }
402
403
404
405 func (client MetricAlertsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
406 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
407 }
408
409
410
411 func (client MetricAlertsClient) ListBySubscriptionResponder(resp *http.Response) (result MetricAlertResourceCollection, err error) {
412 err = autorest.Respond(
413 resp,
414 azure.WithErrorUnlessStatusCode(http.StatusOK),
415 autorest.ByUnmarshallingJSON(&result),
416 autorest.ByClosing())
417 result.Response = autorest.Response{Response: resp}
418 return
419 }
420
421
422
423
424
425
426 func (client MetricAlertsClient) Update(ctx context.Context, resourceGroupName string, ruleName string, parameters MetricAlertResourcePatch) (result MetricAlertResource, err error) {
427 if tracing.IsEnabled() {
428 ctx = tracing.StartSpan(ctx, fqdn+"/MetricAlertsClient.Update")
429 defer func() {
430 sc := -1
431 if result.Response.Response != nil {
432 sc = result.Response.Response.StatusCode
433 }
434 tracing.EndSpan(ctx, sc, err)
435 }()
436 }
437 req, err := client.UpdatePreparer(ctx, resourceGroupName, ruleName, parameters)
438 if err != nil {
439 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Update", nil, "Failure preparing request")
440 return
441 }
442
443 resp, err := client.UpdateSender(req)
444 if err != nil {
445 result.Response = autorest.Response{Response: resp}
446 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Update", resp, "Failure sending request")
447 return
448 }
449
450 result, err = client.UpdateResponder(resp)
451 if err != nil {
452 err = autorest.NewErrorWithError(err, "insights.MetricAlertsClient", "Update", resp, "Failure responding to request")
453 return
454 }
455
456 return
457 }
458
459
460 func (client MetricAlertsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, ruleName string, parameters MetricAlertResourcePatch) (*http.Request, error) {
461 pathParameters := map[string]interface{}{
462 "resourceGroupName": autorest.Encode("path", resourceGroupName),
463 "ruleName": autorest.Encode("path", ruleName),
464 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
465 }
466
467 const APIVersion = "2018-03-01"
468 queryParameters := map[string]interface{}{
469 "api-version": APIVersion,
470 }
471
472 preparer := autorest.CreatePreparer(
473 autorest.AsContentType("application/json; charset=utf-8"),
474 autorest.AsPatch(),
475 autorest.WithBaseURL(client.BaseURI),
476 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}", pathParameters),
477 autorest.WithJSON(parameters),
478 autorest.WithQueryParameters(queryParameters))
479 return preparer.Prepare((&http.Request{}).WithContext(ctx))
480 }
481
482
483
484 func (client MetricAlertsClient) UpdateSender(req *http.Request) (*http.Response, error) {
485 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
486 }
487
488
489
490 func (client MetricAlertsClient) UpdateResponder(resp *http.Response) (result MetricAlertResource, err error) {
491 err = autorest.Respond(
492 resp,
493 azure.WithErrorUnlessStatusCode(http.StatusOK),
494 autorest.ByUnmarshallingJSON(&result),
495 autorest.ByClosing())
496 result.Response = autorest.Response{Response: resp}
497 return
498 }
499
View as plain text