Skip to content

Commit 0d6926d

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add filter.scope to Monitor Notification Rules (DataDog#3462)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent d1db495 commit 0d6926d

15 files changed

+382
-21
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32691,15 +32691,23 @@ components:
3269132691
properties:
3269232692
recipients:
3269332693
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
32694+
description: A list of recipients to notify. Uses the same format as the
32695+
monitor `message` field. Must not start with an '@'.
3269432696
scope:
32695-
$ref: '#/components/schemas/MonitorNotificationRuleScope'
32697+
$ref: '#/components/schemas/MonitorNotificationRuleConditionScope'
3269632698
required:
3269732699
- scope
3269832700
- recipients
3269932701
type: object
32702+
MonitorNotificationRuleConditionScope:
32703+
description: The scope to which the monitor applied.
32704+
example: transition_type:alert
32705+
maxLength: 3000
32706+
minLength: 1
32707+
type: string
3270032708
MonitorNotificationRuleConditionalRecipients:
3270132709
description: Use conditional recipients to define different recipients for different
32702-
situations.
32710+
situations. Cannot be used with `recipients`.
3270332711
properties:
3270432712
conditions:
3270532713
description: Conditions of the notification rule.
@@ -32749,12 +32757,30 @@ components:
3274932757
description: Filter used to associate the notification rule with monitors.
3275032758
oneOf:
3275132759
- $ref: '#/components/schemas/MonitorNotificationRuleFilterTags'
32760+
- $ref: '#/components/schemas/MonitorNotificationRuleFilterScope'
32761+
MonitorNotificationRuleFilterScope:
32762+
additionalProperties: false
32763+
description: Filter monitor notifications. A monitor notification must match
32764+
the scope.
32765+
properties:
32766+
scope:
32767+
description: A scope composed of one or several key:value pairs, which can
32768+
be used to filter monitor notifications on monitor and group tags.
32769+
example: service:(foo OR bar) AND team:test NOT environment:staging
32770+
maxLength: 3000
32771+
minLength: 1
32772+
type: string
32773+
required:
32774+
- scope
32775+
type: object
3275232776
MonitorNotificationRuleFilterTags:
3275332777
additionalProperties: false
32754-
description: Filter monitors by tags. Monitors must match all tags.
32778+
description: Filter monitor notifications by tags. A monitor notification must
32779+
match all tags.
3275532780
properties:
3275632781
tags:
32757-
description: A list of monitor tags.
32782+
description: A list of tags (key:value pairs), which can be used to filter
32783+
monitor notifications on monitor and group tags.
3275832784
example:
3275932785
- team:product
3276032786
- host:abc
@@ -32794,7 +32820,7 @@ components:
3279432820
type: string
3279532821
MonitorNotificationRuleRecipients:
3279632822
description: A list of recipients to notify. Uses the same format as the monitor
32797-
`message` field. Must not start with an '@'.
32823+
`message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
3279832824
example:
3279932825
- slack-test-channel
3280032826
- jira-test
@@ -32877,12 +32903,6 @@ components:
3287732903
description: An object related to a monitor notification rule.
3287832904
oneOf:
3287932905
- $ref: '#/components/schemas/User'
32880-
MonitorNotificationRuleScope:
32881-
description: The scope to which the monitor applied.
32882-
example: transition_type:alert
32883-
maxLength: 3000
32884-
minLength: 1
32885-
type: string
3288632906
MonitorNotificationRuleUpdateRequest:
3288732907
description: Request for updating a monitor notification rule.
3288832908
properties:

api/datadogV2/model_monitor_notification_rule_attributes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ 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.
15+
// Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
1616
ConditionalRecipients *MonitorNotificationRuleConditionalRecipients `json:"conditional_recipients,omitempty"`
1717
// Filter used to associate the notification rule with monitors.
1818
Filter *MonitorNotificationRuleFilter `json:"filter,omitempty"`
1919
// The name of the monitor notification rule.
2020
Name string `json:"name"`
21-
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
21+
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
2222
Recipients []string `json:"recipients,omitempty"`
2323
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
2424
UnparsedObject map[string]interface{} `json:"-"`

api/datadogV2/model_monitor_notification_rule_condition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
// MonitorNotificationRuleCondition Conditions for `conditional_recipients`.
1414
type MonitorNotificationRuleCondition struct {
15-
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
15+
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
1616
Recipients []string `json:"recipients"`
1717
// The scope to which the monitor applied.
1818
Scope string `json:"scope"`

api/datadogV2/model_monitor_notification_rule_conditional_recipients.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
1111
)
1212

13-
// MonitorNotificationRuleConditionalRecipients Use conditional recipients to define different recipients for different situations.
13+
// MonitorNotificationRuleConditionalRecipients Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
1414
type MonitorNotificationRuleConditionalRecipients struct {
1515
// Conditions of the notification rule.
1616
Conditions []MonitorNotificationRuleCondition `json:"conditions"`
17-
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
17+
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
1818
FallbackRecipients []string `json:"fallback_recipients,omitempty"`
1919
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
2020
UnparsedObject map[string]interface{} `json:"-"`

api/datadogV2/model_monitor_notification_rule_filter.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010

1111
// MonitorNotificationRuleFilter - Filter used to associate the notification rule with monitors.
1212
type MonitorNotificationRuleFilter struct {
13-
MonitorNotificationRuleFilterTags *MonitorNotificationRuleFilterTags
13+
MonitorNotificationRuleFilterTags *MonitorNotificationRuleFilterTags
14+
MonitorNotificationRuleFilterScope *MonitorNotificationRuleFilterScope
1415

1516
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
1617
UnparsedObject interface{}
@@ -21,6 +22,11 @@ func MonitorNotificationRuleFilterTagsAsMonitorNotificationRuleFilter(v *Monitor
2122
return MonitorNotificationRuleFilter{MonitorNotificationRuleFilterTags: v}
2223
}
2324

25+
// MonitorNotificationRuleFilterScopeAsMonitorNotificationRuleFilter is a convenience function that returns MonitorNotificationRuleFilterScope wrapped in MonitorNotificationRuleFilter.
26+
func MonitorNotificationRuleFilterScopeAsMonitorNotificationRuleFilter(v *MonitorNotificationRuleFilterScope) MonitorNotificationRuleFilter {
27+
return MonitorNotificationRuleFilter{MonitorNotificationRuleFilterScope: v}
28+
}
29+
2430
// UnmarshalJSON turns data into one of the pointers in the struct.
2531
func (obj *MonitorNotificationRuleFilter) UnmarshalJSON(data []byte) error {
2632
var err error
@@ -42,9 +48,27 @@ func (obj *MonitorNotificationRuleFilter) UnmarshalJSON(data []byte) error {
4248
obj.MonitorNotificationRuleFilterTags = nil
4349
}
4450

51+
// try to unmarshal data into MonitorNotificationRuleFilterScope
52+
err = datadog.Unmarshal(data, &obj.MonitorNotificationRuleFilterScope)
53+
if err == nil {
54+
if obj.MonitorNotificationRuleFilterScope != nil && obj.MonitorNotificationRuleFilterScope.UnparsedObject == nil {
55+
jsonMonitorNotificationRuleFilterScope, _ := datadog.Marshal(obj.MonitorNotificationRuleFilterScope)
56+
if string(jsonMonitorNotificationRuleFilterScope) == "{}" { // empty struct
57+
obj.MonitorNotificationRuleFilterScope = nil
58+
} else {
59+
match++
60+
}
61+
} else {
62+
obj.MonitorNotificationRuleFilterScope = nil
63+
}
64+
} else {
65+
obj.MonitorNotificationRuleFilterScope = nil
66+
}
67+
4568
if match != 1 { // more than 1 match
4669
// reset to nil
4770
obj.MonitorNotificationRuleFilterTags = nil
71+
obj.MonitorNotificationRuleFilterScope = nil
4872
return datadog.Unmarshal(data, &obj.UnparsedObject)
4973
}
5074
return nil // exactly one match
@@ -56,6 +80,10 @@ func (obj MonitorNotificationRuleFilter) MarshalJSON() ([]byte, error) {
5680
return datadog.Marshal(&obj.MonitorNotificationRuleFilterTags)
5781
}
5882

83+
if obj.MonitorNotificationRuleFilterScope != nil {
84+
return datadog.Marshal(&obj.MonitorNotificationRuleFilterScope)
85+
}
86+
5987
if obj.UnparsedObject != nil {
6088
return datadog.Marshal(obj.UnparsedObject)
6189
}
@@ -68,6 +96,10 @@ func (obj *MonitorNotificationRuleFilter) GetActualInstance() interface{} {
6896
return obj.MonitorNotificationRuleFilterTags
6997
}
7098

99+
if obj.MonitorNotificationRuleFilterScope != nil {
100+
return obj.MonitorNotificationRuleFilterScope
101+
}
102+
71103
// all schemas are nil
72104
return nil
73105
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
// MonitorNotificationRuleFilterScope Filter monitor notifications. A monitor notification must match the scope.
14+
type MonitorNotificationRuleFilterScope struct {
15+
// A scope composed of one or several key:value pairs, which can be used to filter monitor notifications on monitor and group tags.
16+
Scope string `json:"scope"`
17+
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
18+
UnparsedObject map[string]interface{} `json:"-"`
19+
}
20+
21+
// NewMonitorNotificationRuleFilterScope instantiates a new MonitorNotificationRuleFilterScope object.
22+
// This constructor will assign default values to properties that have it defined,
23+
// and makes sure properties required by API are set, but the set of arguments
24+
// will change when the set of required properties is changed.
25+
func NewMonitorNotificationRuleFilterScope(scope string) *MonitorNotificationRuleFilterScope {
26+
this := MonitorNotificationRuleFilterScope{}
27+
this.Scope = scope
28+
return &this
29+
}
30+
31+
// NewMonitorNotificationRuleFilterScopeWithDefaults instantiates a new MonitorNotificationRuleFilterScope object.
32+
// This constructor will only assign default values to properties that have it defined,
33+
// but it doesn't guarantee that properties required by API are set.
34+
func NewMonitorNotificationRuleFilterScopeWithDefaults() *MonitorNotificationRuleFilterScope {
35+
this := MonitorNotificationRuleFilterScope{}
36+
return &this
37+
}
38+
39+
// GetScope returns the Scope field value.
40+
func (o *MonitorNotificationRuleFilterScope) GetScope() string {
41+
if o == nil {
42+
var ret string
43+
return ret
44+
}
45+
return o.Scope
46+
}
47+
48+
// GetScopeOk returns a tuple with the Scope field value
49+
// and a boolean to check if the value has been set.
50+
func (o *MonitorNotificationRuleFilterScope) GetScopeOk() (*string, bool) {
51+
if o == nil {
52+
return nil, false
53+
}
54+
return &o.Scope, true
55+
}
56+
57+
// SetScope sets field value.
58+
func (o *MonitorNotificationRuleFilterScope) SetScope(v string) {
59+
o.Scope = v
60+
}
61+
62+
// MarshalJSON serializes the struct using spec logic.
63+
func (o MonitorNotificationRuleFilterScope) MarshalJSON() ([]byte, error) {
64+
toSerialize := map[string]interface{}{}
65+
if o.UnparsedObject != nil {
66+
return datadog.Marshal(o.UnparsedObject)
67+
}
68+
toSerialize["scope"] = o.Scope
69+
return datadog.Marshal(toSerialize)
70+
}
71+
72+
// UnmarshalJSON deserializes the given payload.
73+
func (o *MonitorNotificationRuleFilterScope) UnmarshalJSON(bytes []byte) (err error) {
74+
all := struct {
75+
Scope *string `json:"scope"`
76+
}{}
77+
if err = datadog.Unmarshal(bytes, &all); err != nil {
78+
return datadog.Unmarshal(bytes, &o.UnparsedObject)
79+
}
80+
if all.Scope == nil {
81+
return fmt.Errorf("required field scope missing")
82+
}
83+
o.Scope = *all.Scope
84+
85+
return nil
86+
}

api/datadogV2/model_monitor_notification_rule_filter_tags.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
1111
)
1212

13-
// MonitorNotificationRuleFilterTags Filter monitors by tags. Monitors must match all tags.
13+
// MonitorNotificationRuleFilterTags Filter monitor notifications by tags. A monitor notification must match all tags.
1414
type MonitorNotificationRuleFilterTags struct {
15-
// A list of monitor tags.
15+
// A list of tags (key:value pairs), which can be used to filter monitor notifications on monitor and group tags.
1616
Tags []string `json:"tags"`
1717
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
1818
UnparsedObject map[string]interface{} `json:"-"`

api/datadogV2/model_monitor_notification_rule_response_attributes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
// MonitorNotificationRuleResponseAttributes Attributes of the monitor notification rule.
1414
type MonitorNotificationRuleResponseAttributes struct {
15-
// Use conditional recipients to define different recipients for different situations.
15+
// Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
1616
ConditionalRecipients *MonitorNotificationRuleConditionalRecipients `json:"conditional_recipients,omitempty"`
1717
// Creation time of the monitor notification rule.
1818
Created *time.Time `json:"created,omitempty"`
@@ -22,7 +22,7 @@ type MonitorNotificationRuleResponseAttributes struct {
2222
Modified *time.Time `json:"modified,omitempty"`
2323
// The name of the monitor notification rule.
2424
Name *string `json:"name,omitempty"`
25-
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
25+
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
2626
Recipients []string `json:"recipients,omitempty"`
2727
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
2828
UnparsedObject map[string]interface{} `json:"-"`
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Create a monitor notification rule with scope returns "OK" response
2+
3+
package main
4+
5+
import (
6+
"context"
7+
"encoding/json"
8+
"fmt"
9+
"os"
10+
11+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
12+
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
13+
)
14+
15+
func main() {
16+
body := datadogV2.MonitorNotificationRuleCreateRequest{
17+
Data: datadogV2.MonitorNotificationRuleCreateRequestData{
18+
Attributes: datadogV2.MonitorNotificationRuleAttributes{
19+
Filter: &datadogV2.MonitorNotificationRuleFilter{
20+
MonitorNotificationRuleFilterScope: &datadogV2.MonitorNotificationRuleFilterScope{
21+
Scope: "test:example-monitor",
22+
}},
23+
Name: "test rule",
24+
Recipients: []string{
25+
"slack-test-channel",
26+
"jira-test",
27+
},
28+
},
29+
Type: datadogV2.MONITORNOTIFICATIONRULERESOURCETYPE_MONITOR_NOTIFICATION_RULE.Ptr(),
30+
},
31+
}
32+
ctx := datadog.NewDefaultContext(context.Background())
33+
configuration := datadog.NewConfiguration()
34+
apiClient := datadog.NewAPIClient(configuration)
35+
api := datadogV2.NewMonitorsApi(apiClient)
36+
resp, r, err := api.CreateMonitorNotificationRule(ctx, body)
37+
38+
if err != nil {
39+
fmt.Fprintf(os.Stderr, "Error when calling `MonitorsApi.CreateMonitorNotificationRule`: %v\n", err)
40+
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
41+
}
42+
43+
responseContent, _ := json.MarshalIndent(resp, "", " ")
44+
fmt.Fprintf(os.Stdout, "Response from `MonitorsApi.CreateMonitorNotificationRule`:\n%s\n", responseContent)
45+
}

0 commit comments

Comments
 (0)