Skip to content

Commit 342ebb4

Browse files
fix: path issue for default alert icon (#1839)
**Issue number:** ### PR Type **What kind of change does this PR introduce?** * [ ] Feature * [x] Bug Fix * [ ] Refactoring (no functional or API changes) * [ ] Documentation Update * [ ] Maintenance (dependency updates, CI, etc.) ## Summary ### Changes Fix the path issue for `alerticon.png`. Earlier, UCC was not able to correctly find path for alerticon.png. Updated the smoke test case respectively. ### User experience No build failure will occur if `iconFileName` is not provide in alerts. ## Checklist If an item doesn't apply to your changes, leave it unchecked. ### Review * [x] self-review - I have performed a self-review of this change according to the [development guidelines](https://splunk.github.io/addonfactory-ucc-generator/contributing/#development-guidelines) * [ ] Changes are documented. The documentation is understandable, examples work [(more info)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#documentation-guidelines) * [x] PR title and description follows the [contributing principles](https://splunk.github.io/addonfactory-ucc-generator/contributing/#pull-requests) * [ ] meeting - I have scheduled a meeting or recorded a demo to explain these changes (if there is a video, put a link below and in the ticket) ### Tests See [the testing doc](https://splunk.github.io/addonfactory-ucc-generator/contributing/#build-and-test). * [ ] Unit - tests have been added/modified to cover the changes * [x] Smoke - tests have been added/modified to cover the changes * [ ] UI - tests have been added/modified to cover the changes * [ ] coverage - I have checked the code coverage of my changes [(see more)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#checking-the-code-coverage) **Demo/meeting:** *Reviewers are encouraged to request meetings or demos if any part of the change is unclear* --------- Co-authored-by: soleksy-splunk <143183665+soleksy-splunk@users.noreply.github.com>
1 parent 01e526c commit 342ebb4

File tree

11 files changed

+165
-9
lines changed

11 files changed

+165
-9
lines changed

splunk_add_on_ucc_framework/generators/file_generator.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
# limitations under the License.
1515
#
1616
import logging
17-
import os
1817
from abc import ABC
19-
from os.path import realpath, sep
18+
from os.path import realpath, sep, dirname, abspath
2019
from typing import Any, Dict, List, Union, NoReturn, Optional
2120

2221
from jinja2 import Environment, FileSystemLoader, select_autoescape
@@ -39,7 +38,7 @@
3938
class FileGenerator(ABC):
4039
__description__ = "DESCRIBE THE FILE THAT IS GENERATED"
4140

42-
_ucc_dir = ucc_framework_file
41+
_ucc_dir = abspath(dirname(ucc_framework_file))
4342

4443
def __init__(
4544
self,
@@ -57,7 +56,7 @@ def __init__(
5756
self._global_config = global_config
5857
self._input_dir = input_dir
5958
self._output_dir = output_dir
60-
self._template_dir = [(sep.join([os.path.dirname(self._ucc_dir), "templates"]))]
59+
self._template_dir = [(sep.join([self._ucc_dir, "templates"]))]
6160
self._template = Environment(
6261
loader=FileSystemLoader(self._template_dir),
6362
trim_blocks=True,

tests/smoke/test_ucc_build.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def test_ucc_generate_with_everything(caplog):
146146
files_to_be_equal = [
147147
("README.txt",),
148148
("appserver", "static", "test icon.png"),
149+
("appserver", "static", "alerticon.png"),
149150
("appserver", "static", "js", "build", "custom", "custom_tab.js"),
150151
("default", "alert_actions.conf"),
151152
("default", "eventtypes.conf"),
@@ -158,6 +159,7 @@ def test_ucc_generate_with_everything(caplog):
158159
("default", "commands.conf"),
159160
("default", "searchbnf.conf"),
160161
("default", "data", "ui", "alerts", "test_alert.html"),
162+
("default", "data", "ui", "alerts", "test_alert_default.html"),
161163
("default", "data", "ui", "nav", "default.xml"),
162164
("default", "data", "ui", "views", "configuration.xml"),
163165
("default", "data", "ui", "views", "inputs.xml"),
@@ -188,6 +190,8 @@ def test_ucc_generate_with_everything(caplog):
188190
("bin", "splunk_ta_uccexample_validate_account_rh.py"),
189191
("bin", "myAlertLogic.py"),
190192
("bin", "test_alert.py"),
193+
("bin", "test_alert_default.py"),
194+
("bin", "splunk_ta_uccexample", "modalert_test_alert_default_helper.py"),
191195
("README", "alert_actions.conf.spec"),
192196
("README", "inputs.conf.spec"),
193197
("README", "some_conf.conf.spec"),
@@ -213,7 +217,6 @@ def test_ucc_generate_with_everything(caplog):
213217

214218
# when custom files are provided, default files shouldn't be shipped
215219
files_should_be_absent = [
216-
("appserver", "static", "alerticon.png"),
217220
("bin", "splunk_ta_uccexample", "modalert_test_alert_helper.py"),
218221
("appserver", "static", "js", "build", "entry_page.js.map"),
219222
("lib", "__pycache__"),

tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/README/alert_actions.conf.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ param.description = <string> Description. It's a required parameter. It's defaul
55
param.all_incidents = <bool> All Incidents.
66
param.table_list = <list> Table List. It's default value is problem.
77
param.action = <list> Action:. It's a required parameter. It's default value is update.
8-
param.account = <list> Select Account. It's a required parameter.
8+
param.account = <list> Select Account. It's a required parameter.
9+
10+
[test_alert_default]
11+
param._cam = <json> Adaptive Response parameters.
12+
param.name = <string> Name. It's a required parameter. It's default value is xyz.
8.78 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# encoding = utf-8
2+
3+
def process_event(helper, *args, **kwargs):
4+
"""
5+
# IMPORTANT
6+
# Do not remove the anchor macro:start and macro:end lines.
7+
# These lines are used to generate sample code. If they are
8+
# removed, the sample code will not be updated when configurations
9+
# are updated.
10+
11+
[sample_code_macro:start]
12+
13+
# The following example gets the alert action parameters and prints them to the log
14+
name = helper.get_param("name")
15+
helper.log_info("name={}".format(name))
16+
17+
18+
# The following example adds two sample events ("hello", "world")
19+
# and writes them to Splunk
20+
# NOTE: Call helper.writeevents() only once after all events
21+
# have been added
22+
helper.addevent("hello", sourcetype="test:incident")
23+
helper.addevent("world", sourcetype="test:incident")
24+
helper.writeevents(index="summary", host="localhost", source="localhost")
25+
26+
# The following example gets the events that trigger the alert
27+
events = helper.get_events()
28+
for event in events:
29+
helper.log_info("event={}".format(event))
30+
31+
# helper.settings is a dict that includes environment configuration
32+
# Example usage: helper.settings["server_uri"]
33+
helper.log_info("server_uri={}".format(helper.settings["server_uri"]))
34+
[sample_code_macro:end]
35+
"""
36+
37+
helper.log_info("Alert action test_alert_default started.")
38+
39+
# TODO: Implement your alert action logic here
40+
return 0
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# encoding = utf-8
2+
# Always put this line at the beginning of this file
3+
import import_declare_test
4+
5+
import os
6+
import sys
7+
8+
from splunktaucclib.alert_actions_base import ModularAlertBase
9+
from splunk_ta_uccexample import modalert_test_alert_default_helper
10+
11+
class AlertActionWorkertest_alert_default(ModularAlertBase):
12+
13+
def __init__(self, ta_name, alert_name):
14+
super(AlertActionWorkertest_alert_default, self).__init__(ta_name, alert_name)
15+
16+
def validate_params(self):
17+
18+
19+
if not self.get_param("name"):
20+
self.log_error('name is a mandatory parameter, but its value is None.')
21+
return False
22+
return True
23+
24+
def process_event(self, *args, **kwargs):
25+
status = 0
26+
try:
27+
if not self.validate_params():
28+
return 3
29+
status = modalert_test_alert_default_helper.process_event(self, *args, **kwargs)
30+
except (AttributeError, TypeError) as ae:
31+
self.log_error("Error: {}. Please double check spelling and also verify that a compatible version of Splunk_SA_CIM is installed.".format(str(ae)))#ae.message replaced with str(ae)
32+
return 4
33+
except Exception as e:
34+
msg = "Unexpected error: {}."
35+
if str(e):
36+
self.log_error(msg.format(str(e)))#e.message replaced with str(ae)
37+
else:
38+
import traceback
39+
self.log_error(msg.format(traceback.format_exc()))
40+
return 5
41+
return status
42+
43+
if __name__ == "__main__":
44+
exitcode = AlertActionWorkertest_alert_default("Splunk_TA_UCCExample", "test_alert_default").run(sys.argv)
45+
sys.exit(exitcode)

tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/default/alert_actions.conf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@ param.action = update
1111
param.account =
1212
python.version = python3
1313
is_custom = 1
14-
payload_format = json
14+
payload_format = json
15+
16+
[test_alert_default]
17+
icon_path = alerticon.png
18+
label = Test Alert Default
19+
description = Description for test Alert Action
20+
param._cam = {"task": ["Create"], "subject": ["endpoint"], "category": ["Information Portrayal"], "technology": [{"version": ["1.0.0"], "product": "Test Incident Update", "vendor": "Splunk"}], "drilldown_uri": "search?q=search%20index%3D\"_internal\"&earliest=0&latest="}
21+
param.name = xyz
22+
python.version = python3
23+
is_custom = 1
24+
payload_format = json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<form class="form-horizontal form-complex">
2+
<div class="control-group">
3+
<label class="control-label" for="test_alert_default_name">Name <span class="required">*</span> </label>
4+
<div class="controls">
5+
<input type="text" name="action.test_alert_default.param.name"
6+
id="test_alert_default_name" />
7+
<span class="help-block">
8+
Please enter your name
9+
</span>
10+
</div>
11+
</div>
12+
</form>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[test_alert_modaction_result]
2-
search = sourcetype="test:incident"
2+
search = sourcetype="test:incident"
3+
4+
[test_alert_default_modaction_result]
5+
search = sourcetype="test:incident"
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[eventtype=test_alert_modaction_result]
2-
modaction_result = enabled
2+
modaction_result = enabled
3+
4+
[eventtype=test_alert_default_modaction_result]
5+
modaction_result = enabled

0 commit comments

Comments
 (0)