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 ActivityLogAlertsClient struct {
20 BaseClient
21 }
22
23
24 func NewActivityLogAlertsClient(subscriptionID string) ActivityLogAlertsClient {
25 return NewActivityLogAlertsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30
31 func NewActivityLogAlertsClientWithBaseURI(baseURI string, subscriptionID string) ActivityLogAlertsClient {
32 return ActivityLogAlertsClient{NewWithBaseURI(baseURI, subscriptionID)}
33 }
34
35
36
37
38
39
40 func (client ActivityLogAlertsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, activityLogAlertName string, activityLogAlert ActivityLogAlertResource) (result ActivityLogAlertResource, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/ActivityLogAlertsClient.CreateOrUpdate")
43 defer func() {
44 sc := -1
45 if result.Response.Response != nil {
46 sc = result.Response.Response.StatusCode
47 }
48 tracing.EndSpan(ctx, sc, err)
49 }()
50 }
51 if err := validation.Validate([]validation.Validation{
52 {TargetValue: activityLogAlert,
53 Constraints: []validation.Constraint{{Target: "activityLogAlert.ActivityLogAlert", Name: validation.Null, Rule: false,
54 Chain: []validation.Constraint{{Target: "activityLogAlert.ActivityLogAlert.Scopes", Name: validation.Null, Rule: true, Chain: nil},
55 {Target: "activityLogAlert.ActivityLogAlert.Condition", Name: validation.Null, Rule: true,
56 Chain: []validation.Constraint{{Target: "activityLogAlert.ActivityLogAlert.Condition.AllOf", Name: validation.Null, Rule: true, Chain: nil}}},
57 {Target: "activityLogAlert.ActivityLogAlert.Actions", Name: validation.Null, Rule: true, Chain: nil},
58 }}}}}); err != nil {
59 return result, validation.NewError("insights.ActivityLogAlertsClient", "CreateOrUpdate", err.Error())
60 }
61
62 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, activityLogAlertName, activityLogAlert)
63 if err != nil {
64 err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "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.ActivityLogAlertsClient", "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.ActivityLogAlertsClient", "CreateOrUpdate", resp, "Failure responding to request")
78 return
79 }
80
81 return
82 }
83
84
85 func (client ActivityLogAlertsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, activityLogAlertName string, activityLogAlert ActivityLogAlertResource) (*http.Request, error) {
86 pathParameters := map[string]interface{}{
87 "activityLogAlertName": autorest.Encode("path", activityLogAlertName),
88 "resourceGroupName": autorest.Encode("path", resourceGroupName),
89 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
90 }
91
92 const APIVersion = "2017-04-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/activityLogAlerts/{activityLogAlertName}", pathParameters),
102 autorest.WithJSON(activityLogAlert),
103 autorest.WithQueryParameters(queryParameters))
104 return preparer.Prepare((&http.Request{}).WithContext(ctx))
105 }
106
107
108
109 func (client ActivityLogAlertsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
110 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
111 }
112
113
114
115 func (client ActivityLogAlertsClient) CreateOrUpdateResponder(resp *http.Response) (result ActivityLogAlertResource, err error) {
116 err = autorest.Respond(
117 resp,
118 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
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 ActivityLogAlertsClient) Delete(ctx context.Context, resourceGroupName string, activityLogAlertName string) (result autorest.Response, err error) {
130 if tracing.IsEnabled() {
131 ctx = tracing.StartSpan(ctx, fqdn+"/ActivityLogAlertsClient.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, activityLogAlertName)
141 if err != nil {
142 err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "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.ActivityLogAlertsClient", "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.ActivityLogAlertsClient", "Delete", resp, "Failure responding to request")
156 return
157 }
158
159 return
160 }
161
162
163 func (client ActivityLogAlertsClient) DeletePreparer(ctx context.Context, resourceGroupName string, activityLogAlertName string) (*http.Request, error) {
164 pathParameters := map[string]interface{}{
165 "activityLogAlertName": autorest.Encode("path", activityLogAlertName),
166 "resourceGroupName": autorest.Encode("path", resourceGroupName),
167 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
168 }
169
170 const APIVersion = "2017-04-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/activityLogAlerts/{activityLogAlertName}", pathParameters),
179 autorest.WithQueryParameters(queryParameters))
180 return preparer.Prepare((&http.Request{}).WithContext(ctx))
181 }
182
183
184
185 func (client ActivityLogAlertsClient) DeleteSender(req *http.Request) (*http.Response, error) {
186 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
187 }
188
189
190
191 func (client ActivityLogAlertsClient) 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 ActivityLogAlertsClient) Get(ctx context.Context, resourceGroupName string, activityLogAlertName string) (result ActivityLogAlertResource, err error) {
205 if tracing.IsEnabled() {
206 ctx = tracing.StartSpan(ctx, fqdn+"/ActivityLogAlertsClient.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, activityLogAlertName)
216 if err != nil {
217 err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "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.ActivityLogAlertsClient", "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.ActivityLogAlertsClient", "Get", resp, "Failure responding to request")
231 return
232 }
233
234 return
235 }
236
237
238 func (client ActivityLogAlertsClient) GetPreparer(ctx context.Context, resourceGroupName string, activityLogAlertName string) (*http.Request, error) {
239 pathParameters := map[string]interface{}{
240 "activityLogAlertName": autorest.Encode("path", activityLogAlertName),
241 "resourceGroupName": autorest.Encode("path", resourceGroupName),
242 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
243 }
244
245 const APIVersion = "2017-04-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/activityLogAlerts/{activityLogAlertName}", pathParameters),
254 autorest.WithQueryParameters(queryParameters))
255 return preparer.Prepare((&http.Request{}).WithContext(ctx))
256 }
257
258
259
260 func (client ActivityLogAlertsClient) GetSender(req *http.Request) (*http.Response, error) {
261 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
262 }
263
264
265
266 func (client ActivityLogAlertsClient) GetResponder(resp *http.Response) (result ActivityLogAlertResource, 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 ActivityLogAlertsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ActivityLogAlertList, err error) {
280 if tracing.IsEnabled() {
281 ctx = tracing.StartSpan(ctx, fqdn+"/ActivityLogAlertsClient.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.ActivityLogAlertsClient", "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.ActivityLogAlertsClient", "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.ActivityLogAlertsClient", "ListByResourceGroup", resp, "Failure responding to request")
306 return
307 }
308
309 return
310 }
311
312
313 func (client ActivityLogAlertsClient) 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 = "2017-04-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/activityLogAlerts", pathParameters),
328 autorest.WithQueryParameters(queryParameters))
329 return preparer.Prepare((&http.Request{}).WithContext(ctx))
330 }
331
332
333
334 func (client ActivityLogAlertsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
335 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
336 }
337
338
339
340 func (client ActivityLogAlertsClient) ListByResourceGroupResponder(resp *http.Response) (result ActivityLogAlertList, 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 ActivityLogAlertsClient) ListBySubscriptionID(ctx context.Context) (result ActivityLogAlertList, err error) {
352 if tracing.IsEnabled() {
353 ctx = tracing.StartSpan(ctx, fqdn+"/ActivityLogAlertsClient.ListBySubscriptionID")
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.ListBySubscriptionIDPreparer(ctx)
363 if err != nil {
364 err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "ListBySubscriptionID", nil, "Failure preparing request")
365 return
366 }
367
368 resp, err := client.ListBySubscriptionIDSender(req)
369 if err != nil {
370 result.Response = autorest.Response{Response: resp}
371 err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "ListBySubscriptionID", resp, "Failure sending request")
372 return
373 }
374
375 result, err = client.ListBySubscriptionIDResponder(resp)
376 if err != nil {
377 err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "ListBySubscriptionID", resp, "Failure responding to request")
378 return
379 }
380
381 return
382 }
383
384
385 func (client ActivityLogAlertsClient) ListBySubscriptionIDPreparer(ctx context.Context) (*http.Request, error) {
386 pathParameters := map[string]interface{}{
387 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
388 }
389
390 const APIVersion = "2017-04-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/activityLogAlerts", pathParameters),
399 autorest.WithQueryParameters(queryParameters))
400 return preparer.Prepare((&http.Request{}).WithContext(ctx))
401 }
402
403
404
405 func (client ActivityLogAlertsClient) ListBySubscriptionIDSender(req *http.Request) (*http.Response, error) {
406 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
407 }
408
409
410
411 func (client ActivityLogAlertsClient) ListBySubscriptionIDResponder(resp *http.Response) (result ActivityLogAlertList, 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 ActivityLogAlertsClient) Update(ctx context.Context, resourceGroupName string, activityLogAlertName string, activityLogAlertPatch ActivityLogAlertPatchBody) (result ActivityLogAlertResource, err error) {
427 if tracing.IsEnabled() {
428 ctx = tracing.StartSpan(ctx, fqdn+"/ActivityLogAlertsClient.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, activityLogAlertName, activityLogAlertPatch)
438 if err != nil {
439 err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "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.ActivityLogAlertsClient", "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.ActivityLogAlertsClient", "Update", resp, "Failure responding to request")
453 return
454 }
455
456 return
457 }
458
459
460 func (client ActivityLogAlertsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, activityLogAlertName string, activityLogAlertPatch ActivityLogAlertPatchBody) (*http.Request, error) {
461 pathParameters := map[string]interface{}{
462 "activityLogAlertName": autorest.Encode("path", activityLogAlertName),
463 "resourceGroupName": autorest.Encode("path", resourceGroupName),
464 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
465 }
466
467 const APIVersion = "2017-04-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/activityLogAlerts/{activityLogAlertName}", pathParameters),
477 autorest.WithJSON(activityLogAlertPatch),
478 autorest.WithQueryParameters(queryParameters))
479 return preparer.Prepare((&http.Request{}).WithContext(ctx))
480 }
481
482
483
484 func (client ActivityLogAlertsClient) UpdateSender(req *http.Request) (*http.Response, error) {
485 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
486 }
487
488
489
490 func (client ActivityLogAlertsClient) UpdateResponder(resp *http.Response) (result ActivityLogAlertResource, 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