Skip to content

Commit 67b90fb

Browse files
authored
Merge pull request #372 from splunk/dashboards_dropdown
Dashboards dropdown
2 parents 32ced32 + e185d62 commit 67b90fb

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
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: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
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

11-
DEFAULT_DASHBAORD_JINJA2_TEMPLATE = """<dashboard version="2" theme="{{ dashboard.theme }}">
13+
DEFAULT_DASHBOARD_JINJA2_TEMPLATE = """<dashboard version="2" theme="{{ dashboard.theme }}">
1214
<label>{{ dashboard.label(config) }}</label>
1315
<description></description>
1416
<definition><![CDATA[
@@ -31,7 +33,7 @@ class DashboardTheme(StrEnum):
3133

3234
class Dashboard(SecurityContentObject):
3335
j2_template: str = Field(
34-
default=DEFAULT_DASHBAORD_JINJA2_TEMPLATE,
36+
default=DEFAULT_DASHBOARD_JINJA2_TEMPLATE,
3537
description="Jinja2 Template used to construct the dashboard",
3638
)
3739
description: str = Field(
@@ -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):
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<nav search_view="search" color="#65A637">
22
<view name="escu_summary" default="true"/>
3-
<view name="feedback"/>
43
<view name="search"/>
5-
<view name="dashboards"/>
6-
<a href="http://docs.splunk.com/Documentation/ESSOC">Docs</a>
4+
<collection label="Dashboards">
5+
<view source="unclassified" match=" - "/>
6+
</collection>
77
</nav>

0 commit comments

Comments
 (0)