Hi everyone, I have a script.py which requires one argument to run normally, for eg. script.py D:\Downloads\12-Dec-2022\1234\ I am intending to create a custom search command so that I can have a Splunk Dashboard GUI which allows the user to input the file path i.e D:\Downloads\12-Dec-2022\1234\ and then it will run in the backend this --> script.py D:\Downloads\12-Dec-2022\1234\ and generate a csv file in which I will use the splunk search command to format the data. My question would be how can I write the generator.py script so that it calls the script.py I have a template I found:
#!/usr/bin/env python
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
from splunklib.searchcommands import \
dispatch, GeneratingCommand, Configuration, Option, validators
@Configuration()
class %(command.title())Command(GeneratingCommand):
""" %(synopsis)
##Syntax
%(syntax)
##Description
%(description)
"""
def generate(self):
# Put your event code here
# To connect with Splunk, use the instantiated service object which is created using the server-uri and
# other meta details and can be accessed as shown below
# Example:-
# service = self.service
pass
dispatch(%(command.title())Command, sys.argv, sys.stdin, sys.stdout, __name__)
However, I am not sure like how to write it such that this command will accept an argument (eg. file path inputted by the user) So how I Forsee it is I have 3 things
1. Custom search command named mycommand 2. my own script.py which accepts one argument (a file path) use to run and generate stats 3. Splunk search command
So once I have the custom search command mycommand I can use it in splunk search | mycommand <user input>
something like that..however writing the custom search command am not sure how to make it accept an argument inputted for the user in the splunk gui. can anyone help please?
... View more