Hi
Here is what I am trying to accomplish:
1. Click a button on dashboard
2. it calls a script (Python or JavaScript)
3. the Script will then run some shell script and do the CLI search which creates a CSV file on local directory
4. Returns the value
5. downloads the CSV file created on the server to the Browser
Can i call python script by click on a button in dashboard?
Or, should i call Javascript and then that javascript calls python script?
Or, can i accomplish this by only coding javascript?
my splunk is running on Linux server.
Looking forward for your replies.
Thank you.
The two links will help you in exposing your python method for a http call..
http://wiki.splunk.com/Community:40GUIDevelopment
After writing your python method just add a button to your dashboard and make an ajax call to your python 🙂
I'll answer here. With pictures. Going through the difficulty of writing a button to export results to CSV is not worth they payoff. Every single panel in a Splunk Dashboard, and in the search results, by default, has a "Button On the Dashboard, That When Clicked, Will Download a CSV Through a User's Browser". That is the requirement here, no? The functionality exists already, why duplicate it? I don't always do things "just because the customer asked for it", instead, show them the built-in, supported, automatic, scaleable feature. They will love you for it. Instead of spending a week Developing this feature, you now have spent 1 hour explaining it. Much better ROI if you ask me.
Every Panel has this :
Clicking the second button gives you this:
This is exactly what you wanted. A button on a dashboard to export data to CSV, with UNLIMITED results.
The two links will help you in exposing your python method for a http call..
http://wiki.splunk.com/Community:40GUIDevelopment
After writing your python method just add a button to your dashboard and make an ajax call to your python 🙂
Hi paramgurukarthikeyan
Thanks for the reply.
Yes, i think i want to try this too!
You are welcome 🙂
I have to run, but hopefully I'll remember to update this with more details when I have time.
I suggest using the SearchManager from the SplunkJS stack: http://dev.splunk.com/view/webframework-developapps/SP-CAAAENJ
You can include the javascript on the page using this method: http://docs.splunk.com/Documentation/Splunk/6.1.5/Viz/CustomizeSimpleXML
Then you can export the CSV in the javascript: http://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-sid...
Hi bruceclarke!!
Thanks for the reply!!
I am trying as you have mentioned, but do i need to install Node.js first?
Node.js is not needed. You will need to read up on bootstrap, jquery, mvc, backbone, and the SplunkJS documentation itself, as well as custom web endpoints, advanced configurations, and a some best practices on securing the endpoint itself. See my answer above. If your question is still not answered exactly as you need it to be, please clarify your answer with even more detail, as what you have described is already implemented in the core Splunk.
Hi alacercogitatus
Thanks for the reply.
what i am trying to accomplish is, to
1) click a button on dashboard
2) runs two separate search which outputs two csv files
3) merge those two csv files
4) download from web browser
Using CLI commands, yes i can do it. But we need to make a custom button on the dashboard as well.
i found the link below, which you are explaining about how to call python from html view
https://answers.splunk.com/answers/352862/how-to-call-a-python-script-from-an-html-view.html
and, i think this is what i want to do.
Why do you have to create the CSV file with a Python script? If you actually create the CSV using a Splunk Search you could use |outputcsv csvexport.csv
or just export it from the dashboard. Also see here: https://answers.splunk.com/answers/869/export-results-to-csv.html
Hi guys,
thanks for the reply! I appreciate it.
Sorry i wasn't clear of my question.
I am doing this for my customer's request, and they specifically would like to "click a button on the dashboard" to to export the CSV.
Generally, is it possible to call python script by clicking a button on the dashboard? if so, could you give me some way forward for this?
Thank you.