Splunk Dev

Custom Python Command to read a CSV file

marvinlee93
Explorer

I have created a custom python command but I'm facing this problem. I have a dynamic fileName.
The filename that I want to read changes everyday.
It works fine before I package the code using the splunk streaming command.

with open('C:\Users\Desktop\%s\%s\%s'%('assetfiles','DailySchedule',fileName)) as csv_file:
This will give me:
C:\Users\KGQJ3999\Desktop\assetfiles\assetfiles\DailySchedule\2019-12-20_NAME1.csv

However, after packaging it into the streaming command, it's giving me this.
C:\Users\KGQJ3999\Desktop\assetfiles\assetfiles\DailySchedule\ .csv

I have tried many ways to concatenate strings. Even forcing the filename to be str(fileName). Still, the fileName is dissappearing from the splunk side and I'm getting the IO error.

Anybody has any idea why??

Labels (1)
0 Karma

martynoconnor
Communicator

Is fileName a field that exists in your search results immediately before you | to your custom command? If not, I would have expected the script to error out (missing a required arg?) but perhaps it's carrying on with null/empty value and that's why you're getting a csv with no name?

0 Karma
Get Updates on the Splunk Community!

What’s New in Splunk Enterprise 9.4: Tools for Digital Resilience

What’s New in Splunk Enterprise 9.4: Tools for Digital ResilienceTune in to What’s New in Splunk Enterprise ...

Get Schooled with Splunk Education: Explore Our Latest Courses

At Splunk Education, we’re dedicated to providing incredible learning experiences that cater to every skill ...

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL  The Splunk AI Assistant for SPL ...