Skip to content

Commit 6ccfcbc

Browse files
authored
Merge pull request #463 from splunk/feature/include-fbds
Feature: supports adding FBDs to savedsearches.conf
2 parents a2810b3 + 3a2e580 commit 6ccfcbc

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

contentctl/actions/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def execute(self, input_dto: BuildInputDto) -> DirectorOutputDto:
3030
updated_conf_files.update(
3131
conf_output.writeDetections(input_dto.director_output_dto.detections)
3232
)
33+
updated_conf_files.update(conf_output.writeFbds())
3334
updated_conf_files.update(
3435
conf_output.writeStories(input_dto.director_output_dto.stories)
3536
)

contentctl/output/conf_output.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,67 @@ def writeDetections(self, objects: list[Detection]) -> set[pathlib.Path]:
110110
)
111111
return written_files
112112

113+
def writeFbds(self) -> set[pathlib.Path]:
114+
written_files: set[pathlib.Path] = set()
115+
116+
# Path to the static FBD configuration file
117+
fbd_config_path = self.config.path / "static_configs" / "savedsearches_fbd.conf"
118+
119+
if not fbd_config_path.exists():
120+
# If the file doesn't exist, just return empty set - no FBDs to write
121+
print("No FBD configuration file found; skipping FBD writing to conf.")
122+
return written_files
123+
print(f"Reading FBD configuration from {fbd_config_path}")
124+
125+
# Read and parse the FBD configuration file
126+
fbd_stanzas = self._parse_fbd_config_file(fbd_config_path)
127+
128+
if fbd_stanzas: # Only write if there are actual stanzas
129+
written_files.add(
130+
ConfWriter.writeConfFile(
131+
pathlib.Path("default/savedsearches.conf"),
132+
"savedsearches_fbds.j2",
133+
self.config,
134+
fbd_stanzas,
135+
)
136+
)
137+
138+
return written_files
139+
140+
def _parse_fbd_config_file(self, file_path: pathlib.Path) -> list:
141+
"""Parse the FBD configuration file into individual stanza objects."""
142+
stanzas = []
143+
current_stanza_lines = []
144+
145+
with open(file_path, "r", encoding="utf-8") as f:
146+
for line in f:
147+
stripped_line = line.strip()
148+
149+
# Skip comment lines (lines starting with # after stripping whitespace)
150+
if stripped_line.startswith("#"):
151+
continue
152+
153+
# If we hit a blank line and have accumulated stanza content, finalize the current stanza
154+
if not stripped_line:
155+
if current_stanza_lines:
156+
stanza_content = "\n".join(current_stanza_lines)
157+
stanza_obj = type(
158+
"FbdStanza", (), {"content": stanza_content}
159+
)()
160+
stanzas.append(stanza_obj)
161+
current_stanza_lines = []
162+
continue
163+
164+
# Accumulate non-empty, non-comment lines for the current stanza
165+
current_stanza_lines.append(line.rstrip())
166+
# Handle the last stanza if the file doesn't end with a blank line
167+
if current_stanza_lines:
168+
stanza_content = "\n".join(current_stanza_lines)
169+
stanza_obj = type("FbdStanza", (), {"content": stanza_content})()
170+
stanzas.append(stanza_obj)
171+
172+
return stanzas
173+
113174
def writeStories(self, objects: list[Story]) -> set[pathlib.Path]:
114175
written_files: set[pathlib.Path] = set()
115176
written_files.add(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
### {{app.label}} FBDS ###
4+
5+
{% for fbd_stanza in objects %}
6+
{{ fbd_stanza.content }}
7+
8+
{% endfor %}
9+
### END {{app.label}} FBDS ###

0 commit comments

Comments
 (0)