forked from Azure/azure-sdk-for-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alerts.go
654 lines (594 loc) · 29.1 KB
/
alerts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
package alertsmanagement
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
import (
"context"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/tracing"
"net/http"
)
// AlertsClient is the alertsManagement Client
type AlertsClient struct {
BaseClient
}
// NewAlertsClient creates an instance of the AlertsClient client.
func NewAlertsClient(scope string, subscriptionID string, subscriptionID1 string) AlertsClient {
return NewAlertsClientWithBaseURI(DefaultBaseURI, scope, subscriptionID, subscriptionID1)
}
// NewAlertsClientWithBaseURI creates an instance of the AlertsClient client using a custom endpoint. Use this when
// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
func NewAlertsClientWithBaseURI(baseURI string, scope string, subscriptionID string, subscriptionID1 string) AlertsClient {
return AlertsClient{NewWithBaseURI(baseURI, scope, subscriptionID, subscriptionID1)}
}
// ChangeState change the state of an alert. If scope is a deleted resource then please use scope as parent resource of
// the delete resource. For example if my alert id is
// '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/vm1/providers/Microsoft.AlertsManagement/alerts/{alertId}'
// and 'vm1' is deleted then if you want to change state of this particular alert then use parent resource of scope. So
// in this example change state call will look like this:
// '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AlertsManagement/alerts/{alertId}'.
// Parameters:
// alertID - unique ID of an alert instance.
// newState - new state of the alert.
func (client AlertsClient) ChangeState(ctx context.Context, alertID string, newState AlertState) (result Alert, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ChangeState")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
req, err := client.ChangeStatePreparer(ctx, alertID, newState)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "ChangeState", nil, "Failure preparing request")
return
}
resp, err := client.ChangeStateSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "ChangeState", resp, "Failure sending request")
return
}
result, err = client.ChangeStateResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "ChangeState", resp, "Failure responding to request")
return
}
return
}
// ChangeStatePreparer prepares the ChangeState request.
func (client AlertsClient) ChangeStatePreparer(ctx context.Context, alertID string, newState AlertState) (*http.Request, error) {
pathParameters := map[string]interface{}{
"alertId": autorest.Encode("path", alertID),
"scope": client.Scope,
}
const APIVersion = "2018-05-05"
queryParameters := map[string]interface{}{
"api-version": APIVersion,
"newState": autorest.Encode("query", newState),
}
preparer := autorest.CreatePreparer(
autorest.AsPost(),
autorest.WithBaseURL(client.BaseURI),
autorest.WithPathParameters("/{scope}/providers/Microsoft.AlertsManagement/alerts/{alertId}/changestate", pathParameters),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// ChangeStateSender sends the ChangeState request. The method will close the
// http.Response Body if it receives an error.
func (client AlertsClient) ChangeStateSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// ChangeStateResponder handles the response to the ChangeState request. The method always
// closes the http.Response Body.
func (client AlertsClient) ChangeStateResponder(resp *http.Response) (result Alert, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// GetAll list all existing alerts, where the results can be filtered on the basis of multiple parameters (e.g. time
// range). The results can then be sorted on the basis specific fields, with the default being lastModifiedDateTime.
// Parameters:
// targetResource - filter by target resource( which is full ARM ID) Default value is select all.
// targetResourceType - filter by target resource type. Default value is select all.
// targetResourceGroup - filter by target resource group name. Default value is select all.
// monitorService - filter by monitor service which generates the alert instance. Default value is select all.
// monitorCondition - filter by monitor condition which is either 'Fired' or 'Resolved'. Default value is to
// select all.
// severity - filter by severity. Default value is select all.
// alertState - filter by state of the alert instance. Default value is to select all.
// alertRule - filter by specific alert rule. Default value is to select all.
// smartGroupID - filter the alerts list by the Smart Group Id. Default value is none.
// includeContext - include context which has contextual data specific to the monitor service. Default value is
// false'
// includeEgressConfig - include egress config which would be used for displaying the content in portal.
// Default value is 'false'.
// pageCount - determines number of alerts returned per page in response. Permissible value is between 1 to
// 250. When the "includeContent" filter is selected, maximum value allowed is 25. Default value is 25.
// sortBy - sort the query results by input field, Default value is 'lastModifiedDateTime'.
// sortOrder - sort the query results order in either ascending or descending. Default value is 'desc' for
// time fields and 'asc' for others.
// selectParameter - this filter allows to selection of the fields(comma separated) which would be part of the
// essential section. This would allow to project only the required fields rather than getting entire content.
// Default is to fetch all the fields in the essentials section.
// timeRange - filter by time range by below listed values. Default value is 1 day.
// customTimeRange - filter by custom time range in the format <start-time>/<end-time> where time is in
// (ISO-8601 format)'. Permissible values is within 30 days from query time. Either timeRange or
// customTimeRange could be used but not both. Default is none.
func (client AlertsClient) GetAll(ctx context.Context, targetResource string, targetResourceType string, targetResourceGroup string, monitorService MonitorService, monitorCondition MonitorCondition, severity Severity, alertState AlertState, alertRule string, smartGroupID string, includeContext *bool, includeEgressConfig *bool, pageCount *int32, sortBy AlertsSortByFields, sortOrder string, selectParameter string, timeRange TimeRange, customTimeRange string) (result AlertsListPage, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.GetAll")
defer func() {
sc := -1
if result.al.Response.Response != nil {
sc = result.al.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
result.fn = client.getAllNextResults
req, err := client.GetAllPreparer(ctx, targetResource, targetResourceType, targetResourceGroup, monitorService, monitorCondition, severity, alertState, alertRule, smartGroupID, includeContext, includeEgressConfig, pageCount, sortBy, sortOrder, selectParameter, timeRange, customTimeRange)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetAll", nil, "Failure preparing request")
return
}
resp, err := client.GetAllSender(req)
if err != nil {
result.al.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetAll", resp, "Failure sending request")
return
}
result.al, err = client.GetAllResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetAll", resp, "Failure responding to request")
return
}
if result.al.hasNextLink() && result.al.IsEmpty() {
err = result.NextWithContext(ctx)
return
}
return
}
// GetAllPreparer prepares the GetAll request.
func (client AlertsClient) GetAllPreparer(ctx context.Context, targetResource string, targetResourceType string, targetResourceGroup string, monitorService MonitorService, monitorCondition MonitorCondition, severity Severity, alertState AlertState, alertRule string, smartGroupID string, includeContext *bool, includeEgressConfig *bool, pageCount *int32, sortBy AlertsSortByFields, sortOrder string, selectParameter string, timeRange TimeRange, customTimeRange string) (*http.Request, error) {
pathParameters := map[string]interface{}{
"scope": client.Scope,
}
const APIVersion = "2018-05-05"
queryParameters := map[string]interface{}{
"api-version": APIVersion,
}
if len(targetResource) > 0 {
queryParameters["targetResource"] = autorest.Encode("query", targetResource)
}
if len(targetResourceType) > 0 {
queryParameters["targetResourceType"] = autorest.Encode("query", targetResourceType)
}
if len(targetResourceGroup) > 0 {
queryParameters["targetResourceGroup"] = autorest.Encode("query", targetResourceGroup)
}
if len(string(monitorService)) > 0 {
queryParameters["monitorService"] = autorest.Encode("query", monitorService)
}
if len(string(monitorCondition)) > 0 {
queryParameters["monitorCondition"] = autorest.Encode("query", monitorCondition)
}
if len(string(severity)) > 0 {
queryParameters["severity"] = autorest.Encode("query", severity)
}
if len(string(alertState)) > 0 {
queryParameters["alertState"] = autorest.Encode("query", alertState)
}
if len(alertRule) > 0 {
queryParameters["alertRule"] = autorest.Encode("query", alertRule)
}
if len(smartGroupID) > 0 {
queryParameters["smartGroupId"] = autorest.Encode("query", smartGroupID)
}
if includeContext != nil {
queryParameters["includeContext"] = autorest.Encode("query", *includeContext)
}
if includeEgressConfig != nil {
queryParameters["includeEgressConfig"] = autorest.Encode("query", *includeEgressConfig)
}
if pageCount != nil {
queryParameters["pageCount"] = autorest.Encode("query", *pageCount)
}
if len(string(sortBy)) > 0 {
queryParameters["sortBy"] = autorest.Encode("query", sortBy)
}
if len(string(sortOrder)) > 0 {
queryParameters["sortOrder"] = autorest.Encode("query", sortOrder)
}
if len(selectParameter) > 0 {
queryParameters["select"] = autorest.Encode("query", selectParameter)
}
if len(string(timeRange)) > 0 {
queryParameters["timeRange"] = autorest.Encode("query", timeRange)
}
if len(customTimeRange) > 0 {
queryParameters["customTimeRange"] = autorest.Encode("query", customTimeRange)
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithBaseURL(client.BaseURI),
autorest.WithPathParameters("/{scope}/providers/Microsoft.AlertsManagement/alerts", pathParameters),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// GetAllSender sends the GetAll request. The method will close the
// http.Response Body if it receives an error.
func (client AlertsClient) GetAllSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// GetAllResponder handles the response to the GetAll request. The method always
// closes the http.Response Body.
func (client AlertsClient) GetAllResponder(resp *http.Response) (result AlertsList, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// getAllNextResults retrieves the next set of results, if any.
func (client AlertsClient) getAllNextResults(ctx context.Context, lastResults AlertsList) (result AlertsList, err error) {
req, err := lastResults.alertsListPreparer(ctx)
if err != nil {
return result, autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "getAllNextResults", nil, "Failure preparing next results request")
}
if req == nil {
return
}
resp, err := client.GetAllSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
return result, autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "getAllNextResults", resp, "Failure sending next results request")
}
result, err = client.GetAllResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "getAllNextResults", resp, "Failure responding to next results request")
}
return
}
// GetAllComplete enumerates all values, automatically crossing page boundaries as required.
func (client AlertsClient) GetAllComplete(ctx context.Context, targetResource string, targetResourceType string, targetResourceGroup string, monitorService MonitorService, monitorCondition MonitorCondition, severity Severity, alertState AlertState, alertRule string, smartGroupID string, includeContext *bool, includeEgressConfig *bool, pageCount *int32, sortBy AlertsSortByFields, sortOrder string, selectParameter string, timeRange TimeRange, customTimeRange string) (result AlertsListIterator, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.GetAll")
defer func() {
sc := -1
if result.Response().Response.Response != nil {
sc = result.page.Response().Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
result.page, err = client.GetAll(ctx, targetResource, targetResourceType, targetResourceGroup, monitorService, monitorCondition, severity, alertState, alertRule, smartGroupID, includeContext, includeEgressConfig, pageCount, sortBy, sortOrder, selectParameter, timeRange, customTimeRange)
return
}
// GetByID get information related to a specific alert. If scope is a deleted resource then please use scope as parent
// resource of the delete resource. For example if my alert id is
// '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/vm1/providers/Microsoft.AlertsManagement/alerts/{alertId}'
// and 'vm1' is deleted then if you want to get alert by id then use parent resource of scope. So in this example get
// alert by id call will look like this:
// '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AlertsManagement/alerts/{alertId}'.
// Parameters:
// alertID - unique ID of an alert instance.
func (client AlertsClient) GetByID(ctx context.Context, alertID string) (result Alert, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.GetByID")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
req, err := client.GetByIDPreparer(ctx, alertID)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetByID", nil, "Failure preparing request")
return
}
resp, err := client.GetByIDSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetByID", resp, "Failure sending request")
return
}
result, err = client.GetByIDResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetByID", resp, "Failure responding to request")
return
}
return
}
// GetByIDPreparer prepares the GetByID request.
func (client AlertsClient) GetByIDPreparer(ctx context.Context, alertID string) (*http.Request, error) {
pathParameters := map[string]interface{}{
"alertId": autorest.Encode("path", alertID),
"scope": client.Scope,
}
const APIVersion = "2018-05-05"
queryParameters := map[string]interface{}{
"api-version": APIVersion,
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithBaseURL(client.BaseURI),
autorest.WithPathParameters("/{scope}/providers/Microsoft.AlertsManagement/alerts/{alertId}", pathParameters),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// GetByIDSender sends the GetByID request. The method will close the
// http.Response Body if it receives an error.
func (client AlertsClient) GetByIDSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// GetByIDResponder handles the response to the GetByID request. The method always
// closes the http.Response Body.
func (client AlertsClient) GetByIDResponder(resp *http.Response) (result Alert, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// GetHistory get the history of an alert, which captures any monitor condition changes (Fired/Resolved), alert state
// changes (New/Acknowledged/Closed) and applied action rules for that particular alert. If scope is a deleted resource
// then please use scope as parent resource of the delete resource. For example if my alert id is
// '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/vm1/providers/Microsoft.AlertsManagement/alerts/{alertId}'
// and 'vm1' is deleted then if you want to get history of this particular alert then use parent resource of scope. So
// in this example get history call will look like this:
// '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AlertsManagement/alerts/{alertId}/history'.
// Parameters:
// alertID - unique ID of an alert instance.
func (client AlertsClient) GetHistory(ctx context.Context, alertID string) (result AlertModification, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.GetHistory")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
req, err := client.GetHistoryPreparer(ctx, alertID)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetHistory", nil, "Failure preparing request")
return
}
resp, err := client.GetHistorySender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetHistory", resp, "Failure sending request")
return
}
result, err = client.GetHistoryResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetHistory", resp, "Failure responding to request")
return
}
return
}
// GetHistoryPreparer prepares the GetHistory request.
func (client AlertsClient) GetHistoryPreparer(ctx context.Context, alertID string) (*http.Request, error) {
pathParameters := map[string]interface{}{
"alertId": autorest.Encode("path", alertID),
"scope": client.Scope,
}
const APIVersion = "2018-05-05"
queryParameters := map[string]interface{}{
"api-version": APIVersion,
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithBaseURL(client.BaseURI),
autorest.WithPathParameters("/{scope}/providers/Microsoft.AlertsManagement/alerts/{alertId}/history", pathParameters),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// GetHistorySender sends the GetHistory request. The method will close the
// http.Response Body if it receives an error.
func (client AlertsClient) GetHistorySender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// GetHistoryResponder handles the response to the GetHistory request. The method always
// closes the http.Response Body.
func (client AlertsClient) GetHistoryResponder(resp *http.Response) (result AlertModification, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// GetSummary get a summarized count of your alerts grouped by various parameters (e.g. grouping by 'Severity' returns
// the count of alerts for each severity).
// Parameters:
// groupby - this parameter allows the result set to be grouped by input fields. For example,
// groupby=severity,alertstate.
// includeSmartGroupsCount - include count of the SmartGroups as part of the summary. Default value is 'false'.
// targetResource - filter by target resource( which is full ARM ID) Default value is select all.
// targetResourceType - filter by target resource type. Default value is select all.
// targetResourceGroup - filter by target resource group name. Default value is select all.
// monitorService - filter by monitor service which generates the alert instance. Default value is select all.
// monitorCondition - filter by monitor condition which is either 'Fired' or 'Resolved'. Default value is to
// select all.
// severity - filter by severity. Default value is select all.
// alertState - filter by state of the alert instance. Default value is to select all.
// alertRule - filter by specific alert rule. Default value is to select all.
// timeRange - filter by time range by below listed values. Default value is 1 day.
// customTimeRange - filter by custom time range in the format <start-time>/<end-time> where time is in
// (ISO-8601 format)'. Permissible values is within 30 days from query time. Either timeRange or
// customTimeRange could be used but not both. Default is none.
func (client AlertsClient) GetSummary(ctx context.Context, groupby AlertsSummaryGroupByFields, includeSmartGroupsCount *bool, targetResource string, targetResourceType string, targetResourceGroup string, monitorService MonitorService, monitorCondition MonitorCondition, severity Severity, alertState AlertState, alertRule string, timeRange TimeRange, customTimeRange string) (result AlertsSummary, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.GetSummary")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
req, err := client.GetSummaryPreparer(ctx, groupby, includeSmartGroupsCount, targetResource, targetResourceType, targetResourceGroup, monitorService, monitorCondition, severity, alertState, alertRule, timeRange, customTimeRange)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetSummary", nil, "Failure preparing request")
return
}
resp, err := client.GetSummarySender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetSummary", resp, "Failure sending request")
return
}
result, err = client.GetSummaryResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "GetSummary", resp, "Failure responding to request")
return
}
return
}
// GetSummaryPreparer prepares the GetSummary request.
func (client AlertsClient) GetSummaryPreparer(ctx context.Context, groupby AlertsSummaryGroupByFields, includeSmartGroupsCount *bool, targetResource string, targetResourceType string, targetResourceGroup string, monitorService MonitorService, monitorCondition MonitorCondition, severity Severity, alertState AlertState, alertRule string, timeRange TimeRange, customTimeRange string) (*http.Request, error) {
pathParameters := map[string]interface{}{
"scope": client.Scope,
}
const APIVersion = "2018-05-05"
queryParameters := map[string]interface{}{
"api-version": APIVersion,
"groupby": autorest.Encode("query", groupby),
}
if includeSmartGroupsCount != nil {
queryParameters["includeSmartGroupsCount"] = autorest.Encode("query", *includeSmartGroupsCount)
}
if len(targetResource) > 0 {
queryParameters["targetResource"] = autorest.Encode("query", targetResource)
}
if len(targetResourceType) > 0 {
queryParameters["targetResourceType"] = autorest.Encode("query", targetResourceType)
}
if len(targetResourceGroup) > 0 {
queryParameters["targetResourceGroup"] = autorest.Encode("query", targetResourceGroup)
}
if len(string(monitorService)) > 0 {
queryParameters["monitorService"] = autorest.Encode("query", monitorService)
}
if len(string(monitorCondition)) > 0 {
queryParameters["monitorCondition"] = autorest.Encode("query", monitorCondition)
}
if len(string(severity)) > 0 {
queryParameters["severity"] = autorest.Encode("query", severity)
}
if len(string(alertState)) > 0 {
queryParameters["alertState"] = autorest.Encode("query", alertState)
}
if len(alertRule) > 0 {
queryParameters["alertRule"] = autorest.Encode("query", alertRule)
}
if len(string(timeRange)) > 0 {
queryParameters["timeRange"] = autorest.Encode("query", timeRange)
}
if len(customTimeRange) > 0 {
queryParameters["customTimeRange"] = autorest.Encode("query", customTimeRange)
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithBaseURL(client.BaseURI),
autorest.WithPathParameters("/{scope}/providers/Microsoft.AlertsManagement/alertsSummary", pathParameters),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// GetSummarySender sends the GetSummary request. The method will close the
// http.Response Body if it receives an error.
func (client AlertsClient) GetSummarySender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// GetSummaryResponder handles the response to the GetSummary request. The method always
// closes the http.Response Body.
func (client AlertsClient) GetSummaryResponder(resp *http.Response) (result AlertsSummary, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// MetaData list alerts meta data information based on value of identifier parameter.
func (client AlertsClient) MetaData(ctx context.Context) (result AlertsMetaData, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.MetaData")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
req, err := client.MetaDataPreparer(ctx)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "MetaData", nil, "Failure preparing request")
return
}
resp, err := client.MetaDataSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "MetaData", resp, "Failure sending request")
return
}
result, err = client.MetaDataResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "MetaData", resp, "Failure responding to request")
return
}
return
}
// MetaDataPreparer prepares the MetaData request.
func (client AlertsClient) MetaDataPreparer(ctx context.Context) (*http.Request, error) {
const APIVersion = "2018-05-05"
queryParameters := map[string]interface{}{
"api-version": APIVersion,
"identifier": autorest.Encode("query", "MonitorServiceList"),
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithBaseURL(client.BaseURI),
autorest.WithPath("/providers/Microsoft.AlertsManagement/alertsMetaData"),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// MetaDataSender sends the MetaData request. The method will close the
// http.Response Body if it receives an error.
func (client AlertsClient) MetaDataSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// MetaDataResponder handles the response to the MetaData request. The method always
// closes the http.Response Body.
func (client AlertsClient) MetaDataResponder(resp *http.Response) (result AlertsMetaData, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}