-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation endpoint for Security Monitoring Rules (#2251)
Co-authored-by: ci.datadog-api-spec <[email protected]>
- Loading branch information
1 parent
42625b8
commit 32eb45b
Showing
10 changed files
with
316 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
examples/v2/security-monitoring/ValidateSecurityMonitoringRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Validate a detection 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.SecurityMonitoringRuleCaseCreate; | ||
import com.datadog.api.client.v2.model.SecurityMonitoringRuleCreatePayload; | ||
import com.datadog.api.client.v2.model.SecurityMonitoringRuleDetectionMethod; | ||
import com.datadog.api.client.v2.model.SecurityMonitoringRuleEvaluationWindow; | ||
import com.datadog.api.client.v2.model.SecurityMonitoringRuleKeepAlive; | ||
import com.datadog.api.client.v2.model.SecurityMonitoringRuleMaxSignalDuration; | ||
import com.datadog.api.client.v2.model.SecurityMonitoringRuleOptions; | ||
import com.datadog.api.client.v2.model.SecurityMonitoringRuleQueryAggregation; | ||
import com.datadog.api.client.v2.model.SecurityMonitoringRuleSeverity; | ||
import com.datadog.api.client.v2.model.SecurityMonitoringRuleTypeCreate; | ||
import com.datadog.api.client.v2.model.SecurityMonitoringStandardRuleCreatePayload; | ||
import com.datadog.api.client.v2.model.SecurityMonitoringStandardRuleQuery; | ||
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); | ||
|
||
SecurityMonitoringRuleCreatePayload body = | ||
new SecurityMonitoringRuleCreatePayload( | ||
new SecurityMonitoringStandardRuleCreatePayload() | ||
.cases( | ||
Collections.singletonList( | ||
new SecurityMonitoringRuleCaseCreate() | ||
.name("") | ||
.status(SecurityMonitoringRuleSeverity.INFO) | ||
.condition("a > 0"))) | ||
.hasExtendedTitle(true) | ||
.isEnabled(true) | ||
.message("My security monitoring rule") | ||
.name("My security monitoring rule") | ||
.options( | ||
new SecurityMonitoringRuleOptions() | ||
.evaluationWindow(SecurityMonitoringRuleEvaluationWindow.THIRTY_MINUTES) | ||
.keepAlive(SecurityMonitoringRuleKeepAlive.THIRTY_MINUTES) | ||
.maxSignalDuration(SecurityMonitoringRuleMaxSignalDuration.THIRTY_MINUTES) | ||
.detectionMethod(SecurityMonitoringRuleDetectionMethod.THRESHOLD)) | ||
.queries( | ||
Collections.singletonList( | ||
new SecurityMonitoringStandardRuleQuery() | ||
.query("source:source_here") | ||
.groupByFields(Collections.singletonList("@userIdentity.assumed_role")) | ||
.aggregation(SecurityMonitoringRuleQueryAggregation.COUNT) | ||
.name(""))) | ||
.tags(Arrays.asList("env:prod", "team:security")) | ||
.type(SecurityMonitoringRuleTypeCreate.LOG_DETECTION)); | ||
|
||
try { | ||
apiInstance.validateSecurityMonitoringRule(body); | ||
} catch (ApiException e) { | ||
System.err.println( | ||
"Exception when calling SecurityMonitoringApi#validateSecurityMonitoringRule"); | ||
System.err.println("Status code: " + e.getCode()); | ||
System.err.println("Reason: " + e.getResponseBody()); | ||
System.err.println("Response headers: " + e.getResponseHeaders()); | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...urces/cassettes/features/v2/Validate_a_detection_rule_returns_Bad_Request_response.freeze
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2024-03-27T16:23:09.814Z |
32 changes: 32 additions & 0 deletions
32
...sources/cassettes/features/v2/Validate_a_detection_rule_returns_Bad_Request_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[ | ||
{ | ||
"httpRequest": { | ||
"body": { | ||
"type": "JSON", | ||
"json": "{\"cases\":[{\"condition\":\"a > 0\",\"name\":\"\",\"notifications\":[],\"status\":\"info\"}],\"hasExtendedTitle\":true,\"isEnabled\":true,\"message\":\"My security monitoring rule\",\"name\":\"My security monitoring rule\",\"options\":{\"detectionMethod\":\"threshold\",\"evaluationWindow\":1800,\"keepAlive\":999999,\"maxSignalDuration\":1800},\"queries\":[{\"aggregation\":\"count\",\"distinctFields\":[],\"groupByFields\":[\"@userIdentity.assumed_role\"],\"name\":\"\",\"query\":\"source:source_here\"}],\"tags\":[\"env:prod\",\"team:security\"],\"type\":\"log_detection\"}" | ||
}, | ||
"headers": {}, | ||
"method": "POST", | ||
"path": "/api/v2/security_monitoring/rules/validation", | ||
"keepAlive": false, | ||
"secure": true | ||
}, | ||
"httpResponse": { | ||
"body": "{\"error\":{\"code\":\"InvalidArgument\",\"message\":\"Invalid rule configuration\",\"details\":[{\"code\":\"InvalidArgument\",\"message\":\"Max signal duration must be greater than or equal to keep alive\",\"target\":\"maxSignalDuration\"},{\"code\":\"InvalidArgument\",\"message\":\"Keep alive is not in allowed durations: 0, 1, 5, 10, 15, 30, 60, 120, 180, 360 (in minutes)\",\"target\":\"keepAlive\"}]}}\n", | ||
"headers": { | ||
"Content-Type": [ | ||
"application/json" | ||
] | ||
}, | ||
"statusCode": 400, | ||
"reasonPhrase": "Bad Request" | ||
}, | ||
"times": { | ||
"remainingTimes": 1 | ||
}, | ||
"timeToLive": { | ||
"unlimited": true | ||
}, | ||
"id": "195f214f-cab0-861b-1336-ce2aa07b9cf5" | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
...test/resources/cassettes/features/v2/Validate_a_detection_rule_returns_OK_response.freeze
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2024-03-27T16:23:10.157Z |
31 changes: 31 additions & 0 deletions
31
src/test/resources/cassettes/features/v2/Validate_a_detection_rule_returns_OK_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[ | ||
{ | ||
"httpRequest": { | ||
"body": { | ||
"type": "JSON", | ||
"json": "{\"cases\":[{\"condition\":\"a > 0\",\"name\":\"\",\"notifications\":[],\"status\":\"info\"}],\"hasExtendedTitle\":true,\"isEnabled\":true,\"message\":\"My security monitoring rule\",\"name\":\"My security monitoring rule\",\"options\":{\"detectionMethod\":\"threshold\",\"evaluationWindow\":1800,\"keepAlive\":1800,\"maxSignalDuration\":1800},\"queries\":[{\"aggregation\":\"count\",\"distinctFields\":[],\"groupByFields\":[\"@userIdentity.assumed_role\"],\"name\":\"\",\"query\":\"source:source_here\"}],\"tags\":[\"env:prod\",\"team:security\"],\"type\":\"log_detection\"}" | ||
}, | ||
"headers": {}, | ||
"method": "POST", | ||
"path": "/api/v2/security_monitoring/rules/validation", | ||
"keepAlive": false, | ||
"secure": true | ||
}, | ||
"httpResponse": { | ||
"headers": { | ||
"Content-Type": [ | ||
"text/html; charset=utf-8" | ||
] | ||
}, | ||
"statusCode": 204, | ||
"reasonPhrase": "No Content" | ||
}, | ||
"times": { | ||
"remainingTimes": 1 | ||
}, | ||
"timeToLive": { | ||
"unlimited": true | ||
}, | ||
"id": "eff24aa1-fc7c-d68e-5815-6e52bbac0e73" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters