Skip to content

Commit d64540f

Browse files
fixes ADDON-43860 in cim-fields-report: unhashable type: 'list' (#434)
* fixes ADDON-43860 in cim-fields-report: unhashable type: 'list' exception * removes duplications in list of (eventype, punct) pairs * adds unit tests for cim-fields-reports: core data preparation methods * chore: merged from main * fixes ADDON-43860 in cim-fields-report: unhashable type: 'list' exception * removes duplications in list of (eventype, punct) pairs * adds unit tests for cim-fields-reports: core data preparation methods * chore: merged from main * fix(cim-fields-report): fixes unhashable type: 'list' exception
1 parent fdb8c07 commit d64540f

File tree

5 files changed

+375
-5
lines changed

5 files changed

+375
-5
lines changed

deps/apps/Splunk_SA_CIM

Submodule Splunk_SA_CIM updated 55 files

pytest_splunk_addon/tools/cim_field_report.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,33 @@ def collect_job_results(job, acc, fn):
174174
return acc
175175

176176

177+
def collect_punct_and_eventtype(data, records):
178+
"""Accumulator function to be used with collect_job_results.
179+
180+
Accumulates punct and eventtype values, used in get_punct_by_eventtype
181+
182+
Parameters
183+
----------
184+
data : [set(), {}]
185+
Accumulator object to be updated (see collect_job_results acc argument)
186+
records : list
187+
SPL job result entries (result of job.get_results(...).as_list)
188+
"""
189+
190+
for record in records:
191+
eventtype = record["eventtype"]
192+
punct = record["punct"]
193+
if isinstance(eventtype, list):
194+
for entry in eventtype:
195+
new_val = (entry, punct)
196+
if new_val not in data:
197+
data.append(new_val)
198+
else:
199+
new_val = (eventtype, punct)
200+
if new_val not in data:
201+
data.append(new_val)
202+
203+
177204
def get_punct_by_eventtype(jobs, eventtypes, config):
178205
"""Runs SPL request to collect all unique eventtype+punct pairs from splunk instance
179206
@@ -203,8 +230,7 @@ def get_punct_by_eventtype(jobs, eventtypes, config):
203230
try:
204231
job = jobs.create(query, auto_finalize_ec=120, max_time=config.splunk_max_time)
205232
job.wait(config.splunk_max_time)
206-
LOGGER.debug(job.get_results().as_list)
207-
result = [(v["eventtype"], v["punct"]) for v in job.get_results().as_list]
233+
result = collect_job_results(job, [], collect_punct_and_eventtype)
208234
LOGGER.info(
209235
"Time taken to collect eventtype & punct combinations: {} s".format(
210236
time.time() - start
@@ -315,7 +341,7 @@ def get_fieldsummary(jobs, punct_by_eventtype, config):
315341
query, auto_finalize_ec=120, max_time=config.splunk_max_time
316342
)
317343
job.wait(config.splunk_max_time)
318-
summary = job.get_results().as_list
344+
summary = collect_job_results(job, [], lambda acc, recs: acc.extend(recs))
319345
except Exception as e:
320346
LOGGER.error("Errors executing search: {}".format(e))
321347
LOGGER.debug(traceback.format_exc())

tests/unit/tests_standard_lib/tests_tools/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)