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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...