Skip to content
Merged
17 changes: 16 additions & 1 deletion pytest_splunk_addon/addon_parser/props_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""
Provides props.conf parsing mechanism
"""
from typing import Dict
from typing import Dict, List
from typing import Generator
from typing import Optional
import logging
Expand Down Expand Up @@ -57,6 +57,14 @@ def props(self) -> Optional[Dict]:
self._props = self._conf_parser.item_dict()
return self._props if self._props else None

def update_field_names(self, field_list) -> List:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please type field_list here and specify the return type as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""
update field names to remove all the non-alphanumeric chars and replace them with _
"""
for index in range(len(field_list)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do for field in field_list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

field_list[index].name = re.sub(r"\W+", "_", field_list[index].name)
return field_list

def get_props_fields(self):
"""
Parse the props.conf and yield all supported fields
Expand All @@ -82,6 +90,13 @@ def get_props_fields(self):
else:
for transform_stanza, fields in self._get_report_fields(key, value):
field_list = list(fields)
if (
self.transforms_parser.transforms.get(
transform_stanza, {}
).get("CLEAN_KEYS")
!= "false"
):
field_list = self.update_field_names(field_list)
if field_list:
yield {
"stanza": stanza_name,
Expand Down
1 change: 1 addition & 0 deletions pytest_splunk_addon/fields_tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ..addon_parser import Field
import json
from itertools import chain

from ..utilities.log_helper import get_table_output
from ..utilities.log_helper import format_search_query_log

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/addons/TA_broken/default/transforms.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ case_sensitive_match = false
# Expected result: FAIL
[broken-NaN_lookup]
filename = NaN.csv
case_sensitive_match = false
case_sensitive_match = false
3 changes: 3 additions & 0 deletions tests/e2e/addons/TA_fiction/default/props.conf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ EXTRACT-fiction-fourteen = (?<date_only_in_hotwarmpath_event>\d+-\d+-\d+).*in ho
REPORT-fiction-tsc-delim-fields = fiction-tsc-delim-fields
REPORT-fiction-tsc-sk-regex-format = fiction-tsc-sk-regex-format
REPORT-fiction-tsc-sk-delim-format = fiction-tsc-sk-delim-format
REPORT-fiction-tsc-sk-delim-format-with-clean-keys = fiction-tsc-sk-delim-format-with-clean-keys
REPORT-fiction-tsc-non-alphanumeric = fiction-tsc-non-alphanumeric


## multiple transforms stanza associated with REPORT
REPORT-fiction-tsc-regex-format = fiction-tsc-regex, fiction-tsc-regex-format
Expand Down
17 changes: 17 additions & 0 deletions tests/e2e/addons/TA_fiction/default/transforms.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ SOURCE_KEY = event_id
DELIMS = "="
FIELDS = server_contact_mode, dest

# Component tested: REPORT, DELIM-FIELDS-SOURCE_KEY
# Scenario:# Similar to the above scenario
## ## server-contact-mode should be searched as server_contact_mode as CLEAN_KEYS = true by default
Copy link
Contributor

@mkolasinski-splunk mkolasinski-splunk Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLEAN_KEYS is set to false here, so how should this field be looked for? Just description requires small adjustment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

[fiction-tsc-sk-delim-format-with-clean-keys]
CLEAN_KEYS = false
SOURCE_KEY = event_id
DELIMS = "="
FIELDS = server-contact-mode, dest

# Component tested: REPORT, DELIM
# Scenario:
## server-contact-mode should be searched as server_contact_mode as CLEAN_KEYS = true by default[fiction-tsc-non-alphanumeric]
[fiction-tsc-non-alphanumeric]
DELIMS = " "
FIELDS = server-contact, dest_1


# Component tested: REPORT, REGEX-FORMAT-SOURCE_KEY
# Scenario: Source-key with regex and format
## An individual search for SOURCE_KEY and each field extracted in FORMAT and a single search of all the fields with SOURCE_KEY.
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
"*test_splunk_app_fiction.py::Test_App::test_props_fields*splunkd::field::dest* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields*splunkd::REPORT-fiction-tsc-regex-format::fiction-tsc-regex* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields*splunkd::REPORT-fiction-tsc-regex-format::fiction-tsc-regex-format* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields*splunkd::REPORT-fiction-tsc-sk-delim-format-with-clean-keys::fiction-tsc-sk-delim-format-with-clean-keys* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields*splunkd::field::server-contact-mode* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields*splunkd::field::server_contact* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields*splunkd::field::dest* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields*splunkd::field::dest_1* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields*splunkd::field::size1* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields*splunkd::field::size2* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields*splunkd::field::myeval* PASSED*",
Expand Down Expand Up @@ -119,6 +124,11 @@
"*test_splunk_app_fiction.py::Test_App::test_props_fields_no_dash_not_empty**/opt/splunk/var/log/splunk/splunkd.log*::field::splunk_server* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields_no_dash_not_empty**/opt/splunk/var/log/splunk/splunkd_access.log*::field::splunk_server* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields_no_dash_not_empty*splunkd::EXTRACT-fiction-one* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields_no_dash_not_empty*splunkd::REPORT-fiction-tsc-sk-delim-format-with-clean-keys::fiction-tsc-sk-delim-format-with-clean-keys* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields_no_dash_not_empty*splunkd::field::server-contact-mode* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields_no_dash_not_empty*splunkd::field::dest* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields_no_dash_not_empty*splunkd::field::dest_1* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields_no_dash_not_empty*splunkd::field::server_contact* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields_no_dash_not_empty*splunkd::field::extractone* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields_no_dash_not_empty*splunkd::EXTRACT-fiction-two* PASSED*",
"*test_splunk_app_fiction.py::Test_App::test_props_fields_no_dash_not_empty*splunkd::field::extracttwoA* PASSED*",
Expand Down