Getting Data In

Javascript(HTML) and Python

jadengoho
Builder

Good day,
Is it possible to change the value of the python script and trigger it to run

example:
I have a JAVA SCRIPT code that get a value from splunk HTML,
what i want is to change a specific data from the JavaScript to python script.

and after it change it will run the python script , is it possible ?

Tags (1)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi @jadengoho,

Well Yes you can do it by following these steps.

1) Create a endpoint in Splunk app which handle the HTTP request from client side and update the python file using requested value. For updating python file and executing it refer python file handling examples and for executing python refer subprocess example.

2) Create a javascript which call the Splunk endpoint and handle response.

Well, I'm not sure about to change a python script value is safe or efficient for your requirement but I suggest you can handle your all dynamic value in any config file OR property file which can be used in python code as a value parameter. So my suggetsed steps are:

1) Create a endpoint in Splunk app which handle the HTTP request from client side and update the config or property file using requested value. For updating the config or property file refer python file handling examples and for executing python refer subprocess example.

2) Create a javascript which call the Splunk endpoint and handle response.

Let me know if any difficulties in executing these steps.

jadengoho
Builder

HI @kamlesh_vaghela,
is it possible to have a java script code that change the endpoints for example the macro.
as of now i have a python code this :

from splunklib.client import connect
service = connect(username="admin", password="changeme", host="localhost", app="ml_churn")
service.post('properties/macros/SAMPLE', definition="4")
print service.get('properties/macros/SAMPLE/definition')["body"]

is it possible to run this code JAVASCRIPT ?

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

Hi @jadengoho,
Here is the best example I found for what @kamlesh_vaghelahas suggested.
https://www.hurricanelabs.com/splunk-tutorials/splunk-custom-endpoints-part-1-the-basics

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Mile High Learning with Splunk University, Denver, Colorado

If Denver is known for its mile-high elevation, Splunk University is about to raise the bar on technical ...

IT Service Intelligence 5.0 Series: Your Guide to the June Launch

We are excited to announce the June release of Splunk IT Service Intelligence (ITSI) 5.0. This update ...

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...