Skip to content

Commit 4cc844a

Browse files
committed
Add Security Monitoring API to dogshell
1 parent 010d523 commit 4cc844a

8 files changed

+714
-0
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* [Added] Add Cloud SIEM rule management and security signals retrieval.
6+
* [Added] Add dogshell command for security monitoring rule and signal management.
7+
38
## v0.51.0 / 2025-01-27
49

510
* [Added] Add hosts endpoint. See [#884](https://github.com/DataDog/datadogpy/pull/884).

datadog/api/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@
5050
from datadog.api.service_level_objectives import ServiceLevelObjective
5151
from datadog.api.synthetics import Synthetics
5252
from datadog.api.logs import Logs
53+
from datadog.api.security_monitoring_rules import SecurityMonitoringRule
54+
from datadog.api.security_monitoring_signals import SecurityMonitoringSignal
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Unless explicitly stated otherwise all files in this repository are licensed under the BSD-3-Clause License.
2+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
# Copyright 2015-Present Datadog, Inc
4+
"""
5+
Security Monitoring Rule API.
6+
"""
7+
8+
from datadog.api.resources import (
9+
GetableAPIResource,
10+
CreateableAPIResource,
11+
ListableAPIResource,
12+
UpdatableAPIResource,
13+
DeletableAPIResource,
14+
ActionAPIResource,
15+
)
16+
17+
18+
class SecurityMonitoringRule(
19+
GetableAPIResource,
20+
CreateableAPIResource,
21+
ListableAPIResource,
22+
UpdatableAPIResource,
23+
DeletableAPIResource,
24+
ActionAPIResource,
25+
):
26+
"""
27+
A wrapper around Security Monitoring Rule API.
28+
"""
29+
30+
_resource_name = "security_monitoring/rules"
31+
_api_version = "v2"
32+
33+
@classmethod
34+
def get_all(cls, **params):
35+
"""
36+
Get all security monitoring rules.
37+
38+
:param params: additional parameters to filter security monitoring rules
39+
:type params: dict
40+
41+
:returns: Dictionary representing the API's JSON response
42+
"""
43+
return super(SecurityMonitoringRule, cls).get_all(**params)
44+
45+
@classmethod
46+
def get(cls, rule_id, **params):
47+
"""
48+
Get a security monitoring rule's details.
49+
50+
:param rule_id: ID of the security monitoring rule
51+
:type rule_id: str
52+
53+
:returns: Dictionary representing the API's JSON response
54+
"""
55+
return super(SecurityMonitoringRule, cls).get(rule_id, **params)
56+
57+
@classmethod
58+
def create(cls, **params):
59+
"""
60+
Create a security monitoring rule.
61+
62+
:param params: Parameters to create the security monitoring rule with
63+
:type params: dict
64+
65+
:returns: Dictionary representing the API's JSON response
66+
"""
67+
return super(SecurityMonitoringRule, cls).create(**params)
68+
69+
@classmethod
70+
def update(cls, rule_id, **params):
71+
"""
72+
Update a security monitoring rule.
73+
74+
:param rule_id: ID of the security monitoring rule to update
75+
:type rule_id: str
76+
:param params: Parameters to update the security monitoring rule with
77+
:type params: dict
78+
79+
:returns: Dictionary representing the API's JSON response
80+
"""
81+
return super(SecurityMonitoringRule, cls).update(rule_id, **params)
82+
83+
@classmethod
84+
def delete(cls, rule_id, **params):
85+
"""
86+
Delete a security monitoring rule.
87+
88+
:param rule_id: ID of the security monitoring rule to delete
89+
:type rule_id: str
90+
91+
:returns: Dictionary representing the API's JSON response
92+
"""
93+
return super(SecurityMonitoringRule, cls).delete(rule_id, **params)
+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Unless explicitly stated otherwise all files in this repository are licensed under the BSD-3-Clause License.
2+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
# Copyright 2015-Present Datadog, Inc
4+
"""
5+
Security Monitoring Signals API.
6+
"""
7+
8+
from datadog.api.resources import (
9+
GetableAPIResource,
10+
ListableAPIResource,
11+
SearchableAPIResource,
12+
ActionAPIResource,
13+
)
14+
15+
16+
class SecurityMonitoringSignal(
17+
GetableAPIResource,
18+
ListableAPIResource,
19+
SearchableAPIResource,
20+
ActionAPIResource,
21+
):
22+
"""
23+
A wrapper around Security Monitoring Signal API.
24+
"""
25+
26+
_resource_name = "security_monitoring/signals"
27+
_api_version = "v2"
28+
29+
@classmethod
30+
def get(cls, signal_id, **params):
31+
"""
32+
Get a security signal's details.
33+
34+
:param signal_id: ID of the security signal
35+
:type signal_id: str
36+
37+
:returns: Dictionary representing the API's JSON response
38+
"""
39+
return super(SecurityMonitoringSignal, cls).get(signal_id, **params)
40+
41+
@classmethod
42+
def get_all(cls, **params):
43+
"""
44+
Get all security signals.
45+
46+
:param params: additional parameters to filter security signals
47+
Valid options are:
48+
- filter[query]: search query to filter security signals
49+
- filter[from]: minimum timestamp for returned security signals
50+
- filter[to]: maximum timestamp for returned security signals
51+
- sort: sort order, can be 'timestamp', '-timestamp', etc.
52+
- page[size]: number of signals to return per page
53+
- page[cursor]: cursor to use for pagination
54+
:type params: dict
55+
56+
:returns: Dictionary representing the API's JSON response
57+
"""
58+
return super(SecurityMonitoringSignal, cls).get_all(**params)
59+
60+
@classmethod
61+
def search(cls, **params):
62+
"""
63+
Search for security signals.
64+
65+
:param params: search parameters
66+
Valid options are:
67+
- filter[query]: search query to filter security signals
68+
- filter[from]: minimum timestamp for returned security signals
69+
- filter[to]: maximum timestamp for returned security signals
70+
- sort: sort order, can be 'timestamp', '-timestamp', etc.
71+
- page[size]: number of signals to return per page
72+
- page[cursor]: cursor to use for pagination
73+
:type params: dict
74+
75+
:returns: Dictionary representing the API's JSON response
76+
"""
77+
return cls._search(**params)
78+
79+
@classmethod
80+
def change_triage_state(cls, signal_ids, state, **params):
81+
"""
82+
Change the triage state of security signals.
83+
84+
:param signal_ids: list of signal IDs to update
85+
:type signal_ids: list of str
86+
:param state: new triage state ('open', 'archived', 'under_review')
87+
:type state: str
88+
:param params: additional parameters
89+
:type params: dict
90+
91+
:returns: Dictionary representing the API's JSON response
92+
"""
93+
body = {
94+
"data": {
95+
"attributes": {
96+
"signals": signal_ids,
97+
"state": state,
98+
},
99+
"type": "signal_state_change",
100+
}
101+
}
102+
103+
params = params or {}
104+
105+
return cls._trigger_class_action(
106+
"PATCH", "triage_state", params=params, **body
107+
)

datadog/dogshell/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from datadog.dogshell.tag import TagClient
2828
from datadog.dogshell.timeboard import TimeboardClient
2929
from datadog.dogshell.dashboard import DashboardClient
30+
from datadog.dogshell.security_monitoring import SecurityMonitoringClient
3031

3132

3233
def main():
@@ -100,6 +101,7 @@ def main():
100101
DowntimeClient.setup_parser(subparsers)
101102
ServiceCheckClient.setup_parser(subparsers)
102103
ServiceLevelObjectiveClient.setup_parser(subparsers)
104+
SecurityMonitoringClient.setup_parser(subparsers)
103105

104106
args = parser.parse_args()
105107

0 commit comments

Comments
 (0)