Skip to content

Commit 3be2936

Browse files
authored
Merge pull request #190 from PaperMtn/feat/dashboard-method-util-refactor
Feat/dashboard method util refactor
2 parents 19e54da + 971be66 commit 3be2936

6 files changed

Lines changed: 867 additions & 875 deletions

File tree

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,9 +2930,13 @@ dashboard = chronicle.get_dashboard(
29302930
print(f"Dashboard Details: {dashboard}")
29312931
```
29322932

2933-
### List Dashboards with pagination
2933+
### List Dashboards
29342934
```python
2935-
# List dashboards (first page)
2935+
dashboards = chronicle.list_dashboards()
2936+
for dashboard in dashboards.get("nativeDashboards", []):
2937+
print(f"- {dashboard.get('displayName')}")
2938+
2939+
# List dashboards with pagination(first page)
29362940
dashboards = chronicle.list_dashboards(page_size=10)
29372941
for dashboard in dashboards.get("nativeDashboards", []):
29382942
print(f"- {dashboard.get('displayName')}")

src/secops/chronicle/client.py

Lines changed: 91 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4091,6 +4091,7 @@ def create_dashboard(
40914091
description: str | None = None,
40924092
filters: list[dict[str, Any]] | str | None = None,
40934093
charts: list[dict[str, Any]] | str | None = None,
4094+
api_version: APIVersion | None = APIVersion.V1ALPHA,
40944095
) -> dict[str, Any]:
40954096
"""Create a new native dashboard.
40964097
@@ -4102,6 +4103,7 @@ def create_dashboard(
41024103
(JSON or JSON string)
41034104
charts: List of charts to include in the dashboard
41044105
(JSON or JSON string)
4106+
api_version: Preferred API version to use. Defaults to V1ALPHA
41054107
41064108
Returns:
41074109
Dictionary containing the created dashboard details
@@ -4121,56 +4123,70 @@ def create_dashboard(
41214123
description=description,
41224124
filters=filters,
41234125
charts=charts,
4126+
api_version=api_version,
41244127
)
41254128

4126-
def import_dashboard(self, dashboard: dict[str, Any]) -> dict[str, Any]:
4129+
def import_dashboard(
4130+
self,
4131+
dashboard: dict[str, Any],
4132+
api_version: APIVersion | None = APIVersion.V1ALPHA,
4133+
) -> dict[str, Any]:
41274134
"""Create a new native dashboard.
41284135
41294136
Args:
41304137
dashboard: ImportNativeDashboardsInlineSource
4138+
api_version: Preferred API version to use. Defaults to V1ALPHA
41314139
41324140
Returns:
41334141
Dictionary containing the created dashboard details
41344142
41354143
Raises:
41364144
APIError: If the API request fails
41374145
"""
4146+
return _import_dashboard(
4147+
self, dashboard=dashboard, api_version=api_version
4148+
)
41384149

4139-
return _import_dashboard(self, dashboard=dashboard)
4140-
4141-
def export_dashboard(self, dashboard_names: list[str]) -> dict[str, Any]:
4150+
def export_dashboard(
4151+
self,
4152+
dashboard_names: list[str],
4153+
api_version: APIVersion | None = APIVersion.V1ALPHA,
4154+
) -> dict[str, Any]:
41424155
"""Export native dashboards.
41434156
It supports single dashboard export operation only.
41444157
41454158
Args:
41464159
dashboard_names: List of dashboard resource names to export.
4160+
api_version: Preferred API version to use. Defaults to V1ALPHA
41474161
41484162
Returns:
41494163
Dictionary containing the exported dashboards.
41504164
41514165
Raises:
41524166
APIError: If the API request fails
41534167
"""
4154-
4155-
return _export_dashboard(self, dashboard_names=dashboard_names)
4168+
return _export_dashboard(
4169+
self, dashboard_names=dashboard_names, api_version=api_version
4170+
)
41564171

41574172
def list_dashboards(
41584173
self,
41594174
page_size: int | None = None,
41604175
page_token: str | None = None,
4176+
api_version: APIVersion | None = APIVersion.V1ALPHA,
41614177
as_list: bool = False,
4162-
) -> dict[str, Any] | list[dict[str, Any]]:
4163-
"""List all available dashboards.
4178+
) -> dict[str, Any]:
4179+
"""List all available dashboards in Basic View.
41644180
41654181
Args:
41664182
page_size: Maximum number of results to return
41674183
page_token: Token for pagination
4168-
as_list: If True, return a list of dashboards instead of a dict
4169-
with dashboards list and nextPageToken.
4184+
api_version: Preferred API version to use. Defaults to V1ALPHA
4185+
as_list: Whether to return results as a list or dictionary
41704186
41714187
Returns:
41724188
If as_list is True: List of dashboards.
4173-
If as_list is False: Dict with dashboards list and nextPageToken.
4189+
If as_list is False: Dictionary containing list of dashboards and pagination info.
41744190
41754191
Raises:
41764192
APIError: If the API request fails
@@ -4179,23 +4195,29 @@ def list_dashboards(
41794195
self,
41804196
page_size=page_size,
41814197
page_token=page_token,
4198+
api_version=api_version,
41824199
as_list=as_list,
41834200
)
41844201

41854202
def get_dashboard(
41864203
self,
41874204
dashboard_id: str,
41884205
view: str | None = None,
4206+
api_version: APIVersion | None = APIVersion.V1ALPHA,
41894207
) -> dict[str, Any]:
41904208
"""Get information about a specific dashboard.
41914209
41924210
Args:
41934211
dashboard_id: ID of the dashboard to retrieve
41944212
view: Level of detail to include in the response
41954213
Defaults to BASIC
4214+
api_version: Preferred API version to use. Defaults to V1ALPHA
41964215
41974216
Returns:
41984217
Dictionary containing dashboard details
4218+
4219+
Raises:
4220+
APIError: If the API request fails
41994221
"""
42004222
if view:
42014223
try:
@@ -4207,6 +4229,7 @@ def get_dashboard(
42074229
self,
42084230
dashboard_id=dashboard_id,
42094231
view=view,
4232+
api_version=api_version,
42104233
)
42114234

42124235
def update_dashboard(
@@ -4216,6 +4239,7 @@ def update_dashboard(
42164239
description: str | None = None,
42174240
filters: list[dict[str, Any]] | str | None = None,
42184241
charts: list[dict[str, Any]] | str | None = None,
4242+
api_version: APIVersion | None = APIVersion.V1ALPHA,
42194243
) -> dict[str, Any]:
42204244
"""Update an existing dashboard.
42214245
@@ -4225,6 +4249,7 @@ def update_dashboard(
42254249
description: New description for the dashboard (optional)
42264250
filters: New filters for the dashboard (optional)
42274251
charts: New charts for the dashboard (optional)
4252+
api_version: Preferred API version to use. Defaults to V1ALPHA
42284253
42294254
Returns:
42304255
Dictionary containing the updated dashboard details
@@ -4236,15 +4261,29 @@ def update_dashboard(
42364261
description=description,
42374262
filters=filters,
42384263
charts=charts,
4264+
api_version=api_version,
42394265
)
42404266

4241-
def delete_dashboard(self, dashboard_id: str) -> dict[str, Any]:
4267+
def delete_dashboard(
4268+
self,
4269+
dashboard_id: str,
4270+
api_version: APIVersion | None = APIVersion.V1ALPHA,
4271+
) -> dict[str, Any]:
42424272
"""Delete an existing dashboard.
42434273
42444274
Args:
42454275
dashboard_id: ID of the dashboard to delete
4276+
api_version: Preferred API version to use. Defaults to V1ALPHA
4277+
4278+
Returns:
4279+
Empty dictionary if deletion is successful
4280+
4281+
Raises:
4282+
APIError: If the API request fails
42464283
"""
4247-
return _delete_dashboard(self, dashboard_id=dashboard_id)
4284+
return _delete_dashboard(
4285+
self, dashboard_id=dashboard_id, api_version=api_version
4286+
)
42484287

42494288
def add_chart(
42504289
self,
@@ -4258,6 +4297,7 @@ def add_chart(
42584297
description: str | None = None,
42594298
query: str | None = None,
42604299
interval: InputInterval | dict[str, Any] | str | None = None,
4300+
api_version: APIVersion | None = APIVersion.V1ALPHA,
42614301
**kwargs,
42624302
) -> dict[str, Any]:
42634303
"""Add a chart to an existing dashboard.
@@ -4276,6 +4316,7 @@ def add_chart(
42764316
description: Description for the chart
42774317
query: Query for the chart
42784318
interval: Query input interval for the chart
4319+
api_version: Preferred API version to use. Defaults to V1ALPHA
42794320
**kwargs: Additional keyword arguments
42804321
(Will be added to request payload)
42814322
@@ -4300,6 +4341,7 @@ def add_chart(
43004341
description=description,
43014342
query=query,
43024343
interval=interval,
4344+
api_version=api_version,
43034345
**kwargs,
43044346
)
43054347

@@ -4309,17 +4351,24 @@ def duplicate_dashboard(
43094351
display_name: str,
43104352
access_type: str,
43114353
description: str | None = None,
4354+
api_version: APIVersion | None = APIVersion.V1ALPHA,
43124355
) -> dict[str, Any]:
43134356
"""Duplicate an existing dashboard.
43144357
43154358
Args:
4316-
dashboard_id: Id of the dashboard to duplicate
4317-
display_name: Display name for the new dashboard
4318-
access_type: Access type for the new dashboard (PRIVATE or PUBLIC)
4319-
description: Description for the new dashboard
4359+
client: ChronicleClient instance
4360+
dashboard_id: ID of the dashboard to duplicate
4361+
display_name: New name for the duplicated dashboard
4362+
access_type: Access type for the duplicated dashboard
4363+
(DashboardAccessType.PRIVATE or DashboardAccessType.PUBLIC)
4364+
description: Description for the duplicated dashboard
4365+
api_version: Preferred API version to use. Defaults to V1ALPHA
43204366
43214367
Returns:
4322-
Dictionary containing the updated dashboard details
4368+
Dictionary containing the duplicated dashboard details
4369+
4370+
Raises:
4371+
APIError: If the API request fails
43234372
"""
43244373
try:
43254374
access_type = DashboardAccessType[access_type.upper()]
@@ -4332,18 +4381,21 @@ def duplicate_dashboard(
43324381
display_name=display_name,
43334382
access_type=access_type,
43344383
description=description,
4384+
api_version=api_version,
43354385
)
43364386

43374387
def remove_chart(
43384388
self,
43394389
dashboard_id: str,
43404390
chart_id: str,
4391+
api_version: APIVersion | None = APIVersion.V1ALPHA,
43414392
) -> dict[str, Any]:
43424393
"""Remove a chart from a dashboard.
43434394
43444395
Args:
43454396
dashboard_id: ID of the dashboard containing the chart
43464397
chart_id: ID of the chart to remove
4398+
api_version: Preferred API version to use. Defaults to V1ALPHA
43474399
43484400
Returns:
43494401
Dictionary containing the updated dashboard
@@ -4355,24 +4407,34 @@ def remove_chart(
43554407
self,
43564408
dashboard_id=dashboard_id,
43574409
chart_id=chart_id,
4410+
api_version=api_version
43584411
)
43594412

4360-
def get_chart(self, chart_id: str) -> dict[str, Any]:
4361-
"""Get information about a specific chart.
4413+
def get_chart(
4414+
self,
4415+
chart_id: str,
4416+
api_version: APIVersion | None = APIVersion.V1ALPHA,
4417+
) -> dict[str, Any]:
4418+
"""Get detail for dashboard chart.
43624419
43634420
Args:
4364-
chart_id: ID of the chart to retrieve
4421+
chart_id: ID of the chart
4422+
api_version: Preferred API version to use. Defaults to V1ALPHA
43654423
43664424
Returns:
4367-
Dictionary containing chart details
4425+
Dict[str, Any]: Dictionary containing chart details
4426+
4427+
Raises:
4428+
APIError: If the API request fails
43684429
"""
4369-
return _get_chart(self, chart_id)
4430+
return _get_chart(self, chart_id, api_version)
43704431

43714432
def edit_chart(
43724433
self,
43734434
dashboard_id: str,
43744435
dashboard_chart: None | (dict[str, Any] | DashboardChart | str) = None,
43754436
dashboard_query: None | (dict[str, Any] | DashboardQuery | str) = None,
4437+
api_version: APIVersion | None = APIVersion.V1ALPHA,
43764438
) -> dict[str, Any]:
43774439
"""Edit an existing chart in a dashboard.
43784440
@@ -4395,15 +4457,21 @@ def edit_chart(
43954457
"input": {},
43964458
"etag":"123131231321321"
43974459
}
4460+
api_version: Preferred API version to use. Defaults to V1ALPHA
4461+
43984462
Returns:
43994463
Dictionary containing the updated dashboard with edited chart
4464+
4465+
Raises:
4466+
APIError: If the API request fails
44004467
"""
44014468

44024469
return _edit_chart(
44034470
self,
44044471
dashboard_id=dashboard_id,
44054472
dashboard_chart=dashboard_chart,
44064473
dashboard_query=dashboard_query,
4474+
api_version=api_version,
44074475
)
44084476

44094477
def execute_dashboard_query(

0 commit comments

Comments
 (0)