Building for the Splunk Platform

Know CSV file size before download

brunoabreu
Loves-to-Learn Lots

Using the Splunk Python SDK, is there any way to know the size of the CSV file that will be generated after streaming and writing all the results?

I've managed to achieve this with the approach below, but it makes me to download and iterate the CSV lines two times.

splunk_job = service.jobs.create(query, **kwargs)

# waits job to be done

splunk_job_result_args = {
    "output_mode": "csv"
}

splunk_job_results = splunk_job.results(**splunk_job_result_args)
results_length = 0
for bytes_csv_line in splunk_job_results:
    results_length += len(bytes_csv_line)
splunk_job_results.close()

# checks if the results_length exceeds the limit
# if not, executes the following:

splunk_job_results = splunk_job.results(**splunk_job_result_args)
for bytes_csv_line in splunk_job_results:
    # writes the bytes in a file
splunk_job_results.close()

 

Labels (2)
Tags (5)
0 Karma
Get Updates on the Splunk Community!

Starting With Observability: OpenTelemetry Best Practices

Tech Talk Starting With Observability: OpenTelemetry Best Practices Tuesday, October 17, 2023   |  11AM PST / ...

.conf23 | Get Your Cybersecurity Defense Analyst Certification in Vegas

We’re excited to announce a new Splunk certification exam being released at .conf23! If you’re going to Las ...

Streamline Data Ingestion With Deployment Server Essentials

REGISTER NOW! Every day the list of sources Admins are responsible for gets bigger and bigger, often making ...