Skip to content

feat: base code for supporting custom search command #1693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/generated_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The following table describes the files generated by UCC framework.
| alert_actions.conf | output/<YOUR_ADDON_NAME>/default | Generates `alert_actions.conf` and `alert_actions.conf.spec` file for the custom alert actions defined in globalConfig |
| eventtypes.conf | output/<YOUR_ADDON_NAME>/default | Generates `eventtypes.conf` file if the sourcetype is mentioned in Adaptive Response of custom alert action in globalConfig |
| tags.conf | output/<YOUR_ADDON_NAME>/default | Generates `tags.conf` file based on the `eventtypes.conf` created for custom alert actions. |
| commands.conf | output/<YOUR_ADDON_NAME>/default | Generates `commands.conf` for custom commands provided in the globalConfig. |
| searchbnf.conf | output/<YOUR_ADDON_NAME>/default | Generates `searchbnf.conf` for custom search commands provided in the globalConfig. |
| _account.conf | output/&lt;YOUR_ADDON_NAME&gt;/README | Generates `<YOUR_ADDON_NAME>_account.conf.spec` file for the configuration mentioned in globalConfig |
| _settings.conf | output/&lt;YOUR_ADDON_NAME&gt;/README | Generates `<YOUR_ADDON_NAME>_settings.conf.spec` file for the Proxy, Logging or Custom Tab mentioned in globalConfig |
| configuration.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates configuration.xml file in `default/data/ui/views/` folder if configuration is defined in globalConfig. |
Expand All @@ -22,5 +24,6 @@ The following table describes the files generated by UCC framework.
| inputs.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates inputs.xml based on inputs configuration present in globalConfig, in `default/data/ui/views/inputs.xml` folder |
| _redirect.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates ta_name_redirect.xml file, if oauth is mentioned in globalConfig, in `default/data/ui/views/` folder. |
| _.html | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/alerts | Generates `alert_name.html` file based on alerts configuration present in globalConfig, in `default/data/ui/alerts` folder. |
| _.py | output/&lt;YOUR_ADDON_NAME&gt;/bin | Generates Python files for custom search commands provided in the globalConfig. |
| globalConfig.json | &lt;source_dir&gt; | Generates globalConfig.json file in the source code if globalConfig is not present in source directory at build time. |

2 changes: 1 addition & 1 deletion splunk_add_on_ucc_framework/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def generate(
global_config_update.handle_global_config_update(global_config, gc_path)
try:
validator = global_config_validator.GlobalConfigValidator(
internal_root_dir, global_config
internal_root_dir, global_config, source
)
validator.validate()
logger.info("globalConfig file is valid")
Expand Down
175 changes: 175 additions & 0 deletions splunk_add_on_ucc_framework/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
#
# Copyright 2025 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# TODO: Update the list as and when Splunk introduces new commands.
# Links to use: https://docs.splunk.com/Documentation/SplunkCloud/latest/SearchReference
# https://docs.splunk.com/Documentation/Splunk/latest/SearchReference
SPLUNK_COMMANDS = [
"abstract",
"accum",
"addcoltotals",
"addinfo",
"addtotals",
"analyzefields",
"anomalies",
"anomalousvalue",
"anomalydetection",
"append",
"appendcols",
"appendpipe",
"arules",
"associate",
"autoregress",
"awssnsalert",
"bin",
"bucket",
"bucketdir",
"chart",
"cluster",
"cofilter",
"collect",
"concurrency",
"contingency",
"convert",
"correlate",
"ctable",
"datamodel",
"datamodelsimple",
"dbinspect",
"dbxquery",
"dedup",
"delete",
"delta",
"diff",
"entitymerge",
"erex",
"eval",
"eventcount",
"eventstats",
"extract",
"fieldformat",
"fields",
"fieldsummary",
"filldown",
"fillnull",
"findtypes",
"folderize",
"foreach",
"format",
"from",
"fromjson",
"gauge",
"gentimes",
"geom",
"geomfilter",
"geostats",
"head",
"highlight",
"history",
"iconify",
"inputcsv",
"inputintelligence",
"inputlookup",
"iplocation",
"join",
"kmeans",
"kvform",
"loadjob",
"localize",
"localop",
"lookup",
"makecontinuous",
"makemv",
"makeresults",
"map",
"mcollect",
"metadata",
"metasearch",
"meventcollect",
"mpreview",
"msearch",
"mstats",
"multikv",
"multisearch",
"mvcombine",
"mvexpand",
"nomv",
"outlier",
"outputcsv",
"outputlookup",
"outputtext",
"overlap",
"pivot",
"predict",
"rangemap",
"rare",
"regex",
"reltime",
"rename",
"replace",
"require",
"rest",
"return",
"reverse",
"rex",
"rtorder",
"run",
"savedsearch",
"script",
"scrub",
"search",
"searchtxn",
"selfjoin",
"sendalert",
"sendemail",
"set",
"setfields",
"sichart",
"sirare",
"sistats",
"sitimechart",
"sitop",
"sort",
"spath",
"stats",
"strcat",
"streamstats",
"table",
"tags",
"tail",
"timechart",
"timewrap",
"tojson",
"top",
"transaction",
"transpose",
"trendline",
"tscollect",
"tstats",
"typeahead",
"typelearner",
"typer",
"union",
"uniq",
"untable",
"walklex",
"where",
"x11",
"xmlkv",
"xmlunescape",
"xpath",
"xyseries",
]
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from .create_web_conf import WebConf
from .create_account_conf import AccountConf
from .create_settings_conf import SettingsConf
from .create_commands_conf import CommandsConf
from .create_searchbnf_conf import SearchbnfConf

__all__ = [
"FileGenerator",
Expand All @@ -37,4 +39,6 @@
"InputsConf",
"AccountConf",
"SettingsConf",
"CommandsConf",
"SearchbnfConf",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Copyright 2025 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from typing import Any, Dict

from splunk_add_on_ucc_framework.generators.file_generator import FileGenerator


class CommandsConf(FileGenerator):
__description__ = (
"Generates `commands.conf` for custom commands provided in the globalConfig."
)

def _set_attributes(self, **kwargs: Any) -> None:
self.conf_file = "commands.conf"
if self._global_config.has_custom_search_commands():
self.command_names = []
for command in self._global_config.custom_search_commands:
self.command_names.append(command["commandName"])

def generate(self) -> Dict[str, str]:
if not self._global_config.has_custom_search_commands():
return {}

file_path = self.get_file_output_path(["default", self.conf_file])
self.set_template_and_render(
template_file_path=["conf_files"], file_name="commands_conf.template"
)
rendered_content = self._template.render(
command_names=self.command_names,
)
self.writer(
file_name=self.conf_file,
file_path=file_path,
content=rendered_content,
)
return {self.conf_file: file_path}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Copyright 2025 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from typing import Any, Dict

from splunk_add_on_ucc_framework.generators.file_generator import FileGenerator


class SearchbnfConf(FileGenerator):
__description__ = "Generates `searchbnf.conf` for custom search commands provided in the globalConfig."

def _set_attributes(self, **kwargs: Any) -> None:
self.conf_file = "searchbnf.conf"
self.searchbnf_info = []
if self._global_config.has_custom_search_commands():
for command in self._global_config.custom_search_commands:
if command.get("requiredSearchAssistant", False):
searchbnf_dict = {
"command_name": command["commandName"],
"description": command["description"],
"syntax": command["syntax"],
"usage": command["usage"],
}
self.searchbnf_info.append(searchbnf_dict)

def generate(self) -> Dict[str, str]:
if not self.searchbnf_info:
return {}

file_path = self.get_file_output_path(["default", self.conf_file])
self.set_template_and_render(
template_file_path=["conf_files"], file_name="searchbnf_conf.template"
)
rendered_content = self._template.render(
searchbnf_info=self.searchbnf_info,
)
self.writer(
file_name=self.conf_file,
file_path=file_path,
content=rendered_content,
)
return {self.conf_file: file_path}
10 changes: 10 additions & 0 deletions splunk_add_on_ucc_framework/generators/file_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
RedirectXml,
)
from splunk_add_on_ucc_framework.generators.html_files import AlertActionsHtml
from splunk_add_on_ucc_framework.generators.python_files import CustomCommandPy
from splunk_add_on_ucc_framework.generators.conf_files import (
AlertActionsConf,
AppConf,
Expand All @@ -35,6 +36,8 @@
WebConf,
AccountConf,
SettingsConf,
CommandsConf,
SearchbnfConf,
)

__all__ = ["FileClass", "GEN_FILE_LIST"]
Expand All @@ -59,6 +62,8 @@ class FileClass(NamedTuple):
),
FileClass("eventtypes.conf", EventtypesConf, ["default"]),
FileClass("tags.conf", TagsConf, ["default"]),
FileClass("commands.conf", CommandsConf, ["default"]),
FileClass("searchbnf.conf", SearchbnfConf, ["default"]),
FileClass("_account.conf", AccountConf, ["README"]),
FileClass("_settings.conf", SettingsConf, ["README"]),
FileClass(
Expand Down Expand Up @@ -91,4 +96,9 @@ class FileClass(NamedTuple):
AlertActionsHtml,
["default", "data", "ui", "alerts"],
),
FileClass(
"_.py",
CustomCommandPy,
["bin"],
),
]
19 changes: 19 additions & 0 deletions splunk_add_on_ucc_framework/generators/python_files/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright 2025 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from ..file_generator import FileGenerator
from .create_custom_command_python import CustomCommandPy

__all__ = ["FileGenerator", "CustomCommandPy"]
Loading
Loading