Skip to content

Commit 254c591

Browse files
chore: add samples for transform tests
1 parent 25eef8b commit 254c591

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

pytest_splunk_addon/addon_parser/transforms_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def get_sourcetype_from_transform(self, transform_stanza: str) -> Optional[str]:
187187
format_value = transforms_values["FORMAT"]
188188
# Match pattern: sourcetype::<sourcetype_name>
189189
# Case-insensitive, handles whitespace, handles quoted values
190-
regex = r"(?i)sourcetype\s*::\s*([^\s]+)"
190+
# Excludes patterns with $ variables (like $1, $2, etc.) Such cases need to be handled via sourcetype_to_search in pytest-splunk-addon-data.conf
191+
regex = r"(?i)sourcetype\s*::\s*([^\s\$]+)"
191192
match = re.search(regex, format_value)
192193

193194
if match:

tests/e2e/addons/TA_fiction_indextime/default/pytest-splunk-addon-data.conf

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,4 +1160,40 @@ token.3.field = dest
11601160
token.4.token = (##DEST_PORT##)
11611161
token.4.replacementType = random
11621162
token.4.replacement = dest_port
1163-
token.4.field = dest_port
1163+
token.4.field = dest_port
1164+
1165+
# Sample for testing rename sourcetype using source transform
1166+
# Tests the rename_sourcetype_using_source transform which extracts sourcetype from source
1167+
# The transform regex: (?:[a-zA-Z0-9_]+\.)?([a-zA-Z0-9_]+)\.log
1168+
# Expected result: sourcetype should become test:indextime:uf_file_monitor_rename_sourcetype:application
1169+
[uf_rename_sourcetype.samples]
1170+
sourcetype = test:indextime:uf_file_monitor_rename_sourcetype
1171+
host_type = plugin
1172+
input_type = file_monitor
1173+
source = /var/log/application.log
1174+
sourcetype_to_search = test:indextime:uf_file_monitor_rename_sourcetype:application
1175+
sample_count = 1
1176+
timestamp_type = event
1177+
1178+
token.0.token = (\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+)
1179+
token.0.replacementType = timestamp
1180+
token.0.replacement = %Y-%m-%dT%H:%M:%S
1181+
token.0.field = _time
1182+
1183+
# Sample for testing sourcetype update transform
1184+
# Tests the update_sourcetype transform which removes _sourcetype suffix
1185+
# The transform regex: sourcetype::(.*)_sourcetype
1186+
# Expected result: sourcetype should become test:indextime:sourcetype:updated
1187+
[updated_sourcetype.samples]
1188+
sourcetype = test:indextime:sourcetype:updated_sourcetype
1189+
host_type = plugin
1190+
input_type = file_monitor
1191+
source = pytest-splunk-addon:updated_sourcetype
1192+
sourcetype_to_search = test:indextime:sourcetype:updated
1193+
sample_count = 1
1194+
timestamp_type = event
1195+
1196+
token.0.token = (\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+)
1197+
token.0.replacementType = timestamp
1198+
token.0.replacement = %Y-%m-%dT%H:%M:%S
1199+
token.0.field = _time
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2024-01-15T10:32:00.789+0000 INFO File operation completed successfully operation=read file=/var/log/application.log
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2024-01-15T10:30:45.123+0000 INFO Application started successfully with config_param=test_value host=server01 static_value_2 component=main

0 commit comments

Comments
 (0)