Skip to content

Commit cdacbf4

Browse files
Adam Taverasjshcodes
authored andcommitted
added GetSensorUsageHourly as this allows you to pull hourly for Cloud based; added it to test sensor; tested it in production and works since the endpoint does work and provides hourly usage billing that is used for Cloud (reserved hourly) usage
1 parent 4ee330d commit cdacbf4

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

src/falconpy/_endpoint/_sensor_usage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,27 @@
5858
"in": "query"
5959
}
6060
]
61+
],
62+
[
63+
"GetSensorUsageHourly",
64+
"GET",
65+
"/billing-dashboards-usage/aggregates/hourly-average/v1",
66+
"Fetches hourly average. Each data point represents the average of how many unique AIDs were seen per week "
67+
"for the previous 28 days.",
68+
"sensor_usage",
69+
[
70+
{
71+
"type": "string",
72+
"description": "The FQL search filter. Allowed fields:\n\"event_date\" : A specified date that will be "
73+
" final date of the results returned. Specified date cannot be after the default.\n\tFormat: "
74+
"'2024-06-11'\n\tDefault: the current date, minus 2 days, in UTC\n\"period\" : An integer surrounded by single "
75+
"quotes representing the number of days to return.\n\tFormat: '30'\n\tDefault: '28'\n\tMinimum: '1'\n\tMaximum: "
76+
" '395'\n\"selected_cids\" : A comma separated list of CIDs to return data for. Caller must be a parent CID or "
77+
"have special access enabled.\n\tFormat: 'cid_1,cid_2,cid_3'\n\tDefault: for parent CIDs the default is the "
78+
"parent and all children, otherwise the current CID",
79+
"name": "filter",
80+
"in": "query"
81+
}
82+
]
6183
]
6284
]

src/falconpy/sensor_usage.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,48 @@ def get_weekly_usage(self: object, parameters: dict = None, **kwargs) -> Union[D
9797
params=parameters
9898
)
9999

100+
@force_default(defaults=["parameters"], default_types=["dict"])
101+
def get_hourly_usage(self: object, parameters: dict = None, **kwargs) -> Union[Dict[str, Union[int, dict]], Result]:
102+
"""Fetch hourly sensor usage average used to measure cloud usage.
103+
104+
Each data point represents the average of how many unique AIDs were seen per week for the previous 28 days.
105+
106+
Keyword arguments:
107+
filter -- The FQL search filter.
108+
Allowed fields:
109+
event_date - A specified date that will be final date of the results returned.
110+
Specified date cannot be after the default.
111+
Format: '2024-06-11'
112+
Default: the current date, minus 2 days, in UTC
113+
period - An integer surrounded by single quotes representing the number of days to return.
114+
Format: '30'
115+
Default: '28'
116+
Minimum: '1'
117+
Maximum: '395'
118+
selected_cids - A comma delimited list of CIDs to return data for.
119+
Caller must be a parent CID or have special access enabled.
120+
Format: 'cid_1,cid_2,cid_3'
121+
Default: for parent CIDs the default is the parent and all children,
122+
otherwise the current CID
123+
parameters -- Full parameters payload dictionary. Not required if using other keywords.
124+
125+
This method only supports keywords for providing arguments.
126+
127+
Returns: dict object containing API response.
128+
129+
HTTP Method: GET
130+
131+
Swagger URL
132+
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/sensor-usage-api/GetSensorUsageWeekly
133+
Endpoint is not in Swagger file, but allows you to pull `hourly` usage which is used to determine cloud usage
134+
"""
135+
return process_service_request(
136+
calling_object=self,
137+
endpoints=Endpoints,
138+
operation_id="GetSensorUsageHourly",
139+
keywords=kwargs,
140+
params=parameters
141+
)
142+
100143
GetSensorUsageWeekly = get_weekly_usage
144+
GetSensorUsageHourly = get_hourly_usage

tests/test_sensor_usage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class TestSensorUsage:
2323
def test_all_code_paths(self):
2424
error_checks = True
2525
tests = {
26-
"GetWeeklySensorUsage": falcon.get_weekly_usage()
26+
"GetWeeklySensorUsage": falcon.get_weekly_usage(),
27+
"GetHourlySensorUsage": falcon.get_hourly_usage()
2728
}
2829
for key in tests:
2930
if tests[key]["status_code"] not in AllowedResponses:

0 commit comments

Comments
 (0)