Splunk Dev

How to customize a button in the dashboard to run a python script using SplunkJS?

xuehui
New Member

In my dashboard, I want to create a button that runs a python script when it's clicked.

Can I achieve this using SplunkJS?

Labels (2)
Tags (2)
0 Karma

shaskell_splunk
Splunk Employee
Splunk Employee

Splunkjs is Javascript library and it runs in the browser on the client. Python, on the other hand, is an interpreted language that runs server side and isn't exposed via the UI. What does your Python script do? Is there any reason what you're trying to accomplish in Python can't be done purely in Javascript?

It would be helpful to understand what you're trying to do when the button is clicked to suggest a possible solution.

0 Karma

xuehui
New Member

The python script is an API of other program.
I need call this API when click a button to make that program do something.
And, To run the API need some classlib, I think in javascript to call this API is impossible,or troublesome.
Thank you.

0 Karma

shaskell_splunk
Splunk Employee
Splunk Employee

Do you need to use the results of a search to send to an API for validation? I'm still not understanding what exactly you're trying to accomplish and what the workflow is. If so, you could probably handle this with a custom search command.

You can absolutely use Javascript to call an API. The bigger question is if you need to use credentials to authenticate with the API. It also sounds like you're not familiar with coding in Javascript so that's going to be the biggest barrier. To call a REST API in javascript, look at jQuery's ajax.

https://api.jquery.com/jquery.ajax/

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...