You can use below code to reload DS from splunklib.binding import HTTPError
import splunk.clilib.cli_common as scc
def trigger_reload_deploy_server(self, sc=None):
"""Triggers the 'reload deploy-server' command via the Splunk REST API."""
try:
# Trigger the 'reload deploy-server' command using the REST API
log("INFO","Triggering 'reload deploy-server' command.",file_name="getdiaginfo")
splunkd_uri = scc.getMgmtUri()
session_key = self.service.token
endpoint = splunkd_uri + "/services/deployment/server/config/_reload"
headers = {"Authorization": f"Splunk {session_key}", "Content-Type": "application/json"}
# Prepare the request body
if not sc:
body = ''
else:
body = urllib.parse.urlencode({"serverclass": sc})
update_response = requests.post(endpoint, headers=headers, data=body, verify=False)
if update_response.status_code == 200:
log("INFO", "--> 'reload deploy-server' command triggered successfully.", file_name="getdiaginfo")
return True
else:
log("ERROR", f"Failed to trigger 'reload deploy-server'. Status: {update_response.status_code}, Response: {update_response.text}", file_name="getdiaginfo")
return False
except HTTPError as e:
log("ERROR",f"Failed to trigger 'reload deploy-server': {e}",file_name="getdiaginfo")
return False
@Configuration()
class Getdiaginfo(GeneratingCommand):
server_list = Option(require=False)
def generate(self):
trigger_reload_deploy_server(self, <"serverclass-name">)
dispatch(Getdiaginfo, sys.argv, sys.stdin, sys.stdout, __name__)
... View more