Getting Data In

Splunk Adaptive Response sending post command in REST API

ramesh_babu71
Path Finder

Hi,

I am trying to create a new app which will be used to send a Splunk Adaptive response via REST API. I am able get the response from Splunk REST API using using below code

     headers_server, content_server = rest.simpleRequest('/services/server/info?output_mode=json', sessionKey=sessionKey)

However my requirement is to convert the below curl command which has a POST action to python REST API.

curl -k -u admin:Password1 https://localhost:8089/services/data/inputs/script/restart?output_mode=json -d script=".\bin\script_test\windows.bat"

Would require you help on how to send this POST command in python REST API format.

0 Karma
1 Solution

harsmarvania57
SplunkTrust
SplunkTrust

Hi @ramesh_babu71,

Please try this python code

   rest.simpleRequest('/services/data/inputs/script/restart', sessionKey=sessionKey, postargs={'script': ".\bin\script_test\windows.bat"}, method='POST', raiseAllErrors=True)

EDIT1: Updated code, but what you want to achieve. It seems like /services/data/inputs/script/restartgiving me HTTP 400 error with GET request but didn't tried POST request.

EDIT2: Based on this doc http://docs.splunk.com/Documentation/Splunk/6.6.4/RESTREF/RESTinput#data.2Finputs.2Fscript.2Frestart
POST request should be like

rest.simpleRequest('/servicesNS/nobody/<APPNAME>/data/inputs/script/restart', sessionKey=sessionKey, postargs={'script': ".\bin\script_test\windows.bat"}, method='POST', raiseAllErrors=True)

View solution in original post

0 Karma

harsmarvania57
SplunkTrust
SplunkTrust

Hi @ramesh_babu71,

Please try this python code

   rest.simpleRequest('/services/data/inputs/script/restart', sessionKey=sessionKey, postargs={'script': ".\bin\script_test\windows.bat"}, method='POST', raiseAllErrors=True)

EDIT1: Updated code, but what you want to achieve. It seems like /services/data/inputs/script/restartgiving me HTTP 400 error with GET request but didn't tried POST request.

EDIT2: Based on this doc http://docs.splunk.com/Documentation/Splunk/6.6.4/RESTREF/RESTinput#data.2Finputs.2Fscript.2Frestart
POST request should be like

rest.simpleRequest('/servicesNS/nobody/<APPNAME>/data/inputs/script/restart', sessionKey=sessionKey, postargs={'script': ".\bin\script_test\windows.bat"}, method='POST', raiseAllErrors=True)
0 Karma

ramesh_babu71
Path Finder

Thanks Harshil. This is what I was looking for. The POST command lets me to restart/enable the scripted input

However a slight modification was required as \b in ".\bin...."python is taken as ASCII so we have to tell python to take it as string using r in front

 rest.simpleRequest('/services/data/inputs/script/restart', sessionKey=sessionKey, postargs={'script': r".\bin\script_test\windows.bat"}, method='POST', raiseAllErrors=True)
0 Karma

harsmarvania57
SplunkTrust
SplunkTrust

Great that it helped you, I have converted my comment to answer so you can accept it and thanks for the explanation about ASCII character.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...