diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 74b9de40104..4eb200d8854 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -23283,6 +23283,8 @@ components: $ref: "#/components/schemas/Enabled" name: $ref: "#/components/schemas/RuleName" + routing: + $ref: "#/components/schemas/NotificationRuleRouting" selectors: $ref: "#/components/schemas/Selectors" targets: @@ -57809,6 +57811,72 @@ components: - targets - version type: object + NotificationRulePreviewNotificationStatus: + description: The notification status for the given rule type. `SUCCESS` means a matching event was found and the notification was sent successfully. `DEFAULT` means no matching event was found and a default placeholder notification was sent instead. `ERROR` means an error occurred while sending the notification. + enum: + - SUCCESS + - DEFAULT + - ERROR + example: SUCCESS + type: string + x-enum-varnames: + - SUCCESS + - DEFAULT + - ERROR + NotificationRulePreviewResponse: + description: Response from the notification preview request. + properties: + data: + $ref: "#/components/schemas/NotificationRulePreviewResponseData" + required: + - data + type: object + NotificationRulePreviewResponseAttributes: + description: Attributes of the notification preview response. + properties: + preview_results: + $ref: "#/components/schemas/NotificationRulePreviewResults" + required: + - preview_results + type: object + NotificationRulePreviewResponseData: + description: The notification preview response data. + properties: + attributes: + $ref: "#/components/schemas/NotificationRulePreviewResponseAttributes" + type: + $ref: "#/components/schemas/NotificationRulePreviewResponseType" + required: + - type + - attributes + type: object + NotificationRulePreviewResponseType: + description: The type of the notification preview response. + enum: + - notification_preview_response + example: notification_preview_response + type: string + x-enum-varnames: + - NOTIFICATION_PREVIEW_RESPONSE + NotificationRulePreviewResult: + description: The preview result for a single rule type. + properties: + notification_status: + $ref: "#/components/schemas/NotificationRulePreviewNotificationStatus" + rule_type: + $ref: "#/components/schemas/RuleTypesItems" + required: + - rule_type + - notification_status + type: object + NotificationRulePreviewResults: + description: List of preview results for each rule type matched by the notification rule. + example: + - notification_status: DEFAULT + rule_type: log_detection + items: + $ref: "#/components/schemas/NotificationRulePreviewResult" + type: array NotificationRuleQuery: description: The query is composed of one or several key:value pairs, which can be used to filter security issues on tags and attributes. example: (source:production_service OR env:prod) @@ -57819,6 +57887,22 @@ components: data: $ref: "#/components/schemas/NotificationRule" type: object + NotificationRuleRouting: + description: Routing configuration for the notification rule. + properties: + mode: + $ref: "#/components/schemas/NotificationRuleRoutingMode" + required: + - mode + type: object + NotificationRuleRoutingMode: + description: The routing mode for the notification rule. `manual` sends notifications to the configured targets. + enum: + - manual + example: manual + type: string + x-enum-varnames: + - MANUAL NotificationRulesType: description: The rule type associated to notification rules. enum: @@ -67052,6 +67136,8 @@ components: $ref: "#/components/schemas/Enabled" name: $ref: "#/components/schemas/RuleName" + routing: + $ref: "#/components/schemas/NotificationRuleRouting" selectors: $ref: "#/components/schemas/Selectors" targets: @@ -73361,6 +73447,7 @@ components: - iac_misconfiguration - sast_vulnerability - secret_vulnerability + example: log_detection type: string x-enum-varnames: - APPLICATION_SECURITY @@ -159547,6 +159634,72 @@ paths: x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + /api/v2/security_monitoring/configuration/notification_rules/send_notification_preview: + post: + description: Send a notification preview to test that a notification rule's targets are properly configured. + operationId: SendSecurityMonitoringNotificationPreview + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + enabled: true + name: Rule 1 + selectors: + query: env:prod + rule_types: + - log_detection + severities: + - critical + trigger_source: security_signals + targets: + - "@john.doe@email.com" + type: notification_rules + schema: + $ref: "#/components/schemas/CreateNotificationRuleParameters" + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + preview_results: + - notification_status: DEFAULT + rule_type: log_detection + type: notification_preview_response + schema: + $ref: "#/components/schemas/NotificationRulePreviewResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "403": + $ref: "#/components/responses/NotAuthorizedResponse" + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - security_monitoring_notification_profiles_read + summary: Test a notification rule + tags: + - Security Monitoring + x-codegen-request-body-name: body + "x-permission": + operator: OR + permissions: + - security_monitoring_notification_profiles_read /api/v2/security_monitoring/configuration/security_filters: get: description: Get the list of configured security filters with their definitions. diff --git a/examples/v2/security-monitoring/SendSecurityMonitoringNotificationPreview.java b/examples/v2/security-monitoring/SendSecurityMonitoringNotificationPreview.java new file mode 100644 index 00000000000..4c24019d2bb --- /dev/null +++ b/examples/v2/security-monitoring/SendSecurityMonitoringNotificationPreview.java @@ -0,0 +1,62 @@ +// Test a notification rule returns "OK" response + +import com.datadog.api.client.ApiClient; +import com.datadog.api.client.ApiException; +import com.datadog.api.client.v2.api.SecurityMonitoringApi; +import com.datadog.api.client.v2.model.CreateNotificationRuleParameters; +import com.datadog.api.client.v2.model.CreateNotificationRuleParametersData; +import com.datadog.api.client.v2.model.CreateNotificationRuleParametersDataAttributes; +import com.datadog.api.client.v2.model.NotificationRulePreviewResponse; +import com.datadog.api.client.v2.model.NotificationRuleRouting; +import com.datadog.api.client.v2.model.NotificationRuleRoutingMode; +import com.datadog.api.client.v2.model.NotificationRulesType; +import com.datadog.api.client.v2.model.RuleSeverity; +import com.datadog.api.client.v2.model.RuleTypesItems; +import com.datadog.api.client.v2.model.Selectors; +import com.datadog.api.client.v2.model.TriggerSource; +import java.util.Arrays; +import java.util.Collections; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = ApiClient.getDefaultApiClient(); + SecurityMonitoringApi apiInstance = new SecurityMonitoringApi(defaultClient); + + CreateNotificationRuleParameters body = + new CreateNotificationRuleParameters() + .data( + new CreateNotificationRuleParametersData() + .attributes( + new CreateNotificationRuleParametersDataAttributes() + .enabled(true) + .name("Rule 1") + .routing( + new NotificationRuleRouting() + .mode(NotificationRuleRoutingMode.MANUAL)) + .selectors( + new Selectors() + .query("(source:production_service OR env:prod)") + .ruleTypes( + Arrays.asList( + RuleTypesItems.MISCONFIGURATION, + RuleTypesItems.ATTACK_PATH)) + .severities(Collections.singletonList(RuleSeverity.CRITICAL)) + .triggerSource(TriggerSource.SECURITY_FINDINGS)) + .targets(Collections.singletonList("@john.doe@email.com")) + .timeAggregation(86400L)) + .type(NotificationRulesType.NOTIFICATION_RULES)); + + try { + NotificationRulePreviewResponse result = + apiInstance.sendSecurityMonitoringNotificationPreview(body); + System.out.println(result); + } catch (ApiException e) { + System.err.println( + "Exception when calling SecurityMonitoringApi#sendSecurityMonitoringNotificationPreview"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/datadog/api/client/v2/api/SecurityMonitoringApi.java b/src/main/java/com/datadog/api/client/v2/api/SecurityMonitoringApi.java index bcb269b2137..c4b3a279aab 100644 --- a/src/main/java/com/datadog/api/client/v2/api/SecurityMonitoringApi.java +++ b/src/main/java/com/datadog/api/client/v2/api/SecurityMonitoringApi.java @@ -56,6 +56,7 @@ import com.datadog.api.client.v2.model.MuteFindingsRequest; import com.datadog.api.client.v2.model.MuteFindingsResponse; import com.datadog.api.client.v2.model.NodeTypesResponse; +import com.datadog.api.client.v2.model.NotificationRulePreviewResponse; import com.datadog.api.client.v2.model.NotificationRuleResponse; import com.datadog.api.client.v2.model.PatchNotificationRuleParameters; import com.datadog.api.client.v2.model.RunHistoricalJobRequest; @@ -21635,6 +21636,149 @@ public PaginationIterable searchSecurityMonitoringSign new GenericType() {}); } + /** + * Test a notification rule. + * + *

See {@link #sendSecurityMonitoringNotificationPreviewWithHttpInfo}. + * + * @param body (required) + * @return NotificationRulePreviewResponse + * @throws ApiException if fails to make API call + */ + public NotificationRulePreviewResponse sendSecurityMonitoringNotificationPreview( + CreateNotificationRuleParameters body) throws ApiException { + return sendSecurityMonitoringNotificationPreviewWithHttpInfo(body).getData(); + } + + /** + * Test a notification rule. + * + *

See {@link #sendSecurityMonitoringNotificationPreviewWithHttpInfoAsync}. + * + * @param body (required) + * @return CompletableFuture<NotificationRulePreviewResponse> + */ + public CompletableFuture + sendSecurityMonitoringNotificationPreviewAsync(CreateNotificationRuleParameters body) { + return sendSecurityMonitoringNotificationPreviewWithHttpInfoAsync(body) + .thenApply( + response -> { + return response.getData(); + }); + } + + /** + * Send a notification preview to test that a notification rule's targets are properly configured. + * + * @param body (required) + * @return ApiResponse<NotificationRulePreviewResponse> + * @throws ApiException if fails to make API call + * @http.response.details + * + * + * + * + * + * + * + *
Response details
Status Code Description Response Headers
200 OK -
400 Bad Request -
403 Not Authorized -
429 Too many requests -
+ */ + public ApiResponse + sendSecurityMonitoringNotificationPreviewWithHttpInfo(CreateNotificationRuleParameters body) + throws ApiException { + Object localVarPostBody = body; + + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException( + 400, + "Missing the required parameter 'body' when calling" + + " sendSecurityMonitoringNotificationPreview"); + } + // create path and map variables + String localVarPath = + "/api/v2/security_monitoring/configuration/notification_rules/send_notification_preview"; + + Map localVarHeaderParams = new HashMap(); + + Invocation.Builder builder = + apiClient.createBuilder( + "v2.SecurityMonitoringApi.sendSecurityMonitoringNotificationPreview", + localVarPath, + new ArrayList(), + localVarHeaderParams, + new HashMap(), + new String[] {"application/json"}, + new String[] {"apiKeyAuth", "appKeyAuth", "AuthZ"}); + return apiClient.invokeAPI( + "POST", + builder, + localVarHeaderParams, + new String[] {"application/json"}, + localVarPostBody, + new HashMap(), + false, + new GenericType() {}); + } + + /** + * Test a notification rule. + * + *

See {@link #sendSecurityMonitoringNotificationPreviewWithHttpInfo}. + * + * @param body (required) + * @return CompletableFuture<ApiResponse<NotificationRulePreviewResponse>> + */ + public CompletableFuture> + sendSecurityMonitoringNotificationPreviewWithHttpInfoAsync( + CreateNotificationRuleParameters body) { + Object localVarPostBody = body; + + // verify the required parameter 'body' is set + if (body == null) { + CompletableFuture> result = + new CompletableFuture<>(); + result.completeExceptionally( + new ApiException( + 400, + "Missing the required parameter 'body' when calling" + + " sendSecurityMonitoringNotificationPreview")); + return result; + } + // create path and map variables + String localVarPath = + "/api/v2/security_monitoring/configuration/notification_rules/send_notification_preview"; + + Map localVarHeaderParams = new HashMap(); + + Invocation.Builder builder; + try { + builder = + apiClient.createBuilder( + "v2.SecurityMonitoringApi.sendSecurityMonitoringNotificationPreview", + localVarPath, + new ArrayList(), + localVarHeaderParams, + new HashMap(), + new String[] {"application/json"}, + new String[] {"apiKeyAuth", "appKeyAuth", "AuthZ"}); + } catch (ApiException ex) { + CompletableFuture> result = + new CompletableFuture<>(); + result.completeExceptionally(ex); + return result; + } + return apiClient.invokeAPIAsync( + "POST", + builder, + localVarHeaderParams, + new String[] {"application/json"}, + localVarPostBody, + new HashMap(), + false, + new GenericType() {}); + } + /** * Test an existing rule. * diff --git a/src/main/java/com/datadog/api/client/v2/model/CreateNotificationRuleParametersDataAttributes.java b/src/main/java/com/datadog/api/client/v2/model/CreateNotificationRuleParametersDataAttributes.java index 61125836b26..8551ea4d74f 100644 --- a/src/main/java/com/datadog/api/client/v2/model/CreateNotificationRuleParametersDataAttributes.java +++ b/src/main/java/com/datadog/api/client/v2/model/CreateNotificationRuleParametersDataAttributes.java @@ -23,6 +23,7 @@ @JsonPropertyOrder({ CreateNotificationRuleParametersDataAttributes.JSON_PROPERTY_ENABLED, CreateNotificationRuleParametersDataAttributes.JSON_PROPERTY_NAME, + CreateNotificationRuleParametersDataAttributes.JSON_PROPERTY_ROUTING, CreateNotificationRuleParametersDataAttributes.JSON_PROPERTY_SELECTORS, CreateNotificationRuleParametersDataAttributes.JSON_PROPERTY_TARGETS, CreateNotificationRuleParametersDataAttributes.JSON_PROPERTY_TIME_AGGREGATION @@ -37,6 +38,9 @@ public class CreateNotificationRuleParametersDataAttributes { public static final String JSON_PROPERTY_NAME = "name"; private String name; + public static final String JSON_PROPERTY_ROUTING = "routing"; + private NotificationRuleRouting routing; + public static final String JSON_PROPERTY_SELECTORS = "selectors"; private Selectors selectors; @@ -100,6 +104,28 @@ public void setName(String name) { this.name = name; } + public CreateNotificationRuleParametersDataAttributes routing(NotificationRuleRouting routing) { + this.routing = routing; + this.unparsed |= routing.unparsed; + return this; + } + + /** + * Routing configuration for the notification rule. + * + * @return routing + */ + @jakarta.annotation.Nullable + @JsonProperty(JSON_PROPERTY_ROUTING) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public NotificationRuleRouting getRouting() { + return routing; + } + + public void setRouting(NotificationRuleRouting routing) { + this.routing = routing; + } + public CreateNotificationRuleParametersDataAttributes selectors(Selectors selectors) { this.selectors = selectors; this.unparsed |= selectors.unparsed; @@ -235,6 +261,7 @@ public boolean equals(Object o) { (CreateNotificationRuleParametersDataAttributes) o; return Objects.equals(this.enabled, createNotificationRuleParametersDataAttributes.enabled) && Objects.equals(this.name, createNotificationRuleParametersDataAttributes.name) + && Objects.equals(this.routing, createNotificationRuleParametersDataAttributes.routing) && Objects.equals(this.selectors, createNotificationRuleParametersDataAttributes.selectors) && Objects.equals(this.targets, createNotificationRuleParametersDataAttributes.targets) && Objects.equals( @@ -246,7 +273,8 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(enabled, name, selectors, targets, timeAggregation, additionalProperties); + return Objects.hash( + enabled, name, routing, selectors, targets, timeAggregation, additionalProperties); } @Override @@ -255,6 +283,7 @@ public String toString() { sb.append("class CreateNotificationRuleParametersDataAttributes {\n"); sb.append(" enabled: ").append(toIndentedString(enabled)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" routing: ").append(toIndentedString(routing)).append("\n"); sb.append(" selectors: ").append(toIndentedString(selectors)).append("\n"); sb.append(" targets: ").append(toIndentedString(targets)).append("\n"); sb.append(" timeAggregation: ").append(toIndentedString(timeAggregation)).append("\n"); diff --git a/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewNotificationStatus.java b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewNotificationStatus.java new file mode 100644 index 00000000000..7645185a225 --- /dev/null +++ b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewNotificationStatus.java @@ -0,0 +1,72 @@ +/* + * 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 com.datadog.api.client.v2.model; + +import com.datadog.api.client.ModelEnum; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * The notification status for the given rule type. SUCCESS means a matching event was + * found and the notification was sent successfully. DEFAULT means no matching event + * was found and a default placeholder notification was sent instead. ERROR means an + * error occurred while sending the notification. + */ +@JsonSerialize( + using = + NotificationRulePreviewNotificationStatus + .NotificationRulePreviewNotificationStatusSerializer.class) +public class NotificationRulePreviewNotificationStatus extends ModelEnum { + + private static final Set allowedValues = + new HashSet(Arrays.asList("SUCCESS", "DEFAULT", "ERROR")); + + public static final NotificationRulePreviewNotificationStatus SUCCESS = + new NotificationRulePreviewNotificationStatus("SUCCESS"); + public static final NotificationRulePreviewNotificationStatus DEFAULT = + new NotificationRulePreviewNotificationStatus("DEFAULT"); + public static final NotificationRulePreviewNotificationStatus ERROR = + new NotificationRulePreviewNotificationStatus("ERROR"); + + NotificationRulePreviewNotificationStatus(String value) { + super(value, allowedValues); + } + + public static class NotificationRulePreviewNotificationStatusSerializer + extends StdSerializer { + public NotificationRulePreviewNotificationStatusSerializer( + Class t) { + super(t); + } + + public NotificationRulePreviewNotificationStatusSerializer() { + this(null); + } + + @Override + public void serialize( + NotificationRulePreviewNotificationStatus value, + JsonGenerator jgen, + SerializerProvider provider) + throws IOException, JsonProcessingException { + jgen.writeObject(value.value); + } + } + + @JsonCreator + public static NotificationRulePreviewNotificationStatus fromValue(String value) { + return new NotificationRulePreviewNotificationStatus(value); + } +} diff --git a/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponse.java b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponse.java new file mode 100644 index 00000000000..26c540f15e3 --- /dev/null +++ b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponse.java @@ -0,0 +1,148 @@ +/* + * 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 com.datadog.api.client.v2.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** Response from the notification preview request. */ +@JsonPropertyOrder({NotificationRulePreviewResponse.JSON_PROPERTY_DATA}) +@jakarta.annotation.Generated( + value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator") +public class NotificationRulePreviewResponse { + @JsonIgnore public boolean unparsed = false; + public static final String JSON_PROPERTY_DATA = "data"; + private NotificationRulePreviewResponseData data; + + public NotificationRulePreviewResponse() {} + + @JsonCreator + public NotificationRulePreviewResponse( + @JsonProperty(required = true, value = JSON_PROPERTY_DATA) + NotificationRulePreviewResponseData data) { + this.data = data; + this.unparsed |= data.unparsed; + } + + public NotificationRulePreviewResponse data(NotificationRulePreviewResponseData data) { + this.data = data; + this.unparsed |= data.unparsed; + return this; + } + + /** + * The notification preview response data. + * + * @return data + */ + @JsonProperty(JSON_PROPERTY_DATA) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public NotificationRulePreviewResponseData getData() { + return data; + } + + public void setData(NotificationRulePreviewResponseData data) { + this.data = data; + } + + /** + * A container for additional, undeclared properties. This is a holder for any undeclared + * properties as specified with the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. If the property + * does not already exist, create it otherwise replace it. + * + * @param key The arbitrary key to set + * @param value The associated value + * @return NotificationRulePreviewResponse + */ + @JsonAnySetter + public NotificationRulePreviewResponse putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return The additional properties + */ + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key The arbitrary key to get + * @return The specific additional property for the given key + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + /** Return true if this NotificationRulePreviewResponse object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + NotificationRulePreviewResponse notificationRulePreviewResponse = + (NotificationRulePreviewResponse) o; + return Objects.equals(this.data, notificationRulePreviewResponse.data) + && Objects.equals( + this.additionalProperties, notificationRulePreviewResponse.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(data, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class NotificationRulePreviewResponse {\n"); + sb.append(" data: ").append(toIndentedString(data)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); + sb.append('}'); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponseAttributes.java b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponseAttributes.java new file mode 100644 index 00000000000..da2e5c1bb56 --- /dev/null +++ b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponseAttributes.java @@ -0,0 +1,161 @@ +/* + * 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 com.datadog.api.client.v2.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** Attributes of the notification preview response. */ +@JsonPropertyOrder({NotificationRulePreviewResponseAttributes.JSON_PROPERTY_PREVIEW_RESULTS}) +@jakarta.annotation.Generated( + value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator") +public class NotificationRulePreviewResponseAttributes { + @JsonIgnore public boolean unparsed = false; + public static final String JSON_PROPERTY_PREVIEW_RESULTS = "preview_results"; + private List previewResults = new ArrayList<>(); + + public NotificationRulePreviewResponseAttributes() {} + + @JsonCreator + public NotificationRulePreviewResponseAttributes( + @JsonProperty(required = true, value = JSON_PROPERTY_PREVIEW_RESULTS) + List previewResults) { + this.previewResults = previewResults; + } + + public NotificationRulePreviewResponseAttributes previewResults( + List previewResults) { + this.previewResults = previewResults; + for (NotificationRulePreviewResult item : previewResults) { + this.unparsed |= item.unparsed; + } + return this; + } + + public NotificationRulePreviewResponseAttributes addPreviewResultsItem( + NotificationRulePreviewResult previewResultsItem) { + this.previewResults.add(previewResultsItem); + this.unparsed |= previewResultsItem.unparsed; + return this; + } + + /** + * List of preview results for each rule type matched by the notification rule. + * + * @return previewResults + */ + @JsonProperty(JSON_PROPERTY_PREVIEW_RESULTS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public List getPreviewResults() { + return previewResults; + } + + public void setPreviewResults(List previewResults) { + this.previewResults = previewResults; + } + + /** + * A container for additional, undeclared properties. This is a holder for any undeclared + * properties as specified with the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. If the property + * does not already exist, create it otherwise replace it. + * + * @param key The arbitrary key to set + * @param value The associated value + * @return NotificationRulePreviewResponseAttributes + */ + @JsonAnySetter + public NotificationRulePreviewResponseAttributes putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return The additional properties + */ + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key The arbitrary key to get + * @return The specific additional property for the given key + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + /** Return true if this NotificationRulePreviewResponseAttributes object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + NotificationRulePreviewResponseAttributes notificationRulePreviewResponseAttributes = + (NotificationRulePreviewResponseAttributes) o; + return Objects.equals( + this.previewResults, notificationRulePreviewResponseAttributes.previewResults) + && Objects.equals( + this.additionalProperties, + notificationRulePreviewResponseAttributes.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(previewResults, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class NotificationRulePreviewResponseAttributes {\n"); + sb.append(" previewResults: ").append(toIndentedString(previewResults)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); + sb.append('}'); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponseData.java b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponseData.java new file mode 100644 index 00000000000..67a3f50b496 --- /dev/null +++ b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponseData.java @@ -0,0 +1,185 @@ +/* + * 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 com.datadog.api.client.v2.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** The notification preview response data. */ +@JsonPropertyOrder({ + NotificationRulePreviewResponseData.JSON_PROPERTY_ATTRIBUTES, + NotificationRulePreviewResponseData.JSON_PROPERTY_TYPE +}) +@jakarta.annotation.Generated( + value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator") +public class NotificationRulePreviewResponseData { + @JsonIgnore public boolean unparsed = false; + public static final String JSON_PROPERTY_ATTRIBUTES = "attributes"; + private NotificationRulePreviewResponseAttributes attributes; + + public static final String JSON_PROPERTY_TYPE = "type"; + private NotificationRulePreviewResponseType type; + + public NotificationRulePreviewResponseData() {} + + @JsonCreator + public NotificationRulePreviewResponseData( + @JsonProperty(required = true, value = JSON_PROPERTY_ATTRIBUTES) + NotificationRulePreviewResponseAttributes attributes, + @JsonProperty(required = true, value = JSON_PROPERTY_TYPE) + NotificationRulePreviewResponseType type) { + this.attributes = attributes; + this.unparsed |= attributes.unparsed; + this.type = type; + this.unparsed |= !type.isValid(); + } + + public NotificationRulePreviewResponseData attributes( + NotificationRulePreviewResponseAttributes attributes) { + this.attributes = attributes; + this.unparsed |= attributes.unparsed; + return this; + } + + /** + * Attributes of the notification preview response. + * + * @return attributes + */ + @JsonProperty(JSON_PROPERTY_ATTRIBUTES) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public NotificationRulePreviewResponseAttributes getAttributes() { + return attributes; + } + + public void setAttributes(NotificationRulePreviewResponseAttributes attributes) { + this.attributes = attributes; + } + + public NotificationRulePreviewResponseData type(NotificationRulePreviewResponseType type) { + this.type = type; + this.unparsed |= !type.isValid(); + return this; + } + + /** + * The type of the notification preview response. + * + * @return type + */ + @JsonProperty(JSON_PROPERTY_TYPE) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public NotificationRulePreviewResponseType getType() { + return type; + } + + public void setType(NotificationRulePreviewResponseType type) { + if (!type.isValid()) { + this.unparsed = true; + } + this.type = type; + } + + /** + * A container for additional, undeclared properties. This is a holder for any undeclared + * properties as specified with the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. If the property + * does not already exist, create it otherwise replace it. + * + * @param key The arbitrary key to set + * @param value The associated value + * @return NotificationRulePreviewResponseData + */ + @JsonAnySetter + public NotificationRulePreviewResponseData putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return The additional properties + */ + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key The arbitrary key to get + * @return The specific additional property for the given key + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + /** Return true if this NotificationRulePreviewResponseData object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + NotificationRulePreviewResponseData notificationRulePreviewResponseData = + (NotificationRulePreviewResponseData) o; + return Objects.equals(this.attributes, notificationRulePreviewResponseData.attributes) + && Objects.equals(this.type, notificationRulePreviewResponseData.type) + && Objects.equals( + this.additionalProperties, notificationRulePreviewResponseData.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(attributes, type, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class NotificationRulePreviewResponseData {\n"); + sb.append(" attributes: ").append(toIndentedString(attributes)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); + sb.append('}'); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponseType.java b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponseType.java new file mode 100644 index 00000000000..6ae8dd41c9f --- /dev/null +++ b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResponseType.java @@ -0,0 +1,59 @@ +/* + * 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 com.datadog.api.client.v2.model; + +import com.datadog.api.client.ModelEnum; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** The type of the notification preview response. */ +@JsonSerialize( + using = NotificationRulePreviewResponseType.NotificationRulePreviewResponseTypeSerializer.class) +public class NotificationRulePreviewResponseType extends ModelEnum { + + private static final Set allowedValues = + new HashSet(Arrays.asList("notification_preview_response")); + + public static final NotificationRulePreviewResponseType NOTIFICATION_PREVIEW_RESPONSE = + new NotificationRulePreviewResponseType("notification_preview_response"); + + NotificationRulePreviewResponseType(String value) { + super(value, allowedValues); + } + + public static class NotificationRulePreviewResponseTypeSerializer + extends StdSerializer { + public NotificationRulePreviewResponseTypeSerializer( + Class t) { + super(t); + } + + public NotificationRulePreviewResponseTypeSerializer() { + this(null); + } + + @Override + public void serialize( + NotificationRulePreviewResponseType value, JsonGenerator jgen, SerializerProvider provider) + throws IOException, JsonProcessingException { + jgen.writeObject(value.value); + } + } + + @JsonCreator + public static NotificationRulePreviewResponseType fromValue(String value) { + return new NotificationRulePreviewResponseType(value); + } +} diff --git a/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResult.java b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResult.java new file mode 100644 index 00000000000..3a63f5a623a --- /dev/null +++ b/src/main/java/com/datadog/api/client/v2/model/NotificationRulePreviewResult.java @@ -0,0 +1,195 @@ +/* + * 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 com.datadog.api.client.v2.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** The preview result for a single rule type. */ +@JsonPropertyOrder({ + NotificationRulePreviewResult.JSON_PROPERTY_NOTIFICATION_STATUS, + NotificationRulePreviewResult.JSON_PROPERTY_RULE_TYPE +}) +@jakarta.annotation.Generated( + value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator") +public class NotificationRulePreviewResult { + @JsonIgnore public boolean unparsed = false; + public static final String JSON_PROPERTY_NOTIFICATION_STATUS = "notification_status"; + private NotificationRulePreviewNotificationStatus notificationStatus; + + public static final String JSON_PROPERTY_RULE_TYPE = "rule_type"; + private RuleTypesItems ruleType; + + public NotificationRulePreviewResult() {} + + @JsonCreator + public NotificationRulePreviewResult( + @JsonProperty(required = true, value = JSON_PROPERTY_NOTIFICATION_STATUS) + NotificationRulePreviewNotificationStatus notificationStatus, + @JsonProperty(required = true, value = JSON_PROPERTY_RULE_TYPE) RuleTypesItems ruleType) { + this.notificationStatus = notificationStatus; + this.unparsed |= !notificationStatus.isValid(); + this.ruleType = ruleType; + this.unparsed |= !ruleType.isValid(); + } + + public NotificationRulePreviewResult notificationStatus( + NotificationRulePreviewNotificationStatus notificationStatus) { + this.notificationStatus = notificationStatus; + this.unparsed |= !notificationStatus.isValid(); + return this; + } + + /** + * The notification status for the given rule type. SUCCESS means a matching event + * was found and the notification was sent successfully. DEFAULT means no matching + * event was found and a default placeholder notification was sent instead. ERROR + * means an error occurred while sending the notification. + * + * @return notificationStatus + */ + @JsonProperty(JSON_PROPERTY_NOTIFICATION_STATUS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public NotificationRulePreviewNotificationStatus getNotificationStatus() { + return notificationStatus; + } + + public void setNotificationStatus(NotificationRulePreviewNotificationStatus notificationStatus) { + if (!notificationStatus.isValid()) { + this.unparsed = true; + } + this.notificationStatus = notificationStatus; + } + + public NotificationRulePreviewResult ruleType(RuleTypesItems ruleType) { + this.ruleType = ruleType; + this.unparsed |= !ruleType.isValid(); + return this; + } + + /** + * Security rule type which can be used in security rules. Signal-based notification rules can + * filter signals based on rule types application_security, log_detection, workload_security, + * signal_correlation, cloud_configuration and infrastructure_configuration. Vulnerability-based + * notification rules can filter vulnerabilities based on rule types + * application_code_vulnerability, application_library_vulnerability, attack_path, + * container_image_vulnerability, identity_risk, misconfiguration, api_security, + * host_vulnerability, iac_misconfiguration, sast_vulnerability and secret_vulnerability. + * + * @return ruleType + */ + @JsonProperty(JSON_PROPERTY_RULE_TYPE) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public RuleTypesItems getRuleType() { + return ruleType; + } + + public void setRuleType(RuleTypesItems ruleType) { + if (!ruleType.isValid()) { + this.unparsed = true; + } + this.ruleType = ruleType; + } + + /** + * A container for additional, undeclared properties. This is a holder for any undeclared + * properties as specified with the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. If the property + * does not already exist, create it otherwise replace it. + * + * @param key The arbitrary key to set + * @param value The associated value + * @return NotificationRulePreviewResult + */ + @JsonAnySetter + public NotificationRulePreviewResult putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return The additional properties + */ + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key The arbitrary key to get + * @return The specific additional property for the given key + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + /** Return true if this NotificationRulePreviewResult object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + NotificationRulePreviewResult notificationRulePreviewResult = (NotificationRulePreviewResult) o; + return Objects.equals(this.notificationStatus, notificationRulePreviewResult.notificationStatus) + && Objects.equals(this.ruleType, notificationRulePreviewResult.ruleType) + && Objects.equals( + this.additionalProperties, notificationRulePreviewResult.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(notificationStatus, ruleType, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class NotificationRulePreviewResult {\n"); + sb.append(" notificationStatus: ").append(toIndentedString(notificationStatus)).append("\n"); + sb.append(" ruleType: ").append(toIndentedString(ruleType)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); + sb.append('}'); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/src/main/java/com/datadog/api/client/v2/model/NotificationRuleRouting.java b/src/main/java/com/datadog/api/client/v2/model/NotificationRuleRouting.java new file mode 100644 index 00000000000..5d1b6d7d311 --- /dev/null +++ b/src/main/java/com/datadog/api/client/v2/model/NotificationRuleRouting.java @@ -0,0 +1,149 @@ +/* + * 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 com.datadog.api.client.v2.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** Routing configuration for the notification rule. */ +@JsonPropertyOrder({NotificationRuleRouting.JSON_PROPERTY_MODE}) +@jakarta.annotation.Generated( + value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator") +public class NotificationRuleRouting { + @JsonIgnore public boolean unparsed = false; + public static final String JSON_PROPERTY_MODE = "mode"; + private NotificationRuleRoutingMode mode; + + public NotificationRuleRouting() {} + + @JsonCreator + public NotificationRuleRouting( + @JsonProperty(required = true, value = JSON_PROPERTY_MODE) NotificationRuleRoutingMode mode) { + this.mode = mode; + this.unparsed |= !mode.isValid(); + } + + public NotificationRuleRouting mode(NotificationRuleRoutingMode mode) { + this.mode = mode; + this.unparsed |= !mode.isValid(); + return this; + } + + /** + * The routing mode for the notification rule. manual sends notifications to the + * configured targets. + * + * @return mode + */ + @JsonProperty(JSON_PROPERTY_MODE) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public NotificationRuleRoutingMode getMode() { + return mode; + } + + public void setMode(NotificationRuleRoutingMode mode) { + if (!mode.isValid()) { + this.unparsed = true; + } + this.mode = mode; + } + + /** + * A container for additional, undeclared properties. This is a holder for any undeclared + * properties as specified with the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. If the property + * does not already exist, create it otherwise replace it. + * + * @param key The arbitrary key to set + * @param value The associated value + * @return NotificationRuleRouting + */ + @JsonAnySetter + public NotificationRuleRouting putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return The additional properties + */ + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key The arbitrary key to get + * @return The specific additional property for the given key + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + /** Return true if this NotificationRuleRouting object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + NotificationRuleRouting notificationRuleRouting = (NotificationRuleRouting) o; + return Objects.equals(this.mode, notificationRuleRouting.mode) + && Objects.equals(this.additionalProperties, notificationRuleRouting.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(mode, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class NotificationRuleRouting {\n"); + sb.append(" mode: ").append(toIndentedString(mode)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); + sb.append('}'); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/src/main/java/com/datadog/api/client/v2/model/NotificationRuleRoutingMode.java b/src/main/java/com/datadog/api/client/v2/model/NotificationRuleRoutingMode.java new file mode 100644 index 00000000000..c179779cda3 --- /dev/null +++ b/src/main/java/com/datadog/api/client/v2/model/NotificationRuleRoutingMode.java @@ -0,0 +1,59 @@ +/* + * 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 com.datadog.api.client.v2.model; + +import com.datadog.api.client.ModelEnum; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * The routing mode for the notification rule. manual sends notifications to the + * configured targets. + */ +@JsonSerialize(using = NotificationRuleRoutingMode.NotificationRuleRoutingModeSerializer.class) +public class NotificationRuleRoutingMode extends ModelEnum { + + private static final Set allowedValues = new HashSet(Arrays.asList("manual")); + + public static final NotificationRuleRoutingMode MANUAL = + new NotificationRuleRoutingMode("manual"); + + NotificationRuleRoutingMode(String value) { + super(value, allowedValues); + } + + public static class NotificationRuleRoutingModeSerializer + extends StdSerializer { + public NotificationRuleRoutingModeSerializer(Class t) { + super(t); + } + + public NotificationRuleRoutingModeSerializer() { + this(null); + } + + @Override + public void serialize( + NotificationRuleRoutingMode value, JsonGenerator jgen, SerializerProvider provider) + throws IOException, JsonProcessingException { + jgen.writeObject(value.value); + } + } + + @JsonCreator + public static NotificationRuleRoutingMode fromValue(String value) { + return new NotificationRuleRoutingMode(value); + } +} diff --git a/src/main/java/com/datadog/api/client/v2/model/PatchNotificationRuleParametersDataAttributes.java b/src/main/java/com/datadog/api/client/v2/model/PatchNotificationRuleParametersDataAttributes.java index 3b6c2660645..5c92fd73237 100644 --- a/src/main/java/com/datadog/api/client/v2/model/PatchNotificationRuleParametersDataAttributes.java +++ b/src/main/java/com/datadog/api/client/v2/model/PatchNotificationRuleParametersDataAttributes.java @@ -25,6 +25,7 @@ @JsonPropertyOrder({ PatchNotificationRuleParametersDataAttributes.JSON_PROPERTY_ENABLED, PatchNotificationRuleParametersDataAttributes.JSON_PROPERTY_NAME, + PatchNotificationRuleParametersDataAttributes.JSON_PROPERTY_ROUTING, PatchNotificationRuleParametersDataAttributes.JSON_PROPERTY_SELECTORS, PatchNotificationRuleParametersDataAttributes.JSON_PROPERTY_TARGETS, PatchNotificationRuleParametersDataAttributes.JSON_PROPERTY_TIME_AGGREGATION, @@ -40,6 +41,9 @@ public class PatchNotificationRuleParametersDataAttributes { public static final String JSON_PROPERTY_NAME = "name"; private String name; + public static final String JSON_PROPERTY_ROUTING = "routing"; + private NotificationRuleRouting routing; + public static final String JSON_PROPERTY_SELECTORS = "selectors"; private Selectors selectors; @@ -94,6 +98,28 @@ public void setName(String name) { this.name = name; } + public PatchNotificationRuleParametersDataAttributes routing(NotificationRuleRouting routing) { + this.routing = routing; + this.unparsed |= routing.unparsed; + return this; + } + + /** + * Routing configuration for the notification rule. + * + * @return routing + */ + @jakarta.annotation.Nullable + @JsonProperty(JSON_PROPERTY_ROUTING) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public NotificationRuleRouting getRouting() { + return routing; + } + + public void setRouting(NotificationRuleRouting routing) { + this.routing = routing; + } + public PatchNotificationRuleParametersDataAttributes selectors(Selectors selectors) { this.selectors = selectors; this.unparsed |= selectors.unparsed; @@ -255,6 +281,7 @@ public boolean equals(Object o) { (PatchNotificationRuleParametersDataAttributes) o; return Objects.equals(this.enabled, patchNotificationRuleParametersDataAttributes.enabled) && Objects.equals(this.name, patchNotificationRuleParametersDataAttributes.name) + && Objects.equals(this.routing, patchNotificationRuleParametersDataAttributes.routing) && Objects.equals(this.selectors, patchNotificationRuleParametersDataAttributes.selectors) && Objects.equals(this.targets, patchNotificationRuleParametersDataAttributes.targets) && Objects.equals( @@ -268,7 +295,7 @@ public boolean equals(Object o) { @Override public int hashCode() { return Objects.hash( - enabled, name, selectors, targets, timeAggregation, version, additionalProperties); + enabled, name, routing, selectors, targets, timeAggregation, version, additionalProperties); } @Override @@ -277,6 +304,7 @@ public String toString() { sb.append("class PatchNotificationRuleParametersDataAttributes {\n"); sb.append(" enabled: ").append(toIndentedString(enabled)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" routing: ").append(toIndentedString(routing)).append("\n"); sb.append(" selectors: ").append(toIndentedString(selectors)).append("\n"); sb.append(" targets: ").append(toIndentedString(targets)).append("\n"); sb.append(" timeAggregation: ").append(toIndentedString(timeAggregation)).append("\n"); diff --git a/src/test/resources/com/datadog/api/client/v2/api/security_monitoring.feature b/src/test/resources/com/datadog/api/client/v2/api/security_monitoring.feature index bae8918780e..aebcb932997 100644 --- a/src/test/resources/com/datadog/api/client/v2/api/security_monitoring.feature +++ b/src/test/resources/com/datadog/api/client/v2/api/security_monitoring.feature @@ -759,7 +759,7 @@ Feature: Security Monitoring @generated @skip @team:DataDog/cloud-security-posture-management Scenario: Create a new signal-based notification rule returns "Bad Request" response Given new "CreateSignalNotificationRule" request - And body with value {"data": {"attributes": {"enabled": true, "name": "Rule 1", "selectors": {"query": "(source:production_service OR env:prod)", "rule_types": ["misconfiguration", "attack_path"], "severities": ["critical"], "trigger_source": "security_findings"}, "targets": ["@john.doe@email.com"], "time_aggregation": 86400}, "type": "notification_rules"}} + And body with value {"data": {"attributes": {"enabled": true, "name": "Rule 1", "routing": {"mode": "manual"}, "selectors": {"query": "(source:production_service OR env:prod)", "rule_types": ["misconfiguration", "attack_path"], "severities": ["critical"], "trigger_source": "security_findings"}, "targets": ["@john.doe@email.com"], "time_aggregation": 86400}, "type": "notification_rules"}} When the request is sent Then the response status is 400 Bad Request @@ -773,7 +773,7 @@ Feature: Security Monitoring @generated @skip @team:DataDog/cloud-security-posture-management Scenario: Create a new vulnerability-based notification rule returns "Bad Request" response Given new "CreateVulnerabilityNotificationRule" request - And body with value {"data": {"attributes": {"enabled": true, "name": "Rule 1", "selectors": {"query": "(source:production_service OR env:prod)", "rule_types": ["misconfiguration", "attack_path"], "severities": ["critical"], "trigger_source": "security_findings"}, "targets": ["@john.doe@email.com"], "time_aggregation": 86400}, "type": "notification_rules"}} + And body with value {"data": {"attributes": {"enabled": true, "name": "Rule 1", "routing": {"mode": "manual"}, "selectors": {"query": "(source:production_service OR env:prod)", "rule_types": ["misconfiguration", "attack_path"], "severities": ["critical"], "trigger_source": "security_findings"}, "targets": ["@john.doe@email.com"], "time_aggregation": 86400}, "type": "notification_rules"}} When the request is sent Then the response status is 400 Bad Request @@ -2470,7 +2470,7 @@ Feature: Security Monitoring Scenario: Patch a signal-based notification rule returns "The server cannot process the request because it contains invalid data." response Given new "PatchSignalNotificationRule" request And request contains "id" parameter from "REPLACE.ME" - And body with value {"data": {"attributes": {"enabled": true, "name": "Rule 1", "selectors": {"query": "(source:production_service OR env:prod)", "rule_types": ["misconfiguration", "attack_path"], "severities": ["critical"], "trigger_source": "security_findings"}, "targets": ["@john.doe@email.com"], "time_aggregation": 86400, "version": 1}, "id": "aaa-bbb-ccc", "type": "notification_rules"}} + And body with value {"data": {"attributes": {"enabled": true, "name": "Rule 1", "routing": {"mode": "manual"}, "selectors": {"query": "(source:production_service OR env:prod)", "rule_types": ["misconfiguration", "attack_path"], "severities": ["critical"], "trigger_source": "security_findings"}, "targets": ["@john.doe@email.com"], "time_aggregation": 86400, "version": 1}, "id": "aaa-bbb-ccc", "type": "notification_rules"}} When the request is sent Then the response status is 422 The server cannot process the request because it contains invalid data. @@ -2504,7 +2504,7 @@ Feature: Security Monitoring Scenario: Patch a vulnerability-based notification rule returns "The server cannot process the request because it contains invalid data." response Given new "PatchVulnerabilityNotificationRule" request And request contains "id" parameter from "REPLACE.ME" - And body with value {"data": {"attributes": {"enabled": true, "name": "Rule 1", "selectors": {"query": "(source:production_service OR env:prod)", "rule_types": ["misconfiguration", "attack_path"], "severities": ["critical"], "trigger_source": "security_findings"}, "targets": ["@john.doe@email.com"], "time_aggregation": 86400, "version": 1}, "id": "aaa-bbb-ccc", "type": "notification_rules"}} + And body with value {"data": {"attributes": {"enabled": true, "name": "Rule 1", "routing": {"mode": "manual"}, "selectors": {"query": "(source:production_service OR env:prod)", "rule_types": ["misconfiguration", "attack_path"], "severities": ["critical"], "trigger_source": "security_findings"}, "targets": ["@john.doe@email.com"], "time_aggregation": 86400, "version": 1}, "id": "aaa-bbb-ccc", "type": "notification_rules"}} When the request is sent Then the response status is 422 The server cannot process the request because it contains invalid data. @@ -2611,6 +2611,20 @@ Feature: Security Monitoring When the request is sent Then the response status is 200 OK + @generated @skip @team:DataDog/k9-cloud-siem + Scenario: Test a notification rule returns "Bad Request" response + Given new "SendSecurityMonitoringNotificationPreview" request + And body with value {"data": {"attributes": {"enabled": true, "name": "Rule 1", "routing": {"mode": "manual"}, "selectors": {"query": "(source:production_service OR env:prod)", "rule_types": ["misconfiguration", "attack_path"], "severities": ["critical"], "trigger_source": "security_findings"}, "targets": ["@john.doe@email.com"], "time_aggregation": 86400}, "type": "notification_rules"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/k9-cloud-siem + Scenario: Test a notification rule returns "OK" response + Given new "SendSecurityMonitoringNotificationPreview" request + And body with value {"data": {"attributes": {"enabled": true, "name": "Rule 1", "routing": {"mode": "manual"}, "selectors": {"query": "(source:production_service OR env:prod)", "rule_types": ["misconfiguration", "attack_path"], "severities": ["critical"], "trigger_source": "security_findings"}, "targets": ["@john.doe@email.com"], "time_aggregation": 86400}, "type": "notification_rules"}} + When the request is sent + Then the response status is 200 OK + @skip @team:DataDog/k9-cloud-siem Scenario: Test a rule returns "Bad Request" response Given new "TestSecurityMonitoringRule" request diff --git a/src/test/resources/com/datadog/api/client/v2/api/undo.json b/src/test/resources/com/datadog/api/client/v2/api/undo.json index bf8c214ecee..01574cd4caf 100644 --- a/src/test/resources/com/datadog/api/client/v2/api/undo.json +++ b/src/test/resources/com/datadog/api/client/v2/api/undo.json @@ -6800,6 +6800,12 @@ "type": "safe" } }, + "SendSecurityMonitoringNotificationPreview": { + "tag": "Security Monitoring", + "undo": { + "type": "safe" + } + }, "ListSecurityFilters": { "tag": "Security Monitoring", "undo": {