diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 17509b56882d..a0d181216789 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -29565,6 +29565,8 @@ components: additionalProperties: false description: Attributes of the monitor notification rule. properties: + conditional_recipients: + $ref: '#/components/schemas/MonitorNotificationRuleConditionalRecipients' filter: $ref: '#/components/schemas/MonitorNotificationRuleFilter' name: @@ -29573,8 +29575,36 @@ components: $ref: '#/components/schemas/MonitorNotificationRuleRecipients' required: - name + type: object + MonitorNotificationRuleCondition: + description: Conditions for `conditional_recipients`. + properties: + recipients: + $ref: '#/components/schemas/MonitorNotificationRuleRecipients' + scope: + $ref: '#/components/schemas/MonitorNotificationRuleScope' + required: + - scope - recipients type: object + MonitorNotificationRuleConditionalRecipients: + description: Use conditional recipients to define different recipients for different + situations. + properties: + conditions: + description: Conditions of the notification rule. + items: + $ref: '#/components/schemas/MonitorNotificationRuleCondition' + maxItems: 10 + minItems: 1 + type: array + fallback_recipients: + $ref: '#/components/schemas/MonitorNotificationRuleRecipients' + description: If none of the `conditions` applied, `fallback_recipients` + will get notified. + required: + - conditions + type: object MonitorNotificationRuleCreateRequest: description: Request for creating a monitor notification rule. properties: @@ -29714,6 +29744,8 @@ components: additionalProperties: {} description: Attributes of the monitor notification rule. properties: + conditional_recipients: + $ref: '#/components/schemas/MonitorNotificationRuleConditionalRecipients' created: description: Creation time of the monitor notification rule. example: 2020-01-02 03:04:00+00:00 @@ -29735,6 +29767,12 @@ 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: diff --git a/cassettes/features/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen b/cassettes/features/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen new file mode 100644 index 000000000000..da684d32ebfc --- /dev/null +++ b/cassettes/features/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-09-26T01:50:59.027Z \ No newline at end of file diff --git a/cassettes/features/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.yml b/cassettes/features/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.yml new file mode 100644 index 000000000000..5e989cbc11b5 --- /dev/null +++ b/cassettes/features/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.yml @@ -0,0 +1,47 @@ +http_interactions: +- recorded_at: Fri, 26 Sep 2025 01:50:59 GMT + request: + body: + encoding: UTF-8 + string: '{"data":{"attributes":{"conditional_recipients":{"conditions":[{"recipients":["slack-test-channel","jira-test"],"scope":"transition_type:is_alert"}]},"filter":{"tags":["test:test-create_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851459"]},"name":"test + rule"},"type":"monitor-notification-rule"}}' + headers: + Accept: + - application/json + Content-Type: + - application/json + method: POST + uri: https://api.datadoghq.com/api/v2/monitor/notification_rule + response: + body: + encoding: UTF-8 + string: '{"data":{"type":"monitor-notification-rule","attributes":{"name":"test + rule","filter":{"tags":["test:test-create_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851459"]},"created_at":"2025-09-26T01:51:00.132009+00:00","conditional_recipients":{"conditions":[{"recipients":["slack-test-channel","jira-test"],"scope":"transition_type:is_alert"}]},"modified_at":"1970-01-01T00:00:00+00:00"},"id":"707b82d7-6898-4b20-a577-64f76881fe89","relationships":{"created_by":{"data":{"type":"users","id":"9919ec9b-ebc7-49ee-8dc8-03626e717cca"}}}},"included":[{"type":"users","id":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","attributes":{"name":"CI + Account","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","created_at":"2020-12-29T22:58:44.733921+00:00","modified_at":"2021-04-27T13:54:01.547888+00:00","email":"team-intg-tools-libs-spam@datadoghq.com","icon":"https://secure.gravatar.com/avatar/b7c189b5b4c2c429d7c1e0bc3749330e?s=48&d=retro","title":null,"verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active"}}]} + + ' + headers: + Content-Type: + - application/json + status: + code: 200 + message: OK +- recorded_at: Fri, 26 Sep 2025 01:50:59 GMT + request: + body: null + headers: + Accept: + - '*/*' + method: DELETE + uri: https://api.datadoghq.com/api/v2/monitor/notification_rule/707b82d7-6898-4b20-a577-64f76881fe89 + response: + body: + encoding: UTF-8 + string: '' + headers: + Content-Type: + - text/html; charset=utf-8 + status: + code: 204 + message: No Content +recorded_with: VCR 6.0.0 diff --git a/cassettes/features/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen b/cassettes/features/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen new file mode 100644 index 000000000000..8543967b2b98 --- /dev/null +++ b/cassettes/features/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-09-26T01:51:00.504Z \ No newline at end of file diff --git a/cassettes/features/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.yml b/cassettes/features/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.yml new file mode 100644 index 000000000000..ebf5ad62d773 --- /dev/null +++ b/cassettes/features/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.yml @@ -0,0 +1,74 @@ +http_interactions: +- recorded_at: Fri, 26 Sep 2025 01:51:00 GMT + request: + body: + encoding: UTF-8 + string: '{"data":{"attributes":{"filter":{"tags":["app:test-update_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851460"]},"name":"test + rule","recipients":["slack-monitor-app"]},"type":"monitor-notification-rule"}}' + headers: + Accept: + - application/json + Content-Type: + - application/json + method: POST + uri: https://api.datadoghq.com/api/v2/monitor/notification_rule + response: + body: + encoding: UTF-8 + string: '{"data":{"type":"monitor-notification-rule","attributes":{"filter":{"tags":["app:test-update_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851460"]},"created_at":"2025-09-26T01:51:00.665373+00:00","name":"test + rule","recipients":["slack-monitor-app"],"modified_at":"1970-01-01T00:00:00+00:00"},"id":"954d2f74-ec41-4f7b-9f63-7146075f3537","relationships":{"created_by":{"data":{"type":"users","id":"9919ec9b-ebc7-49ee-8dc8-03626e717cca"}}}},"included":[{"type":"users","id":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","attributes":{"name":"CI + Account","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","created_at":"2020-12-29T22:58:44.733921+00:00","modified_at":"2021-04-27T13:54:01.547888+00:00","email":"team-intg-tools-libs-spam@datadoghq.com","icon":"https://secure.gravatar.com/avatar/b7c189b5b4c2c429d7c1e0bc3749330e?s=48&d=retro","title":null,"verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active"}}]} + + ' + headers: + Content-Type: + - application/json + status: + code: 200 + message: OK +- recorded_at: Fri, 26 Sep 2025 01:51:00 GMT + request: + body: + encoding: UTF-8 + string: '{"data":{"attributes":{"conditional_recipients":{"conditions":[{"recipients":["slack-test-channel","jira-test"],"scope":"transition_type:is_alert"}]},"filter":{"tags":["test:test-update_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851460","host:abc"]},"name":"updated + rule"},"id":"954d2f74-ec41-4f7b-9f63-7146075f3537","type":"monitor-notification-rule"}}' + headers: + Accept: + - application/json + Content-Type: + - application/json + method: PATCH + uri: https://api.datadoghq.com/api/v2/monitor/notification_rule/954d2f74-ec41-4f7b-9f63-7146075f3537 + response: + body: + encoding: UTF-8 + string: '{"data":{"type":"monitor-notification-rule","id":"954d2f74-ec41-4f7b-9f63-7146075f3537","attributes":{"filter":{"tags":["test:test-update_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851460","host:abc"]},"modified_at":"2025-09-26T01:51:00.876883+00:00","conditional_recipients":{"conditions":[{"scope":"transition_type:is_alert","recipients":["slack-test-channel","jira-test"]}]},"name":"updated + rule","created_at":"2025-09-26T01:51:00.665373+00:00"},"relationships":{"created_by":{"data":{"type":"users","id":"9919ec9b-ebc7-49ee-8dc8-03626e717cca"}}}},"included":[{"type":"users","id":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","attributes":{"name":"CI + Account","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","created_at":"2020-12-29T22:58:44.733921+00:00","modified_at":"2021-04-27T13:54:01.547888+00:00","email":"team-intg-tools-libs-spam@datadoghq.com","icon":"https://secure.gravatar.com/avatar/b7c189b5b4c2c429d7c1e0bc3749330e?s=48&d=retro","title":null,"verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active"}}]} + + ' + headers: + Content-Type: + - application/json + status: + code: 200 + message: OK +- recorded_at: Fri, 26 Sep 2025 01:51:00 GMT + request: + body: null + headers: + Accept: + - '*/*' + method: DELETE + uri: https://api.datadoghq.com/api/v2/monitor/notification_rule/954d2f74-ec41-4f7b-9f63-7146075f3537 + response: + body: + encoding: UTF-8 + string: '' + headers: + Content-Type: + - text/html; charset=utf-8 + status: + code: 204 + message: No Content +recorded_with: VCR 6.0.0 diff --git a/examples/v2/monitors/CreateMonitorNotificationRule_1181818787.rb b/examples/v2/monitors/CreateMonitorNotificationRule_1181818787.rb new file mode 100644 index 000000000000..fb4f4753b567 --- /dev/null +++ b/examples/v2/monitors/CreateMonitorNotificationRule_1181818787.rb @@ -0,0 +1,30 @@ +# Create a monitor notification rule with conditional recipients returns "OK" response + +require "datadog_api_client" +api_instance = DatadogAPIClient::V2::MonitorsAPI.new + +body = DatadogAPIClient::V2::MonitorNotificationRuleCreateRequest.new({ + data: DatadogAPIClient::V2::MonitorNotificationRuleCreateRequestData.new({ + attributes: DatadogAPIClient::V2::MonitorNotificationRuleAttributes.new({ + filter: DatadogAPIClient::V2::MonitorNotificationRuleFilterTags.new({ + tags: [ + "test:example-monitor", + ], + }), + name: "test rule", + conditional_recipients: DatadogAPIClient::V2::MonitorNotificationRuleConditionalRecipients.new({ + conditions: [ + DatadogAPIClient::V2::MonitorNotificationRuleCondition.new({ + scope: "transition_type:is_alert", + recipients: [ + "slack-test-channel", + "jira-test", + ], + }), + ], + }), + }), + type: DatadogAPIClient::V2::MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE, + }), +}) +p api_instance.create_monitor_notification_rule(body) diff --git a/examples/v2/monitors/UpdateMonitorNotificationRule_1400905713.rb b/examples/v2/monitors/UpdateMonitorNotificationRule_1400905713.rb new file mode 100644 index 000000000000..43389d8da967 --- /dev/null +++ b/examples/v2/monitors/UpdateMonitorNotificationRule_1400905713.rb @@ -0,0 +1,35 @@ +# Update a monitor notification rule with conditional_recipients returns "OK" response + +require "datadog_api_client" +api_instance = DatadogAPIClient::V2::MonitorsAPI.new + +# there is a valid "monitor_notification_rule" in the system +MONITOR_NOTIFICATION_RULE_DATA_ID = ENV["MONITOR_NOTIFICATION_RULE_DATA_ID"] + +body = DatadogAPIClient::V2::MonitorNotificationRuleUpdateRequest.new({ + data: DatadogAPIClient::V2::MonitorNotificationRuleUpdateRequestData.new({ + attributes: DatadogAPIClient::V2::MonitorNotificationRuleAttributes.new({ + filter: DatadogAPIClient::V2::MonitorNotificationRuleFilterTags.new({ + tags: [ + "test:example-monitor", + "host:abc", + ], + }), + name: "updated rule", + conditional_recipients: DatadogAPIClient::V2::MonitorNotificationRuleConditionalRecipients.new({ + conditions: [ + DatadogAPIClient::V2::MonitorNotificationRuleCondition.new({ + scope: "transition_type:is_alert", + recipients: [ + "slack-test-channel", + "jira-test", + ], + }), + ], + }), + }), + id: MONITOR_NOTIFICATION_RULE_DATA_ID, + type: DatadogAPIClient::V2::MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE, + }), +}) +p api_instance.update_monitor_notification_rule(MONITOR_NOTIFICATION_RULE_DATA_ID, body) diff --git a/features/v2/monitors.feature b/features/v2/monitors.feature index d49f00dd0487..3fd3138f9f57 100644 --- a/features/v2/monitors.feature +++ b/features/v2/monitors.feature @@ -44,6 +44,14 @@ Feature: Monitors Then the response status is 200 OK And the response "data.attributes.name" is equal to "test rule" + @team:DataDog/monitor-app + Scenario: Create a monitor notification rule with conditional recipients returns "OK" response + Given new "CreateMonitorNotificationRule" request + And body with value {"data": {"attributes": {"filter": {"tags": ["test:{{ unique_lower }}"]}, "name": "test rule", "conditional_recipients": {"conditions": [{"scope": "transition_type:is_alert", "recipients": ["slack-test-channel", "jira-test"]}]}}, "type": "monitor-notification-rule"}} + When the request is sent + Then the response status is 200 OK + And the response "data.attributes.name" is equal to "test rule" + @skip-validation @team:DataDog/monitor-app Scenario: Create a monitor user template returns "Bad Request" response Given new "CreateMonitorUserTemplate" request @@ -255,6 +263,16 @@ Feature: Monitors Then the response status is 200 OK And the response "data.attributes.name" is equal to "updated rule" + @team:DataDog/monitor-app + Scenario: Update a monitor notification rule with conditional_recipients returns "OK" response + Given there is a valid "monitor_notification_rule" in the system + And new "UpdateMonitorNotificationRule" request + And request contains "rule_id" parameter from "monitor_notification_rule.data.id" + And body with value {"data": {"attributes": {"filter": {"tags": ["test:{{ unique_lower }}", "host:abc"]}, "name": "updated rule", "conditional_recipients": {"conditions": [{"scope": "transition_type:is_alert", "recipients": ["slack-test-channel", "jira-test"]}]}}, "id": "{{ monitor_notification_rule.data.id }}", "type": "monitor-notification-rule"}} + When the request is sent + Then the response status is 200 OK + And the response "data.attributes.name" is equal to "updated rule" + @skip-validation @team:DataDog/monitor-app Scenario: Update a monitor user template to a new version returns "Bad Request" response Given there is a valid "monitor_user_template" in the system diff --git a/lib/datadog_api_client/inflector.rb b/lib/datadog_api_client/inflector.rb index 31aa072fd693..5f593e64148e 100644 --- a/lib/datadog_api_client/inflector.rb +++ b/lib/datadog_api_client/inflector.rb @@ -2759,6 +2759,8 @@ def overrides "v2.monitor_downtime_match_response_attributes" => "MonitorDowntimeMatchResponseAttributes", "v2.monitor_downtime_match_response_data" => "MonitorDowntimeMatchResponseData", "v2.monitor_notification_rule_attributes" => "MonitorNotificationRuleAttributes", + "v2.monitor_notification_rule_condition" => "MonitorNotificationRuleCondition", + "v2.monitor_notification_rule_conditional_recipients" => "MonitorNotificationRuleConditionalRecipients", "v2.monitor_notification_rule_create_request" => "MonitorNotificationRuleCreateRequest", "v2.monitor_notification_rule_create_request_data" => "MonitorNotificationRuleCreateRequestData", "v2.monitor_notification_rule_data" => "MonitorNotificationRuleData", diff --git a/lib/datadog_api_client/v2/models/monitor_notification_rule_attributes.rb b/lib/datadog_api_client/v2/models/monitor_notification_rule_attributes.rb index 06f03578a2e2..dc00970bc9fb 100644 --- a/lib/datadog_api_client/v2/models/monitor_notification_rule_attributes.rb +++ b/lib/datadog_api_client/v2/models/monitor_notification_rule_attributes.rb @@ -21,6 +21,9 @@ module DatadogAPIClient::V2 class MonitorNotificationRuleAttributes include BaseGenericModel + # Use conditional recipients to define different recipients for different situations. + attr_accessor :conditional_recipients + # Filter used to associate the notification rule with monitors. attr_accessor :filter @@ -34,6 +37,7 @@ class MonitorNotificationRuleAttributes # @!visibility private def self.attribute_map { + :'conditional_recipients' => :'conditional_recipients', :'filter' => :'filter', :'name' => :'name', :'recipients' => :'recipients' @@ -44,6 +48,7 @@ def self.attribute_map # @!visibility private def self.openapi_types { + :'conditional_recipients' => :'MonitorNotificationRuleConditionalRecipients', :'filter' => :'MonitorNotificationRuleFilter', :'name' => :'String', :'recipients' => :'Array' @@ -66,6 +71,10 @@ def initialize(attributes = {}) h[k.to_sym] = v } + if attributes.key?(:'conditional_recipients') + self.conditional_recipients = attributes[:'conditional_recipients'] + end + if attributes.key?(:'filter') self.filter = attributes[:'filter'] end @@ -88,9 +97,8 @@ def valid? return false if @name.nil? return false if @name.to_s.length > 1000 return false if @name.to_s.length < 1 - return false if @recipients.nil? - return false if @recipients.length > 20 - return false if @recipients.length < 1 + return false if !@recipients.nil? && @recipients.length > 20 + return false if !@recipients.nil? && @recipients.length < 1 true end @@ -114,13 +122,10 @@ def name=(name) # @param recipients [Object] Object to be assigned # @!visibility private def recipients=(recipients) - if recipients.nil? - fail ArgumentError, 'invalid value for "recipients", recipients cannot be nil.' - end - if recipients.length > 20 + if !recipients.nil? && recipients.length > 20 fail ArgumentError, 'invalid value for "recipients", number of items must be less than or equal to 20.' end - if recipients.length < 1 + if !recipients.nil? && recipients.length < 1 fail ArgumentError, 'invalid value for "recipients", number of items must be greater than or equal to 1.' end @recipients = recipients @@ -132,6 +137,7 @@ def recipients=(recipients) def ==(o) return true if self.equal?(o) self.class == o.class && + conditional_recipients == o.conditional_recipients && filter == o.filter && name == o.name && recipients == o.recipients @@ -141,7 +147,7 @@ def ==(o) # @return [Integer] Hash code # @!visibility private def hash - [filter, name, recipients].hash + [conditional_recipients, filter, name, recipients].hash end end end diff --git a/lib/datadog_api_client/v2/models/monitor_notification_rule_condition.rb b/lib/datadog_api_client/v2/models/monitor_notification_rule_condition.rb new file mode 100644 index 000000000000..484d7221815d --- /dev/null +++ b/lib/datadog_api_client/v2/models/monitor_notification_rule_condition.rb @@ -0,0 +1,162 @@ +=begin +#Datadog API V2 Collection + +#Collection of all Datadog Public endpoints. + +The version of the OpenAPI document: 1.0 +Contact: support@datadoghq.com +Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator + + 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 2020-Present Datadog, Inc. + +=end + +require 'date' +require 'time' + +module DatadogAPIClient::V2 + # Conditions for `conditional_recipients`. + class MonitorNotificationRuleCondition + include BaseGenericModel + + # A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. + attr_reader :recipients + + # The scope to which the monitor applied. + attr_reader :scope + + attr_accessor :additional_properties + + # Attribute mapping from ruby-style variable name to JSON key. + # @!visibility private + def self.attribute_map + { + :'recipients' => :'recipients', + :'scope' => :'scope' + } + end + + # Attribute type mapping. + # @!visibility private + def self.openapi_types + { + :'recipients' => :'Array', + :'scope' => :'String' + } + end + + # Initializes the object + # @param attributes [Hash] Model attributes in the form of hash + # @!visibility private + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `DatadogAPIClient::V2::MonitorNotificationRuleCondition` initialize method" + end + + self.additional_properties = {} + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + self.additional_properties[k.to_sym] = v + else + h[k.to_sym] = v + end + } + + if attributes.key?(:'recipients') + if (value = attributes[:'recipients']).is_a?(Array) + self.recipients = value + end + end + + if attributes.key?(:'scope') + self.scope = attributes[:'scope'] + end + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + # @!visibility private + def valid? + return false if @recipients.nil? + return false if @recipients.length > 20 + return false if @recipients.length < 1 + return false if @scope.nil? + return false if @scope.to_s.length > 3000 + return false if @scope.to_s.length < 1 + true + end + + # Custom attribute writer method with validation + # @param recipients [Object] Object to be assigned + # @!visibility private + def recipients=(recipients) + if recipients.nil? + fail ArgumentError, 'invalid value for "recipients", recipients cannot be nil.' + end + if recipients.length > 20 + fail ArgumentError, 'invalid value for "recipients", number of items must be less than or equal to 20.' + end + if recipients.length < 1 + fail ArgumentError, 'invalid value for "recipients", number of items must be greater than or equal to 1.' + end + @recipients = recipients + end + + # Custom attribute writer method with validation + # @param scope [Object] Object to be assigned + # @!visibility private + def scope=(scope) + if scope.nil? + fail ArgumentError, 'invalid value for "scope", scope cannot be nil.' + end + if scope.to_s.length > 3000 + fail ArgumentError, 'invalid value for "scope", the character length must be smaller than or equal to 3000.' + end + if scope.to_s.length < 1 + fail ArgumentError, 'invalid value for "scope", the character length must be great than or equal to 1.' + end + @scope = scope + end + + # Returns the object in the form of hash, with additionalProperties support. + # @return [Hash] Returns the object in the form of hash + # @!visibility private + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + self.additional_properties.each_pair do |attr, value| + hash[attr] = value + end + hash + end + + # Checks equality by comparing each attribute. + # @param o [Object] Object to be compared + # @!visibility private + def ==(o) + return true if self.equal?(o) + self.class == o.class && + recipients == o.recipients && + scope == o.scope && + additional_properties == o.additional_properties + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + # @!visibility private + def hash + [recipients, scope, additional_properties].hash + end + end +end diff --git a/lib/datadog_api_client/v2/models/monitor_notification_rule_conditional_recipients.rb b/lib/datadog_api_client/v2/models/monitor_notification_rule_conditional_recipients.rb new file mode 100644 index 000000000000..90cc142ac339 --- /dev/null +++ b/lib/datadog_api_client/v2/models/monitor_notification_rule_conditional_recipients.rb @@ -0,0 +1,160 @@ +=begin +#Datadog API V2 Collection + +#Collection of all Datadog Public endpoints. + +The version of the OpenAPI document: 1.0 +Contact: support@datadoghq.com +Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator + + 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 2020-Present Datadog, Inc. + +=end + +require 'date' +require 'time' + +module DatadogAPIClient::V2 + # Use conditional recipients to define different recipients for different situations. + class MonitorNotificationRuleConditionalRecipients + include BaseGenericModel + + # Conditions of the notification rule. + attr_reader :conditions + + # A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. + attr_reader :fallback_recipients + + attr_accessor :additional_properties + + # Attribute mapping from ruby-style variable name to JSON key. + # @!visibility private + def self.attribute_map + { + :'conditions' => :'conditions', + :'fallback_recipients' => :'fallback_recipients' + } + end + + # Attribute type mapping. + # @!visibility private + def self.openapi_types + { + :'conditions' => :'Array', + :'fallback_recipients' => :'Array' + } + end + + # Initializes the object + # @param attributes [Hash] Model attributes in the form of hash + # @!visibility private + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `DatadogAPIClient::V2::MonitorNotificationRuleConditionalRecipients` initialize method" + end + + self.additional_properties = {} + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + self.additional_properties[k.to_sym] = v + else + h[k.to_sym] = v + end + } + + if attributes.key?(:'conditions') + if (value = attributes[:'conditions']).is_a?(Array) + self.conditions = value + end + end + + if attributes.key?(:'fallback_recipients') + if (value = attributes[:'fallback_recipients']).is_a?(Array) + self.fallback_recipients = value + end + end + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + # @!visibility private + def valid? + return false if @conditions.nil? + return false if @conditions.length > 10 + return false if @conditions.length < 1 + return false if !@fallback_recipients.nil? && @fallback_recipients.length > 20 + return false if !@fallback_recipients.nil? && @fallback_recipients.length < 1 + true + end + + # Custom attribute writer method with validation + # @param conditions [Object] Object to be assigned + # @!visibility private + def conditions=(conditions) + if conditions.nil? + fail ArgumentError, 'invalid value for "conditions", conditions cannot be nil.' + end + if conditions.length > 10 + fail ArgumentError, 'invalid value for "conditions", number of items must be less than or equal to 10.' + end + if conditions.length < 1 + fail ArgumentError, 'invalid value for "conditions", number of items must be greater than or equal to 1.' + end + @conditions = conditions + end + + # Custom attribute writer method with validation + # @param fallback_recipients [Object] Object to be assigned + # @!visibility private + def fallback_recipients=(fallback_recipients) + if !fallback_recipients.nil? && fallback_recipients.length > 20 + fail ArgumentError, 'invalid value for "fallback_recipients", number of items must be less than or equal to 20.' + end + if !fallback_recipients.nil? && fallback_recipients.length < 1 + fail ArgumentError, 'invalid value for "fallback_recipients", number of items must be greater than or equal to 1.' + end + @fallback_recipients = fallback_recipients + end + + # Returns the object in the form of hash, with additionalProperties support. + # @return [Hash] Returns the object in the form of hash + # @!visibility private + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + self.additional_properties.each_pair do |attr, value| + hash[attr] = value + end + hash + end + + # Checks equality by comparing each attribute. + # @param o [Object] Object to be compared + # @!visibility private + def ==(o) + return true if self.equal?(o) + self.class == o.class && + conditions == o.conditions && + fallback_recipients == o.fallback_recipients && + additional_properties == o.additional_properties + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + # @!visibility private + def hash + [conditions, fallback_recipients, additional_properties].hash + end + end +end diff --git a/lib/datadog_api_client/v2/models/monitor_notification_rule_response_attributes.rb b/lib/datadog_api_client/v2/models/monitor_notification_rule_response_attributes.rb index e8433b1a00d5..3656f9818315 100644 --- a/lib/datadog_api_client/v2/models/monitor_notification_rule_response_attributes.rb +++ b/lib/datadog_api_client/v2/models/monitor_notification_rule_response_attributes.rb @@ -21,6 +21,9 @@ module DatadogAPIClient::V2 class MonitorNotificationRuleResponseAttributes include BaseGenericModel + # Use conditional recipients to define different recipients for different situations. + attr_accessor :conditional_recipients + # Creation time of the monitor notification rule. attr_accessor :created @@ -42,6 +45,7 @@ class MonitorNotificationRuleResponseAttributes # @!visibility private def self.attribute_map { + :'conditional_recipients' => :'conditional_recipients', :'created' => :'created', :'filter' => :'filter', :'modified' => :'modified', @@ -54,6 +58,7 @@ def self.attribute_map # @!visibility private def self.openapi_types { + :'conditional_recipients' => :'MonitorNotificationRuleConditionalRecipients', :'created' => :'Time', :'filter' => :'MonitorNotificationRuleFilter', :'modified' => :'Time', @@ -80,6 +85,10 @@ def initialize(attributes = {}) end } + if attributes.key?(:'conditional_recipients') + self.conditional_recipients = attributes[:'conditional_recipients'] + end + if attributes.key?(:'created') self.created = attributes[:'created'] end @@ -166,6 +175,7 @@ def to_hash def ==(o) return true if self.equal?(o) self.class == o.class && + conditional_recipients == o.conditional_recipients && created == o.created && filter == o.filter && modified == o.modified && @@ -178,7 +188,7 @@ def ==(o) # @return [Integer] Hash code # @!visibility private def hash - [created, filter, modified, name, recipients, additional_properties].hash + [conditional_recipients, created, filter, modified, name, recipients, additional_properties].hash end end end