Getting Data In

Can REST API be used to execute a python script on Splunk server?

simpkins1958
Contributor

Could we add a custom python script on our Splunk server and have it executed from a client using the Splunk REST API?

paramagurukarth
Builder

Are you looking for something like this
https://wiki.splunk.com/Community:40GUIDevelopment

0 Karma

highsplunker
Contributor

SOLVED for similar case
"Error when I run custom Python script from one server to another sever using cURL (Search Factory: Unknown search command)"

https://answers.splunk.com/answers/747926/error-when-i-run-custom-python-script-from-one-ser.html?ch...

0 Karma

hardikJsheth
Motivator

Yes you can do that. One of the way is Modular Inputs.

0 Karma

jonmargulies
Path Finder

Yes! One way to do this is with a custom search command. Let's say your python script is called "testscript". You could rewrite as (or call it from) a Python script that Splunk recognizes as a custom search command, and then you could execute it as a Splunk search like this: "| testscript". Then you could call that search (adding arguments as needed) using the Splunk REST API.

Here's a link that explains how to create custom search commands: http://dev.splunk.com/view/python-sdk/SP-CAAAEU2
Here's the basic documentation on running a search from Python using Splunk's REST API: http://dev.splunk.com/view/python-sdk/SP-CAAAEE5

highsplunker
Contributor

Guys,
why this does not work from a Linux myServer2?
curl -k -u 'myUser:myPwd' https://myServer1:8089/services/search/jobs/export -d search=" | makeresults | myScript " -d output_mode=csv

But OK for search = " | makeresults | eval myVal=777 "

0 Karma

highsplunker
Contributor

Again. So poor support here...

0 Karma
Get Updates on the Splunk Community!

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...