1 package insights
2
3
4
5
6
7
8
9 import (
10 "context"
11 "encoding/json"
12 "github.com/Azure/go-autorest/autorest"
13 "github.com/Azure/go-autorest/autorest/to"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 const fqdn = "github.com/Azure/azure-sdk-for-go/services/monitor/mgmt/2020-10-01/insights"
20
21
22 type ActionGroup struct {
23
24 ActionGroupID *string `json:"actionGroupId,omitempty"`
25
26 WebhookProperties map[string]*string `json:"webhookProperties"`
27 }
28
29
30 func (ag ActionGroup) MarshalJSON() ([]byte, error) {
31 objectMap := make(map[string]interface{})
32 if ag.ActionGroupID != nil {
33 objectMap["actionGroupId"] = ag.ActionGroupID
34 }
35 if ag.WebhookProperties != nil {
36 objectMap["webhookProperties"] = ag.WebhookProperties
37 }
38 return json.Marshal(objectMap)
39 }
40
41
42 type ActionList struct {
43
44 ActionGroups *[]ActionGroup `json:"actionGroups,omitempty"`
45 }
46
47
48 type ActivityLogAlertResource struct {
49 autorest.Response `json:"-"`
50
51 *AlertRuleProperties `json:"properties,omitempty"`
52
53 ID *string `json:"id,omitempty"`
54
55 Name *string `json:"name,omitempty"`
56
57 Type *string `json:"type,omitempty"`
58
59 Location *string `json:"location,omitempty"`
60
61 Tags map[string]*string `json:"tags"`
62 }
63
64
65 func (alar ActivityLogAlertResource) MarshalJSON() ([]byte, error) {
66 objectMap := make(map[string]interface{})
67 if alar.AlertRuleProperties != nil {
68 objectMap["properties"] = alar.AlertRuleProperties
69 }
70 if alar.Location != nil {
71 objectMap["location"] = alar.Location
72 }
73 if alar.Tags != nil {
74 objectMap["tags"] = alar.Tags
75 }
76 return json.Marshal(objectMap)
77 }
78
79
80 func (alar *ActivityLogAlertResource) UnmarshalJSON(body []byte) error {
81 var m map[string]*json.RawMessage
82 err := json.Unmarshal(body, &m)
83 if err != nil {
84 return err
85 }
86 for k, v := range m {
87 switch k {
88 case "properties":
89 if v != nil {
90 var alertRuleProperties AlertRuleProperties
91 err = json.Unmarshal(*v, &alertRuleProperties)
92 if err != nil {
93 return err
94 }
95 alar.AlertRuleProperties = &alertRuleProperties
96 }
97 case "id":
98 if v != nil {
99 var ID string
100 err = json.Unmarshal(*v, &ID)
101 if err != nil {
102 return err
103 }
104 alar.ID = &ID
105 }
106 case "name":
107 if v != nil {
108 var name string
109 err = json.Unmarshal(*v, &name)
110 if err != nil {
111 return err
112 }
113 alar.Name = &name
114 }
115 case "type":
116 if v != nil {
117 var typeVar string
118 err = json.Unmarshal(*v, &typeVar)
119 if err != nil {
120 return err
121 }
122 alar.Type = &typeVar
123 }
124 case "location":
125 if v != nil {
126 var location string
127 err = json.Unmarshal(*v, &location)
128 if err != nil {
129 return err
130 }
131 alar.Location = &location
132 }
133 case "tags":
134 if v != nil {
135 var tags map[string]*string
136 err = json.Unmarshal(*v, &tags)
137 if err != nil {
138 return err
139 }
140 alar.Tags = tags
141 }
142 }
143 }
144
145 return nil
146 }
147
148
149
150 type AlertRuleAllOfCondition struct {
151
152 AllOf *[]AlertRuleAnyOfOrLeafCondition `json:"allOf,omitempty"`
153 }
154
155
156
157
158
159
160
161
162
163
164 type AlertRuleAnyOfOrLeafCondition struct {
165
166 AnyOf *[]AlertRuleLeafCondition `json:"anyOf,omitempty"`
167
168
169 Field *string `json:"field,omitempty"`
170
171 Equals *string `json:"equals,omitempty"`
172
173 ContainsAny *[]string `json:"containsAny,omitempty"`
174 }
175
176
177
178
179 type AlertRuleLeafCondition struct {
180
181
182 Field *string `json:"field,omitempty"`
183
184 Equals *string `json:"equals,omitempty"`
185
186 ContainsAny *[]string `json:"containsAny,omitempty"`
187 }
188
189
190 type AlertRuleList struct {
191 autorest.Response `json:"-"`
192
193 Value *[]ActivityLogAlertResource `json:"value,omitempty"`
194
195 NextLink *string `json:"nextLink,omitempty"`
196 }
197
198
199 type AlertRuleListIterator struct {
200 i int
201 page AlertRuleListPage
202 }
203
204
205
206 func (iter *AlertRuleListIterator) NextWithContext(ctx context.Context) (err error) {
207 if tracing.IsEnabled() {
208 ctx = tracing.StartSpan(ctx, fqdn+"/AlertRuleListIterator.NextWithContext")
209 defer func() {
210 sc := -1
211 if iter.Response().Response.Response != nil {
212 sc = iter.Response().Response.Response.StatusCode
213 }
214 tracing.EndSpan(ctx, sc, err)
215 }()
216 }
217 iter.i++
218 if iter.i < len(iter.page.Values()) {
219 return nil
220 }
221 err = iter.page.NextWithContext(ctx)
222 if err != nil {
223 iter.i--
224 return err
225 }
226 iter.i = 0
227 return nil
228 }
229
230
231
232
233 func (iter *AlertRuleListIterator) Next() error {
234 return iter.NextWithContext(context.Background())
235 }
236
237
238 func (iter AlertRuleListIterator) NotDone() bool {
239 return iter.page.NotDone() && iter.i < len(iter.page.Values())
240 }
241
242
243 func (iter AlertRuleListIterator) Response() AlertRuleList {
244 return iter.page.Response()
245 }
246
247
248
249 func (iter AlertRuleListIterator) Value() ActivityLogAlertResource {
250 if !iter.page.NotDone() {
251 return ActivityLogAlertResource{}
252 }
253 return iter.page.Values()[iter.i]
254 }
255
256
257 func NewAlertRuleListIterator(page AlertRuleListPage) AlertRuleListIterator {
258 return AlertRuleListIterator{page: page}
259 }
260
261
262 func (arl AlertRuleList) IsEmpty() bool {
263 return arl.Value == nil || len(*arl.Value) == 0
264 }
265
266
267 func (arl AlertRuleList) hasNextLink() bool {
268 return arl.NextLink != nil && len(*arl.NextLink) != 0
269 }
270
271
272
273 func (arl AlertRuleList) alertRuleListPreparer(ctx context.Context) (*http.Request, error) {
274 if !arl.hasNextLink() {
275 return nil, nil
276 }
277 return autorest.Prepare((&http.Request{}).WithContext(ctx),
278 autorest.AsJSON(),
279 autorest.AsGet(),
280 autorest.WithBaseURL(to.String(arl.NextLink)))
281 }
282
283
284 type AlertRuleListPage struct {
285 fn func(context.Context, AlertRuleList) (AlertRuleList, error)
286 arl AlertRuleList
287 }
288
289
290
291 func (page *AlertRuleListPage) NextWithContext(ctx context.Context) (err error) {
292 if tracing.IsEnabled() {
293 ctx = tracing.StartSpan(ctx, fqdn+"/AlertRuleListPage.NextWithContext")
294 defer func() {
295 sc := -1
296 if page.Response().Response.Response != nil {
297 sc = page.Response().Response.Response.StatusCode
298 }
299 tracing.EndSpan(ctx, sc, err)
300 }()
301 }
302 for {
303 next, err := page.fn(ctx, page.arl)
304 if err != nil {
305 return err
306 }
307 page.arl = next
308 if !next.hasNextLink() || !next.IsEmpty() {
309 break
310 }
311 }
312 return nil
313 }
314
315
316
317
318 func (page *AlertRuleListPage) Next() error {
319 return page.NextWithContext(context.Background())
320 }
321
322
323 func (page AlertRuleListPage) NotDone() bool {
324 return !page.arl.IsEmpty()
325 }
326
327
328 func (page AlertRuleListPage) Response() AlertRuleList {
329 return page.arl
330 }
331
332
333 func (page AlertRuleListPage) Values() []ActivityLogAlertResource {
334 if page.arl.IsEmpty() {
335 return nil
336 }
337 return *page.arl.Value
338 }
339
340
341 func NewAlertRuleListPage(cur AlertRuleList, getNextPage func(context.Context, AlertRuleList) (AlertRuleList, error)) AlertRuleListPage {
342 return AlertRuleListPage{
343 fn: getNextPage,
344 arl: cur,
345 }
346 }
347
348
349 type AlertRulePatchObject struct {
350
351 Tags map[string]*string `json:"tags"`
352
353 *AlertRulePatchProperties `json:"properties,omitempty"`
354 }
355
356
357 func (arpo AlertRulePatchObject) MarshalJSON() ([]byte, error) {
358 objectMap := make(map[string]interface{})
359 if arpo.Tags != nil {
360 objectMap["tags"] = arpo.Tags
361 }
362 if arpo.AlertRulePatchProperties != nil {
363 objectMap["properties"] = arpo.AlertRulePatchProperties
364 }
365 return json.Marshal(objectMap)
366 }
367
368
369 func (arpo *AlertRulePatchObject) UnmarshalJSON(body []byte) error {
370 var m map[string]*json.RawMessage
371 err := json.Unmarshal(body, &m)
372 if err != nil {
373 return err
374 }
375 for k, v := range m {
376 switch k {
377 case "tags":
378 if v != nil {
379 var tags map[string]*string
380 err = json.Unmarshal(*v, &tags)
381 if err != nil {
382 return err
383 }
384 arpo.Tags = tags
385 }
386 case "properties":
387 if v != nil {
388 var alertRulePatchProperties AlertRulePatchProperties
389 err = json.Unmarshal(*v, &alertRulePatchProperties)
390 if err != nil {
391 return err
392 }
393 arpo.AlertRulePatchProperties = &alertRulePatchProperties
394 }
395 }
396 }
397
398 return nil
399 }
400
401
402 type AlertRulePatchProperties struct {
403
404 Enabled *bool `json:"enabled,omitempty"`
405 }
406
407
408 type AlertRuleProperties struct {
409
410 Scopes *[]string `json:"scopes,omitempty"`
411
412 Condition *AlertRuleAllOfCondition `json:"condition,omitempty"`
413
414 Actions *ActionList `json:"actions,omitempty"`
415
416 Enabled *bool `json:"enabled,omitempty"`
417
418 Description *string `json:"description,omitempty"`
419 }
420
421
422 type AzureResource struct {
423
424 ID *string `json:"id,omitempty"`
425
426 Name *string `json:"name,omitempty"`
427
428 Type *string `json:"type,omitempty"`
429
430 Location *string `json:"location,omitempty"`
431
432 Tags map[string]*string `json:"tags"`
433 }
434
435
436 func (ar AzureResource) MarshalJSON() ([]byte, error) {
437 objectMap := make(map[string]interface{})
438 if ar.Location != nil {
439 objectMap["location"] = ar.Location
440 }
441 if ar.Tags != nil {
442 objectMap["tags"] = ar.Tags
443 }
444 return json.Marshal(objectMap)
445 }
446
447
448 type ErrorResponse struct {
449
450 Code *string `json:"code,omitempty"`
451
452 Message *string `json:"message,omitempty"`
453 }
454
455
456 func (er ErrorResponse) MarshalJSON() ([]byte, error) {
457 objectMap := make(map[string]interface{})
458 return json.Marshal(objectMap)
459 }
460
View as plain text