- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
All,
I am just the worst at Python, so forcing myself to use it more. I can make a connection and list the apps per the SDK example. But that is as far as I have gotten.
Looking to call my deployment server and reload deploy class
1) How do I make that API?
2) How would I find the name of the method for reloading the deploy class
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @daniel333,
You can try below script to reload deployment server using Python SDK.
import sys
sys.path.append('splunk-sdk-python-1.6.5')
import splunklib.six as six
import urllib
from xml.etree import ElementTree
import getpass
HOST = raw_input("Enter splunk server hostname/ip: ")
PORT = 8089
splunkUser = raw_input("Enter Splunk Admin Username: ")
splunkPassword = getpass.getpass("Enter Splunk Admin Password: ")
sc = raw_input("Enter Serverclass name to reload OR provide hit Enter to reload all server classes: ")
connection = six.moves.http_client.HTTPSConnection(HOST, PORT)
body = urllib.urlencode({'username': splunkUser, 'password': splunkPassword})
headers = {'Content-Type': "application/x-www-form-urlencoded",
'Host': HOST
}
connection.request("POST", "/services/auth/login", body, headers)
response = connection.getresponse()
content = response.read()
connection.close()
session_key = ElementTree.XML(content).findtext("./sessionKey")
connection = six.moves.http_client.HTTPSConnection(HOST, PORT)
headers = {'Content-Type': "application/x-www-form-urlencoded",
'Host': HOST,
'Authorization': "Splunk %s" % session_key
}
if not sc:
body = ''
else:
body = urllib.urlencode({"serverclass": sc})
connection.request("POST", "/services/deployment/server/config/_reload", body, headers)
response = connection.getresponse()
content = response.read()
connection.close()
if response.status == 200:
if not sc:
print 'Deployment Server reloaded successfully'
else:
print 'Deployment server for class ' + sc + ' reloaded successfully'
else:
print 'Deployment Server reload failed'
print content
if you want to reload whole deployment server then just Hit Enter while asking for Serverclass name otherwise provide serverclass name
For example:
Enter splunk server hostname/ip: mysplunkserver
Enter Splunk Admin Username: admin
Enter Splunk Admin Password:
Enter Serverclass name to reload OR provide hit Enter to reload all server classes: myServerClass
Above example reload myServerClass
server class.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @daniel333,
You can try below script to reload deployment server using Python SDK.
import sys
sys.path.append('splunk-sdk-python-1.6.5')
import splunklib.six as six
import urllib
from xml.etree import ElementTree
import getpass
HOST = raw_input("Enter splunk server hostname/ip: ")
PORT = 8089
splunkUser = raw_input("Enter Splunk Admin Username: ")
splunkPassword = getpass.getpass("Enter Splunk Admin Password: ")
sc = raw_input("Enter Serverclass name to reload OR provide hit Enter to reload all server classes: ")
connection = six.moves.http_client.HTTPSConnection(HOST, PORT)
body = urllib.urlencode({'username': splunkUser, 'password': splunkPassword})
headers = {'Content-Type': "application/x-www-form-urlencoded",
'Host': HOST
}
connection.request("POST", "/services/auth/login", body, headers)
response = connection.getresponse()
content = response.read()
connection.close()
session_key = ElementTree.XML(content).findtext("./sessionKey")
connection = six.moves.http_client.HTTPSConnection(HOST, PORT)
headers = {'Content-Type': "application/x-www-form-urlencoded",
'Host': HOST,
'Authorization': "Splunk %s" % session_key
}
if not sc:
body = ''
else:
body = urllib.urlencode({"serverclass": sc})
connection.request("POST", "/services/deployment/server/config/_reload", body, headers)
response = connection.getresponse()
content = response.read()
connection.close()
if response.status == 200:
if not sc:
print 'Deployment Server reloaded successfully'
else:
print 'Deployment server for class ' + sc + ' reloaded successfully'
else:
print 'Deployment Server reload failed'
print content
if you want to reload whole deployment server then just Hit Enter while asking for Serverclass name otherwise provide serverclass name
For example:
Enter splunk server hostname/ip: mysplunkserver
Enter Splunk Admin Username: admin
Enter Splunk Admin Password:
Enter Serverclass name to reload OR provide hit Enter to reload all server classes: myServerClass
Above example reload myServerClass
server class.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. It was helpful.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wow! Exactly what I was trying to build.
1) I see you're not importing the SDK, does that not offer the functionality ?
2) I see you used this endpoint,how would I have found that on my own? /services/deployment/server/config/_reload
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi,
- I am importing Splunk SDK for Python in my script, see
sys.path.append('splunk-sdk-python-1.6.5')
- To use different Splunk REST API start with this documentation , if you will not able to find required REST API in documentation then run test splunk instance and do your work using CLI or Splunk Web and then check
$SPLUNK_HOME/var/log/splunk/splunkd_access.log
to find which REST API Splunk fired, you will get API but what parameter you need to pass for those API is trail and error method.
