Skip to content

Commit 2080cf8

Browse files
committed
Turn Dashboards into a dropdown and automatically populate it with the dashboards you have added to the app. Dashboard names and files are also now prefixed with the name of the app, making them easier to search for.
1 parent 32ced32 commit 2080cf8

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

contentctl/objects/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
CONTENTCTL_DETECTION_STANZA_NAME_FORMAT_TEMPLATE = (
124124
"{app_label} - {detection_name} - Rule"
125125
)
126+
127+
CONTENTCTL_DASHBOARD_LABEL_TEMPLATE = "{app_label} - {dashboard_name}"
126128
CONTENTCTL_BASELINE_STANZA_NAME_FORMAT_TEMPLATE = "{app_label} - {detection_name}"
127129
CONTENTCTL_RESPONSE_TASK_NAME_FORMAT_TEMPLATE = (
128130
"{app_label} - {detection_name} - Response Task"

contentctl/objects/dashboard.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import json
2+
import pathlib
3+
from enum import StrEnum
14
from typing import Any
2-
from pydantic import Field, Json, model_validator
35

4-
import pathlib
56
from jinja2 import Environment
6-
import json
7-
from contentctl.objects.security_content_object import SecurityContentObject
7+
from pydantic import Field, Json, model_validator
8+
89
from contentctl.objects.config import build
9-
from enum import StrEnum
10+
from contentctl.objects.constants import CONTENTCTL_DASHBOARD_LABEL_TEMPLATE
11+
from contentctl.objects.security_content_object import SecurityContentObject
1012

1113
DEFAULT_DASHBAORD_JINJA2_TEMPLATE = """<dashboard version="2" theme="{{ dashboard.theme }}">
1214
<label>{{ dashboard.label(config) }}</label>
@@ -49,7 +51,9 @@ class Dashboard(SecurityContentObject):
4951
)
5052

5153
def label(self, config: build) -> str:
52-
return f"{config.app.label} - {self.name}"
54+
return CONTENTCTL_DASHBOARD_LABEL_TEMPLATE.format(
55+
app_label=config.app.label, dashboard_name=self.name
56+
)
5357

5458
@model_validator(mode="before")
5559
@classmethod
@@ -98,7 +102,9 @@ def pretty_print_json_obj(self):
98102
return json.dumps(self.json_obj, indent=4)
99103

100104
def getOutputFilepathRelativeToAppRoot(self, config: build) -> pathlib.Path:
101-
filename = f"{self.file_path.stem}.xml".lower()
105+
# for clarity, the name of the dashboard file will follow the same convention
106+
# as we use for detections, prefixing it with app_name -
107+
filename = f"{self.label(config)}.xml"
102108
return pathlib.Path("default/data/ui/views") / filename
103109

104110
def writeDashboardFile(self, j2_env: Environment, config: build):

0 commit comments

Comments
 (0)