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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...