Skip to content

Commit 9351558

Browse files
committed
feat: implement helper functions
1 parent 43ec2a1 commit 9351558

3 files changed

Lines changed: 226 additions & 161 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: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4124,36 +4124,48 @@ def create_dashboard(
41244124
api_version=api_version,
41254125
)
41264126

4127-
def import_dashboard(self, dashboard: dict[str, Any]) -> dict[str, Any]:
4127+
def import_dashboard(
4128+
self,
4129+
dashboard: dict[str, Any],
4130+
api_version: APIVersion | None = APIVersion.V1ALPHA,
4131+
) -> dict[str, Any]:
41284132
"""Create a new native dashboard.
41294133
41304134
Args:
41314135
dashboard: ImportNativeDashboardsInlineSource
4136+
api_version: Preferred API version to use. Defaults to V1ALPHA
41324137
41334138
Returns:
41344139
Dictionary containing the created dashboard details
41354140
41364141
Raises:
41374142
APIError: If the API request fails
41384143
"""
4144+
return _import_dashboard(
4145+
self, dashboard=dashboard, api_version=api_version
4146+
)
41394147

4140-
return _import_dashboard(self, dashboard=dashboard)
4141-
4142-
def export_dashboard(self, dashboard_names: list[str]) -> dict[str, Any]:
4148+
def export_dashboard(
4149+
self,
4150+
dashboard_names: list[str],
4151+
api_version: APIVersion | None = APIVersion.V1ALPHA,
4152+
) -> dict[str, Any]:
41434153
"""Export native dashboards.
41444154
It supports single dashboard export operation only.
41454155
41464156
Args:
41474157
dashboard_names: List of dashboard resource names to export.
4158+
api_version: Preferred API version to use. Defaults to V1ALPHA
41484159
41494160
Returns:
41504161
Dictionary containing the exported dashboards.
41514162
41524163
Raises:
41534164
APIError: If the API request fails
41544165
"""
4155-
4156-
return _export_dashboard(self, dashboard_names=dashboard_names)
4166+
return _export_dashboard(
4167+
self, dashboard_names=dashboard_names, api_version=api_version
4168+
)
41574169

41584170
def list_dashboards(
41594171
self,
@@ -4225,6 +4237,7 @@ def update_dashboard(
42254237
description: str | None = None,
42264238
filters: list[dict[str, Any]] | str | None = None,
42274239
charts: list[dict[str, Any]] | str | None = None,
4240+
api_version: APIVersion | None = APIVersion.V1ALPHA,
42284241
) -> dict[str, Any]:
42294242
"""Update an existing dashboard.
42304243
@@ -4234,6 +4247,7 @@ def update_dashboard(
42344247
description: New description for the dashboard (optional)
42354248
filters: New filters for the dashboard (optional)
42364249
charts: New charts for the dashboard (optional)
4250+
api_version: Preferred API version to use. Defaults to V1ALPHA
42374251
42384252
Returns:
42394253
Dictionary containing the updated dashboard details
@@ -4245,15 +4259,29 @@ def update_dashboard(
42454259
description=description,
42464260
filters=filters,
42474261
charts=charts,
4262+
api_version=api_version,
42484263
)
42494264

4250-
def delete_dashboard(self, dashboard_id: str) -> dict[str, Any]:
4265+
def delete_dashboard(
4266+
self,
4267+
dashboard_id: str,
4268+
api_version: APIVersion | None = APIVersion.V1ALPHA,
4269+
) -> dict[str, Any]:
42514270
"""Delete an existing dashboard.
42524271
42534272
Args:
42544273
dashboard_id: ID of the dashboard to delete
4274+
api_version: Preferred API version to use. Defaults to V1ALPHA
4275+
4276+
Returns:
4277+
Empty dictionary if deletion is successful
4278+
4279+
Raises:
4280+
APIError: If the API request fails
42554281
"""
4256-
return _delete_dashboard(self, dashboard_id=dashboard_id)
4282+
return _delete_dashboard(
4283+
self, dashboard_id=dashboard_id, api_version=api_version
4284+
)
42574285

42584286
def add_chart(
42594287
self,
@@ -4267,6 +4295,7 @@ def add_chart(
42674295
description: str | None = None,
42684296
query: str | None = None,
42694297
interval: InputInterval | dict[str, Any] | str | None = None,
4298+
api_version: APIVersion | None = APIVersion.V1ALPHA,
42704299
**kwargs,
42714300
) -> dict[str, Any]:
42724301
"""Add a chart to an existing dashboard.
@@ -4285,6 +4314,7 @@ def add_chart(
42854314
description: Description for the chart
42864315
query: Query for the chart
42874316
interval: Query input interval for the chart
4317+
api_version: Preferred API version to use. Defaults to V1ALPHA
42884318
**kwargs: Additional keyword arguments
42894319
(Will be added to request payload)
42904320
@@ -4309,6 +4339,7 @@ def add_chart(
43094339
description=description,
43104340
query=query,
43114341
interval=interval,
4342+
api_version=api_version,
43124343
**kwargs,
43134344
)
43144345

@@ -4318,17 +4349,24 @@ def duplicate_dashboard(
43184349
display_name: str,
43194350
access_type: str,
43204351
description: str | None = None,
4352+
api_version: APIVersion | None = APIVersion.V1ALPHA,
43214353
) -> dict[str, Any]:
43224354
"""Duplicate an existing dashboard.
43234355
43244356
Args:
4325-
dashboard_id: Id of the dashboard to duplicate
4326-
display_name: Display name for the new dashboard
4327-
access_type: Access type for the new dashboard (PRIVATE or PUBLIC)
4328-
description: Description for the new dashboard
4357+
client: ChronicleClient instance
4358+
dashboard_id: ID of the dashboard to duplicate
4359+
display_name: New name for the duplicated dashboard
4360+
access_type: Access type for the duplicated dashboard
4361+
(DashboardAccessType.PRIVATE or DashboardAccessType.PUBLIC)
4362+
description: Description for the duplicated dashboard
4363+
api_version: Preferred API version to use. Defaults to V1ALPHA
43294364
43304365
Returns:
4331-
Dictionary containing the updated dashboard details
4366+
Dictionary containing the duplicated dashboard details
4367+
4368+
Raises:
4369+
APIError: If the API request fails
43324370
"""
43334371
try:
43344372
access_type = DashboardAccessType[access_type.upper()]
@@ -4341,18 +4379,21 @@ def duplicate_dashboard(
43414379
display_name=display_name,
43424380
access_type=access_type,
43434381
description=description,
4382+
api_version=api_version,
43444383
)
43454384

43464385
def remove_chart(
43474386
self,
43484387
dashboard_id: str,
43494388
chart_id: str,
4389+
api_version: APIVersion | None = APIVersion.V1ALPHA,
43504390
) -> dict[str, Any]:
43514391
"""Remove a chart from a dashboard.
43524392
43534393
Args:
43544394
dashboard_id: ID of the dashboard containing the chart
43554395
chart_id: ID of the chart to remove
4396+
api_version: Preferred API version to use. Defaults to V1ALPHA
43564397
43574398
Returns:
43584399
Dictionary containing the updated dashboard
@@ -4364,24 +4405,34 @@ def remove_chart(
43644405
self,
43654406
dashboard_id=dashboard_id,
43664407
chart_id=chart_id,
4408+
api_version=api_version
43674409
)
43684410

4369-
def get_chart(self, chart_id: str) -> dict[str, Any]:
4370-
"""Get information about a specific chart.
4411+
def get_chart(
4412+
self,
4413+
chart_id: str,
4414+
api_version: APIVersion | None = APIVersion.V1ALPHA,
4415+
) -> dict[str, Any]:
4416+
"""Get detail for dashboard chart.
43714417
43724418
Args:
4373-
chart_id: ID of the chart to retrieve
4419+
chart_id: ID of the chart
4420+
api_version: Preferred API version to use. Defaults to V1ALPHA
43744421
43754422
Returns:
4376-
Dictionary containing chart details
4423+
Dict[str, Any]: Dictionary containing chart details
4424+
4425+
Raises:
4426+
APIError: If the API request fails
43774427
"""
4378-
return _get_chart(self, chart_id)
4428+
return _get_chart(self, chart_id, api_version)
43794429

43804430
def edit_chart(
43814431
self,
43824432
dashboard_id: str,
43834433
dashboard_chart: None | (dict[str, Any] | DashboardChart | str) = None,
43844434
dashboard_query: None | (dict[str, Any] | DashboardQuery | str) = None,
4435+
api_version: APIVersion | None = APIVersion.V1ALPHA,
43854436
) -> dict[str, Any]:
43864437
"""Edit an existing chart in a dashboard.
43874438
@@ -4404,15 +4455,21 @@ def edit_chart(
44044455
"input": {},
44054456
"etag":"123131231321321"
44064457
}
4458+
api_version: Preferred API version to use. Defaults to V1ALPHA
4459+
44074460
Returns:
44084461
Dictionary containing the updated dashboard with edited chart
4462+
4463+
Raises:
4464+
APIError: If the API request fails
44094465
"""
44104466

44114467
return _edit_chart(
44124468
self,
44134469
dashboard_id=dashboard_id,
44144470
dashboard_chart=dashboard_chart,
44154471
dashboard_query=dashboard_query,
4472+
api_version=api_version,
44164473
)
44174474

44184475
def execute_dashboard_query(

0 commit comments

Comments
 (0)