Hi
I want to run the script from a button on a dashboard.
Running the RUN_TEST.sh from as an alert is working (Alert_test).
Do i call the alert that will then call the .sh or can i call the .sh directly?
Example of button. But i have no idea how to run the RUN_TEST.sh (splunk/bin/scripts/RUN_TEST.sh)
<html>
<button class="btn" data-token-json="{"execute_save_test":" RUN_TEST.sh }">RUN TEST SCRIPT</button>
</html>
Thanks in advance
Rob
Hi,
I will try to explain what I have done. Probably it will be helpful and you can customize according to your need.
I saved my below batch file in a place where I have execute permission. In this case I saved in my desktop with name sid.bat
@echo off
color 0a
mode 1000
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random% > C:\Users\s.d.chakraborty\Desktop\test.txt
Then I created a custom command like below with name test.py and saved in my apps bin folder as usual.
import subprocess
subprocess.call([r'C:\Users\s.d.chakraborty\Desktop\sid.bat'])
I configured commands.conf like below,
[testcmd]
filename = test.py
enableheader = true
outputheader = true
requires_srinfo = true
supports_getinfo = true
supports_multivalues = true
supports_rawargs = true
The I created a sample dashboard with checkbox to run the script. Here you can replace with your HTML button logic as well for token setting.
<form>
<label>demo</label>
<search>
<query>| testcmd | eval ignore = $form.tokQuery$</query>
</search>
<fieldset submitButton="false">
<input type="checkbox" token="dummy" searchWhenChanged="true">
<label></label>
<choice value="run">Run</choice>
<delimiter> </delimiter>
<change>
<set token="form.tokQuery">nothing</set>
</change>
</input>
</fieldset>
</form>
if everything goes file it should create a file called test.txt.
Please let me know hot it goes for you. I tested it once and it works for me.
Sid
Hi @sdchakraborty,
I tried to disable supports_getinfo in commands.conf and it works perfectly 🙂
Thank you for your detailed steps above. God bless you!
No worries mate. If this resolves your issue please accept it as answer. Have a nice day.
Sid
Hi @sdchakraborty ,
Tried this and it works for me. However, there were multiple results for my script. The script inside the *.py will send an email to specific recipients, but there were 3 emails being sent upon single execution. Even if I only tried this on adhoc search command, the error is still the same. See below.
01-28-2019 15:04:31.435 ERROR script - Getinfo probe failed for external search command ''
01-28-2019 15:04:31.435 ERROR SearchPhaseGenerator - Fallback to two phase search failed:Error in 'script': Getinfo probe failed for external search command ''
01-28-2019 15:04:31.436 ERROR SearchOrchestrator - Error in 'script': Getinfo probe failed for external search command ''
This is my first time to use .py. Am I missing some config needed for python script? Thanks in advance.
@robertlynch2020 how about you set a token on HTML button click using Splunk JS and Simple XML JS extension (may be the token value can be shell script name itself). Then run the SPL with script command, which will execute only when the token is set (i.e. on HTML button click).
@robertlynch2020 Is your problem resolved? If so, please accept the answer to help future readers.