Splunk Dev

Create a HTML form that post to a python script

splunkcvc
New Member

I have a html page with a form and want the the form to submit to a python script.

Questions:
Where under a custom app would you place the python script?
What url would I put in the form action to hit the script?

Tags (1)
0 Karma

LukeMurphey
Champion

I would use a SplunkWeb controller for this. Here is how you would make it:

Step 1: Make the controller binary

Make an executable in the app under the path: $SPLUNK_HOME/etc/apps//appserver/controllers/. If your controller was called my_custom_controller, it would be under: $SPLUNK_HOME/etc/apps/appserver/controllers/my_custom_controller.py.

See the following example of a Splunk controller: https://github.com/LukeMurphey/splunk-web-input/blob/master/src/appserver/controllers/web_input_cont...

Step 2: Expose the controller

Make a web.conf in the app under the path: $SPLUNK_HOME/etc/apps//default/web.conf. Add a line to this file that exposes your controller. Below is an example (assuming your controller is named called my_custom_controller.py):

[endpoint:my_custom_controller]

Restart Splunk for the controller to be visible. You can verify that your controller is recognized by navigating to /paths with your browser (e.g. http://mysplunkserver/paths); your controller should be listed if this worked (just search for your controller name, e.g. "my_custom_controller").

Step 3: Wire-up your HTML form

Your controller will be exposed under the path /custom//my_custom_controller. For example, if you declared a function called "do_something" within your controller called "my_custom_controller" which is included the in the "my_app" app, then you could access that function from an HTML form with the URL "/custom/my_app/my_custom_controller/do_something").

0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...