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!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...