Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 57 additions & 15 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32691,15 +32691,23 @@ components:
properties:
recipients:
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
description: A list of recipients to notify. Uses the same format as the
monitor `message` field. Must not start with an '@'.
scope:
$ref: '#/components/schemas/MonitorNotificationRuleScope'
$ref: '#/components/schemas/MonitorNotificationRuleConditionScope'
required:
- scope
- recipients
type: object
MonitorNotificationRuleConditionScope:
description: The scope to which the monitor applied.
example: transition_type:alert
maxLength: 3000
minLength: 1
type: string
MonitorNotificationRuleConditionalRecipients:
description: Use conditional recipients to define different recipients for different
situations.
situations. Cannot be used with `recipients`.
properties:
conditions:
description: Conditions of the notification rule.
Expand Down Expand Up @@ -32749,12 +32757,30 @@ components:
description: Filter used to associate the notification rule with monitors.
oneOf:
- $ref: '#/components/schemas/MonitorNotificationRuleFilterTags'
- $ref: '#/components/schemas/MonitorNotificationRuleFilterScope'
MonitorNotificationRuleFilterScope:
additionalProperties: false
description: Filter monitor notifications. A monitor notification must match
the scope.
properties:
scope:
description: A scope composed of one or several key:value pairs, which can
be used to filter monitor notifications on monitor and group tags.
example: service:(foo OR bar) AND team:test NOT environment:staging
maxLength: 3000
minLength: 1
type: string
required:
- scope
type: object
MonitorNotificationRuleFilterTags:
additionalProperties: false
description: Filter monitors by tags. Monitors must match all tags.
description: Filter monitor notifications by tags. A monitor notification must
match all tags.
properties:
tags:
description: A list of monitor tags.
description: A list of tags (key:value pairs), which can be used to filter
monitor notifications on monitor and group tags.
example:
- team:product
- host:abc
Expand Down Expand Up @@ -32794,7 +32820,7 @@ components:
type: string
MonitorNotificationRuleRecipients:
description: A list of recipients to notify. Uses the same format as the monitor
`message` field. Must not start with an '@'.
`message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
example:
- slack-test-channel
- jira-test
Expand Down Expand Up @@ -32877,12 +32903,6 @@ components:
description: An object related to a monitor notification rule.
oneOf:
- $ref: '#/components/schemas/User'
MonitorNotificationRuleScope:
description: The scope to which the monitor applied.
example: transition_type:alert
maxLength: 3000
minLength: 1
type: string
MonitorNotificationRuleUpdateRequest:
description: Request for updating a monitor notification rule.
properties:
Expand Down Expand Up @@ -79113,9 +79133,20 @@ paths:
/api/v2/security_monitoring/rules/convert:
post:
description: 'Convert a rule that doesn''t (yet) exist from JSON to Terraform
for datadog provider
for Datadog provider

resource `datadog_security_monitoring_rule`. You can do so for the following
rule types:

- App and API Protection

- Cloud SIEM (log detection and signal correlation)

resource datadog_security_monitoring_rule.'
- Workload Protection


You can convert Cloud Security configuration rules using Terraform''s [Datadog
Cloud Configuration Rule resource](https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/cloud_configuration_rule).'
operationId: ConvertSecurityMonitoringRuleFromJSONToTerraform
requestBody:
content:
Expand Down Expand Up @@ -79332,9 +79363,20 @@ paths:
- security_monitoring_rules_write
/api/v2/security_monitoring/rules/{rule_id}/convert:
get:
description: 'Convert an existing rule from JSON to Terraform for datadog provider
description: 'Convert an existing rule from JSON to Terraform for Datadog provider

resource `datadog_security_monitoring_rule`. You can do so for the following
rule types:

- App and API Protection

- Cloud SIEM (log detection and signal correlation)

- Workload Protection


resource datadog_security_monitoring_rule.'
You can convert Cloud Security configuration rules using Terraform''s [Datadog
Cloud Configuration Rule resource](https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/cloud_configuration_rule).'
operationId: ConvertExistingSecurityMonitoringRule
parameters:
- $ref: '#/components/parameters/SecurityMonitoringRuleID'
Expand Down
18 changes: 14 additions & 4 deletions api/datadogV2/api_security_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ func (a *SecurityMonitoringApi) CancelThreatHuntingJob(ctx _context.Context, job
}

// ConvertExistingSecurityMonitoringRule Convert an existing rule from JSON to Terraform.
// Convert an existing rule from JSON to Terraform for datadog provider
// resource datadog_security_monitoring_rule.
// Convert an existing rule from JSON to Terraform for Datadog provider
// resource `datadog_security_monitoring_rule`. You can do so for the following rule types:
// - App and API Protection
// - Cloud SIEM (log detection and signal correlation)
// - Workload Protection
//
// You can convert Cloud Security configuration rules using Terraform's [Datadog Cloud Configuration Rule resource](https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/cloud_configuration_rule).
func (a *SecurityMonitoringApi) ConvertExistingSecurityMonitoringRule(ctx _context.Context, ruleId string) (SecurityMonitoringRuleConvertResponse, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodGet
Expand Down Expand Up @@ -255,8 +260,13 @@ func (a *SecurityMonitoringApi) ConvertJobResultToSignal(ctx _context.Context, b
}

// ConvertSecurityMonitoringRuleFromJSONToTerraform Convert a rule from JSON to Terraform.
// Convert a rule that doesn't (yet) exist from JSON to Terraform for datadog provider
// resource datadog_security_monitoring_rule.
// Convert a rule that doesn't (yet) exist from JSON to Terraform for Datadog provider
// resource `datadog_security_monitoring_rule`. You can do so for the following rule types:
// - App and API Protection
// - Cloud SIEM (log detection and signal correlation)
// - Workload Protection
//
// You can convert Cloud Security configuration rules using Terraform's [Datadog Cloud Configuration Rule resource](https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/cloud_configuration_rule).
func (a *SecurityMonitoringApi) ConvertSecurityMonitoringRuleFromJSONToTerraform(ctx _context.Context, body SecurityMonitoringRuleConvertPayload) (SecurityMonitoringRuleConvertResponse, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodPost
Expand Down
4 changes: 2 additions & 2 deletions api/datadogV2/model_monitor_notification_rule_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (

// MonitorNotificationRuleAttributes Attributes of the monitor notification rule.
type MonitorNotificationRuleAttributes struct {
// Use conditional recipients to define different recipients for different situations.
// Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
ConditionalRecipients *MonitorNotificationRuleConditionalRecipients `json:"conditional_recipients,omitempty"`
// Filter used to associate the notification rule with monitors.
Filter *MonitorNotificationRuleFilter `json:"filter,omitempty"`
// The name of the monitor notification rule.
Name string `json:"name"`
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
// 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`.
Recipients []string `json:"recipients,omitempty"`
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject map[string]interface{} `json:"-"`
Expand Down
2 changes: 1 addition & 1 deletion api/datadogV2/model_monitor_notification_rule_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// MonitorNotificationRuleCondition Conditions for `conditional_recipients`.
type MonitorNotificationRuleCondition struct {
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
// 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`.
Recipients []string `json:"recipients"`
// The scope to which the monitor applied.
Scope string `json:"scope"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
)

// MonitorNotificationRuleConditionalRecipients Use conditional recipients to define different recipients for different situations.
// MonitorNotificationRuleConditionalRecipients Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
type MonitorNotificationRuleConditionalRecipients struct {
// Conditions of the notification rule.
Conditions []MonitorNotificationRuleCondition `json:"conditions"`
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
// 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`.
FallbackRecipients []string `json:"fallback_recipients,omitempty"`
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject map[string]interface{} `json:"-"`
Expand Down
34 changes: 33 additions & 1 deletion api/datadogV2/model_monitor_notification_rule_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (

// MonitorNotificationRuleFilter - Filter used to associate the notification rule with monitors.
type MonitorNotificationRuleFilter struct {
MonitorNotificationRuleFilterTags *MonitorNotificationRuleFilterTags
MonitorNotificationRuleFilterTags *MonitorNotificationRuleFilterTags
MonitorNotificationRuleFilterScope *MonitorNotificationRuleFilterScope

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

// MonitorNotificationRuleFilterScopeAsMonitorNotificationRuleFilter is a convenience function that returns MonitorNotificationRuleFilterScope wrapped in MonitorNotificationRuleFilter.
func MonitorNotificationRuleFilterScopeAsMonitorNotificationRuleFilter(v *MonitorNotificationRuleFilterScope) MonitorNotificationRuleFilter {
return MonitorNotificationRuleFilter{MonitorNotificationRuleFilterScope: v}
}

// UnmarshalJSON turns data into one of the pointers in the struct.
func (obj *MonitorNotificationRuleFilter) UnmarshalJSON(data []byte) error {
var err error
Expand All @@ -42,9 +48,27 @@ func (obj *MonitorNotificationRuleFilter) UnmarshalJSON(data []byte) error {
obj.MonitorNotificationRuleFilterTags = nil
}

// try to unmarshal data into MonitorNotificationRuleFilterScope
err = datadog.Unmarshal(data, &obj.MonitorNotificationRuleFilterScope)
if err == nil {
if obj.MonitorNotificationRuleFilterScope != nil && obj.MonitorNotificationRuleFilterScope.UnparsedObject == nil {
jsonMonitorNotificationRuleFilterScope, _ := datadog.Marshal(obj.MonitorNotificationRuleFilterScope)
if string(jsonMonitorNotificationRuleFilterScope) == "{}" { // empty struct
obj.MonitorNotificationRuleFilterScope = nil
} else {
match++
}
} else {
obj.MonitorNotificationRuleFilterScope = nil
}
} else {
obj.MonitorNotificationRuleFilterScope = nil
}

if match != 1 { // more than 1 match
// reset to nil
obj.MonitorNotificationRuleFilterTags = nil
obj.MonitorNotificationRuleFilterScope = nil
return datadog.Unmarshal(data, &obj.UnparsedObject)
}
return nil // exactly one match
Expand All @@ -56,6 +80,10 @@ func (obj MonitorNotificationRuleFilter) MarshalJSON() ([]byte, error) {
return datadog.Marshal(&obj.MonitorNotificationRuleFilterTags)
}

if obj.MonitorNotificationRuleFilterScope != nil {
return datadog.Marshal(&obj.MonitorNotificationRuleFilterScope)
}

if obj.UnparsedObject != nil {
return datadog.Marshal(obj.UnparsedObject)
}
Expand All @@ -68,6 +96,10 @@ func (obj *MonitorNotificationRuleFilter) GetActualInstance() interface{} {
return obj.MonitorNotificationRuleFilterTags
}

if obj.MonitorNotificationRuleFilterScope != nil {
return obj.MonitorNotificationRuleFilterScope
}

// all schemas are nil
return nil
}
86 changes: 86 additions & 0 deletions api/datadogV2/model_monitor_notification_rule_filter_scope.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

package datadogV2

import (
"fmt"

"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
)

// MonitorNotificationRuleFilterScope Filter monitor notifications. A monitor notification must match the scope.
type MonitorNotificationRuleFilterScope struct {
// A scope composed of one or several key:value pairs, which can be used to filter monitor notifications on monitor and group tags.
Scope string `json:"scope"`
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject map[string]interface{} `json:"-"`
}

// NewMonitorNotificationRuleFilterScope instantiates a new MonitorNotificationRuleFilterScope object.
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed.
func NewMonitorNotificationRuleFilterScope(scope string) *MonitorNotificationRuleFilterScope {
this := MonitorNotificationRuleFilterScope{}
this.Scope = scope
return &this
}

// NewMonitorNotificationRuleFilterScopeWithDefaults instantiates a new MonitorNotificationRuleFilterScope object.
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set.
func NewMonitorNotificationRuleFilterScopeWithDefaults() *MonitorNotificationRuleFilterScope {
this := MonitorNotificationRuleFilterScope{}
return &this
}

// GetScope returns the Scope field value.
func (o *MonitorNotificationRuleFilterScope) GetScope() string {
if o == nil {
var ret string
return ret
}
return o.Scope
}

// GetScopeOk returns a tuple with the Scope field value
// and a boolean to check if the value has been set.
func (o *MonitorNotificationRuleFilterScope) GetScopeOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Scope, true
}

// SetScope sets field value.
func (o *MonitorNotificationRuleFilterScope) SetScope(v string) {
o.Scope = v
}

// MarshalJSON serializes the struct using spec logic.
func (o MonitorNotificationRuleFilterScope) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.UnparsedObject != nil {
return datadog.Marshal(o.UnparsedObject)
}
toSerialize["scope"] = o.Scope
return datadog.Marshal(toSerialize)
}

// UnmarshalJSON deserializes the given payload.
func (o *MonitorNotificationRuleFilterScope) UnmarshalJSON(bytes []byte) (err error) {
all := struct {
Scope *string `json:"scope"`
}{}
if err = datadog.Unmarshal(bytes, &all); err != nil {
return datadog.Unmarshal(bytes, &o.UnparsedObject)
}
if all.Scope == nil {
return fmt.Errorf("required field scope missing")
}
o.Scope = *all.Scope

return nil
}
4 changes: 2 additions & 2 deletions api/datadogV2/model_monitor_notification_rule_filter_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
)

// MonitorNotificationRuleFilterTags Filter monitors by tags. Monitors must match all tags.
// MonitorNotificationRuleFilterTags Filter monitor notifications by tags. A monitor notification must match all tags.
type MonitorNotificationRuleFilterTags struct {
// A list of monitor tags.
// A list of tags (key:value pairs), which can be used to filter monitor notifications on monitor and group tags.
Tags []string `json:"tags"`
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject map[string]interface{} `json:"-"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// MonitorNotificationRuleResponseAttributes Attributes of the monitor notification rule.
type MonitorNotificationRuleResponseAttributes struct {
// Use conditional recipients to define different recipients for different situations.
// Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
ConditionalRecipients *MonitorNotificationRuleConditionalRecipients `json:"conditional_recipients,omitempty"`
// Creation time of the monitor notification rule.
Created *time.Time `json:"created,omitempty"`
Expand All @@ -22,7 +22,7 @@ type MonitorNotificationRuleResponseAttributes struct {
Modified *time.Time `json:"modified,omitempty"`
// The name of the monitor notification rule.
Name *string `json:"name,omitempty"`
// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
// 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`.
Recipients []string `json:"recipients,omitempty"`
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject map[string]interface{} `json:"-"`
Expand Down
Loading
Loading