Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def ingest(self, events, thread_count):
"source": event.metadata.get("source", "pytest_splunk_addon:hec:event"),
"event": event.event,
"index": event.metadata.get("index", "main"),
"fields": {"unique_identifier": event.unique_identifier}
}

if event.metadata.get("host_type") in ("plugin", None):
Expand Down
1 change: 1 addition & 0 deletions pytest_splunk_addon/fields_tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def generate_requirements_tests(self):
"escaped_event": escaped_event,
"fields": requirement_fields,
"modinput_params": modinput_params,
"unique_identifier": event.unique_identifier,
},
id=f"sample_name::{event.sample_name}::host::{event.metadata.get('host')}",
)
Expand Down
7 changes: 6 additions & 1 deletion pytest_splunk_addon/fields_tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,16 @@ def test_requirements_fields(
record_property(
"stanza_name", splunk_searchtime_fields_requirements["escaped_event"]
)
record_property(
"stanza_name", splunk_searchtime_fields_requirements["unique_identifier"]
)
record_property("fields", splunk_searchtime_fields_requirements["fields"])
record_property(
"modinput_params", splunk_searchtime_fields_requirements["modinput_params"]
)

escaped_event = splunk_searchtime_fields_requirements["escaped_event"]
unique_identifier = splunk_searchtime_fields_requirements["unique_identifier"]
fields = splunk_searchtime_fields_requirements["fields"]
modinput_params = splunk_searchtime_fields_requirements["modinput_params"]

Expand All @@ -185,7 +189,7 @@ def test_requirements_fields(
if param_value is not None:
basic_search += f" {param}={param_value}"

search = f"search {index_list} {basic_search} {escaped_event} | fields *"
search = f"search {index_list} {basic_search} unique_identifier=\"{unique_identifier}\" | fields *"

self.logger.info(f"Executing the search query: {search}")

Expand Down Expand Up @@ -225,6 +229,7 @@ def test_requirements_fields(
assert wrong_value_fields == {}, (
f"\nNot all required fields have correct values or some fields are missing in Splunk. Wrong field values:\n{wrong_values_table}"
f"{format_search_query_log(search)}"
f"Test failed for event: {escaped_event}\n"
)

@pytest.mark.splunk_searchtime_fields
Expand Down
2 changes: 2 additions & 0 deletions pytest_splunk_addon/sample_generation/sample_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import uuid
import re
import logging
from ..index_tests import key_fields
Expand Down Expand Up @@ -68,6 +69,7 @@ def __init__(self, event_string, metadata, sample_name, requirement_test_data=No
self.metadata = metadata
self.sample_name = sample_name
self.host_count = 0
self.unique_identifier = str(uuid.uuid4())
self.requirement_test_data = requirement_test_data

def update(self, new_event):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def store_events(self, tokenized_events):
"events": [
{
"event": each_event.event,
"unique_identifier": each_event.unique_identifier,
"key_fields": each_event.key_fields,
"time_values": each_event.time_values,
"requirement_test_data": each_event.requirement_test_data,
Expand All @@ -141,6 +142,7 @@ def store_events(self, tokenized_events):
tokenized_samples_dict[each_event.sample_name]["events"].append(
{
"event": each_event.event,
"unique_identifier": each_event.unique_identifier,
"key_fields": each_event.key_fields,
"time_values": each_event.time_values,
"requirement_test_data": each_event.requirement_test_data,
Expand Down
Loading