Skip to content

Commit 9f5763c

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add conditional recipients to notification rule (#3375)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 54d9501 commit 9f5763c

12 files changed

+662
-21
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29565,6 +29565,8 @@ components:
2956529565
additionalProperties: false
2956629566
description: Attributes of the monitor notification rule.
2956729567
properties:
29568+
conditional_recipients:
29569+
$ref: '#/components/schemas/MonitorNotificationRuleConditionalRecipients'
2956829570
filter:
2956929571
$ref: '#/components/schemas/MonitorNotificationRuleFilter'
2957029572
name:
@@ -29573,8 +29575,36 @@ components:
2957329575
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
2957429576
required:
2957529577
- name
29578+
type: object
29579+
MonitorNotificationRuleCondition:
29580+
description: Conditions for `conditional_recipients`.
29581+
properties:
29582+
recipients:
29583+
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
29584+
scope:
29585+
$ref: '#/components/schemas/MonitorNotificationRuleScope'
29586+
required:
29587+
- scope
2957629588
- recipients
2957729589
type: object
29590+
MonitorNotificationRuleConditionalRecipients:
29591+
description: Use conditional recipients to define different recipients for different
29592+
situations.
29593+
properties:
29594+
conditions:
29595+
description: Conditions of the notification rule.
29596+
items:
29597+
$ref: '#/components/schemas/MonitorNotificationRuleCondition'
29598+
maxItems: 10
29599+
minItems: 1
29600+
type: array
29601+
fallback_recipients:
29602+
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
29603+
description: If none of the `conditions` applied, `fallback_recipients`
29604+
will get notified.
29605+
required:
29606+
- conditions
29607+
type: object
2957829608
MonitorNotificationRuleCreateRequest:
2957929609
description: Request for creating a monitor notification rule.
2958029610
properties:
@@ -29714,6 +29744,8 @@ components:
2971429744
additionalProperties: {}
2971529745
description: Attributes of the monitor notification rule.
2971629746
properties:
29747+
conditional_recipients:
29748+
$ref: '#/components/schemas/MonitorNotificationRuleConditionalRecipients'
2971729749
created:
2971829750
description: Creation time of the monitor notification rule.
2971929751
example: 2020-01-02 03:04:00+00:00
@@ -29735,6 +29767,12 @@ components:
2973529767
description: An object related to a monitor notification rule.
2973629768
oneOf:
2973729769
- $ref: '#/components/schemas/User'
29770+
MonitorNotificationRuleScope:
29771+
description: The scope to which the monitor applied.
29772+
example: transition_type:alert
29773+
maxLength: 3000
29774+
minLength: 1
29775+
type: string
2973829776
MonitorNotificationRuleUpdateRequest:
2973929777
description: Request for updating a monitor notification rule.
2974029778
properties:

api/datadogV2/model_monitor_notification_rule_attributes.go

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import (
1212

1313
// MonitorNotificationRuleAttributes Attributes of the monitor notification rule.
1414
type MonitorNotificationRuleAttributes struct {
15+
// Use conditional recipients to define different recipients for different situations.
16+
ConditionalRecipients *MonitorNotificationRuleConditionalRecipients `json:"conditional_recipients,omitempty"`
1517
// Filter used to associate the notification rule with monitors.
1618
Filter *MonitorNotificationRuleFilter `json:"filter,omitempty"`
1719
// The name of the monitor notification rule.
1820
Name string `json:"name"`
1921
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
20-
Recipients []string `json:"recipients"`
22+
Recipients []string `json:"recipients,omitempty"`
2123
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
2224
UnparsedObject map[string]interface{} `json:"-"`
2325
}
@@ -26,10 +28,9 @@ type MonitorNotificationRuleAttributes struct {
2628
// This constructor will assign default values to properties that have it defined,
2729
// and makes sure properties required by API are set, but the set of arguments
2830
// will change when the set of required properties is changed.
29-
func NewMonitorNotificationRuleAttributes(name string, recipients []string) *MonitorNotificationRuleAttributes {
31+
func NewMonitorNotificationRuleAttributes(name string) *MonitorNotificationRuleAttributes {
3032
this := MonitorNotificationRuleAttributes{}
3133
this.Name = name
32-
this.Recipients = recipients
3334
return &this
3435
}
3536

@@ -41,6 +42,34 @@ func NewMonitorNotificationRuleAttributesWithDefaults() *MonitorNotificationRule
4142
return &this
4243
}
4344

45+
// GetConditionalRecipients returns the ConditionalRecipients field value if set, zero value otherwise.
46+
func (o *MonitorNotificationRuleAttributes) GetConditionalRecipients() MonitorNotificationRuleConditionalRecipients {
47+
if o == nil || o.ConditionalRecipients == nil {
48+
var ret MonitorNotificationRuleConditionalRecipients
49+
return ret
50+
}
51+
return *o.ConditionalRecipients
52+
}
53+
54+
// GetConditionalRecipientsOk returns a tuple with the ConditionalRecipients field value if set, nil otherwise
55+
// and a boolean to check if the value has been set.
56+
func (o *MonitorNotificationRuleAttributes) GetConditionalRecipientsOk() (*MonitorNotificationRuleConditionalRecipients, bool) {
57+
if o == nil || o.ConditionalRecipients == nil {
58+
return nil, false
59+
}
60+
return o.ConditionalRecipients, true
61+
}
62+
63+
// HasConditionalRecipients returns a boolean if a field has been set.
64+
func (o *MonitorNotificationRuleAttributes) HasConditionalRecipients() bool {
65+
return o != nil && o.ConditionalRecipients != nil
66+
}
67+
68+
// SetConditionalRecipients gets a reference to the given MonitorNotificationRuleConditionalRecipients and assigns it to the ConditionalRecipients field.
69+
func (o *MonitorNotificationRuleAttributes) SetConditionalRecipients(v MonitorNotificationRuleConditionalRecipients) {
70+
o.ConditionalRecipients = &v
71+
}
72+
4473
// GetFilter returns the Filter field value if set, zero value otherwise.
4574
func (o *MonitorNotificationRuleAttributes) GetFilter() MonitorNotificationRuleFilter {
4675
if o == nil || o.Filter == nil {
@@ -92,25 +121,30 @@ func (o *MonitorNotificationRuleAttributes) SetName(v string) {
92121
o.Name = v
93122
}
94123

95-
// GetRecipients returns the Recipients field value.
124+
// GetRecipients returns the Recipients field value if set, zero value otherwise.
96125
func (o *MonitorNotificationRuleAttributes) GetRecipients() []string {
97-
if o == nil {
126+
if o == nil || o.Recipients == nil {
98127
var ret []string
99128
return ret
100129
}
101130
return o.Recipients
102131
}
103132

104-
// GetRecipientsOk returns a tuple with the Recipients field value
133+
// GetRecipientsOk returns a tuple with the Recipients field value if set, nil otherwise
105134
// and a boolean to check if the value has been set.
106135
func (o *MonitorNotificationRuleAttributes) GetRecipientsOk() (*[]string, bool) {
107-
if o == nil {
136+
if o == nil || o.Recipients == nil {
108137
return nil, false
109138
}
110139
return &o.Recipients, true
111140
}
112141

113-
// SetRecipients sets field value.
142+
// HasRecipients returns a boolean if a field has been set.
143+
func (o *MonitorNotificationRuleAttributes) HasRecipients() bool {
144+
return o != nil && o.Recipients != nil
145+
}
146+
147+
// SetRecipients gets a reference to the given []string and assigns it to the Recipients field.
114148
func (o *MonitorNotificationRuleAttributes) SetRecipients(v []string) {
115149
o.Recipients = v
116150
}
@@ -121,33 +155,46 @@ func (o MonitorNotificationRuleAttributes) MarshalJSON() ([]byte, error) {
121155
if o.UnparsedObject != nil {
122156
return datadog.Marshal(o.UnparsedObject)
123157
}
158+
if o.ConditionalRecipients != nil {
159+
toSerialize["conditional_recipients"] = o.ConditionalRecipients
160+
}
124161
if o.Filter != nil {
125162
toSerialize["filter"] = o.Filter
126163
}
127164
toSerialize["name"] = o.Name
128-
toSerialize["recipients"] = o.Recipients
165+
if o.Recipients != nil {
166+
toSerialize["recipients"] = o.Recipients
167+
}
129168
return datadog.Marshal(toSerialize)
130169
}
131170

132171
// UnmarshalJSON deserializes the given payload.
133172
func (o *MonitorNotificationRuleAttributes) UnmarshalJSON(bytes []byte) (err error) {
134173
all := struct {
135-
Filter *MonitorNotificationRuleFilter `json:"filter,omitempty"`
136-
Name *string `json:"name"`
137-
Recipients *[]string `json:"recipients"`
174+
ConditionalRecipients *MonitorNotificationRuleConditionalRecipients `json:"conditional_recipients,omitempty"`
175+
Filter *MonitorNotificationRuleFilter `json:"filter,omitempty"`
176+
Name *string `json:"name"`
177+
Recipients []string `json:"recipients,omitempty"`
138178
}{}
139179
if err = datadog.Unmarshal(bytes, &all); err != nil {
140180
return datadog.Unmarshal(bytes, &o.UnparsedObject)
141181
}
142182
if all.Name == nil {
143183
return fmt.Errorf("required field name missing")
144184
}
145-
if all.Recipients == nil {
146-
return fmt.Errorf("required field recipients missing")
185+
186+
hasInvalidField := false
187+
if all.ConditionalRecipients != nil && all.ConditionalRecipients.UnparsedObject != nil && o.UnparsedObject == nil {
188+
hasInvalidField = true
147189
}
190+
o.ConditionalRecipients = all.ConditionalRecipients
148191
o.Filter = all.Filter
149192
o.Name = *all.Name
150-
o.Recipients = *all.Recipients
193+
o.Recipients = all.Recipients
194+
195+
if hasInvalidField {
196+
return datadog.Unmarshal(bytes, &o.UnparsedObject)
197+
}
151198

152199
return nil
153200
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
package datadogV2
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
11+
)
12+
13+
// MonitorNotificationRuleCondition Conditions for `conditional_recipients`.
14+
type MonitorNotificationRuleCondition struct {
15+
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
16+
Recipients []string `json:"recipients"`
17+
// The scope to which the monitor applied.
18+
Scope string `json:"scope"`
19+
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
20+
UnparsedObject map[string]interface{} `json:"-"`
21+
AdditionalProperties map[string]interface{} `json:"-"`
22+
}
23+
24+
// NewMonitorNotificationRuleCondition instantiates a new MonitorNotificationRuleCondition object.
25+
// This constructor will assign default values to properties that have it defined,
26+
// and makes sure properties required by API are set, but the set of arguments
27+
// will change when the set of required properties is changed.
28+
func NewMonitorNotificationRuleCondition(recipients []string, scope string) *MonitorNotificationRuleCondition {
29+
this := MonitorNotificationRuleCondition{}
30+
this.Recipients = recipients
31+
this.Scope = scope
32+
return &this
33+
}
34+
35+
// NewMonitorNotificationRuleConditionWithDefaults instantiates a new MonitorNotificationRuleCondition object.
36+
// This constructor will only assign default values to properties that have it defined,
37+
// but it doesn't guarantee that properties required by API are set.
38+
func NewMonitorNotificationRuleConditionWithDefaults() *MonitorNotificationRuleCondition {
39+
this := MonitorNotificationRuleCondition{}
40+
return &this
41+
}
42+
43+
// GetRecipients returns the Recipients field value.
44+
func (o *MonitorNotificationRuleCondition) GetRecipients() []string {
45+
if o == nil {
46+
var ret []string
47+
return ret
48+
}
49+
return o.Recipients
50+
}
51+
52+
// GetRecipientsOk returns a tuple with the Recipients field value
53+
// and a boolean to check if the value has been set.
54+
func (o *MonitorNotificationRuleCondition) GetRecipientsOk() (*[]string, bool) {
55+
if o == nil {
56+
return nil, false
57+
}
58+
return &o.Recipients, true
59+
}
60+
61+
// SetRecipients sets field value.
62+
func (o *MonitorNotificationRuleCondition) SetRecipients(v []string) {
63+
o.Recipients = v
64+
}
65+
66+
// GetScope returns the Scope field value.
67+
func (o *MonitorNotificationRuleCondition) GetScope() string {
68+
if o == nil {
69+
var ret string
70+
return ret
71+
}
72+
return o.Scope
73+
}
74+
75+
// GetScopeOk returns a tuple with the Scope field value
76+
// and a boolean to check if the value has been set.
77+
func (o *MonitorNotificationRuleCondition) GetScopeOk() (*string, bool) {
78+
if o == nil {
79+
return nil, false
80+
}
81+
return &o.Scope, true
82+
}
83+
84+
// SetScope sets field value.
85+
func (o *MonitorNotificationRuleCondition) SetScope(v string) {
86+
o.Scope = v
87+
}
88+
89+
// MarshalJSON serializes the struct using spec logic.
90+
func (o MonitorNotificationRuleCondition) MarshalJSON() ([]byte, error) {
91+
toSerialize := map[string]interface{}{}
92+
if o.UnparsedObject != nil {
93+
return datadog.Marshal(o.UnparsedObject)
94+
}
95+
toSerialize["recipients"] = o.Recipients
96+
toSerialize["scope"] = o.Scope
97+
98+
for key, value := range o.AdditionalProperties {
99+
toSerialize[key] = value
100+
}
101+
return datadog.Marshal(toSerialize)
102+
}
103+
104+
// UnmarshalJSON deserializes the given payload.
105+
func (o *MonitorNotificationRuleCondition) UnmarshalJSON(bytes []byte) (err error) {
106+
all := struct {
107+
Recipients *[]string `json:"recipients"`
108+
Scope *string `json:"scope"`
109+
}{}
110+
if err = datadog.Unmarshal(bytes, &all); err != nil {
111+
return datadog.Unmarshal(bytes, &o.UnparsedObject)
112+
}
113+
if all.Recipients == nil {
114+
return fmt.Errorf("required field recipients missing")
115+
}
116+
if all.Scope == nil {
117+
return fmt.Errorf("required field scope missing")
118+
}
119+
additionalProperties := make(map[string]interface{})
120+
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
121+
datadog.DeleteKeys(additionalProperties, &[]string{"recipients", "scope"})
122+
} else {
123+
return err
124+
}
125+
o.Recipients = *all.Recipients
126+
o.Scope = *all.Scope
127+
128+
if len(additionalProperties) > 0 {
129+
o.AdditionalProperties = additionalProperties
130+
}
131+
132+
return nil
133+
}

0 commit comments

Comments
 (0)