Skip to content

Instantly share code, notes, and snippets.

@sduff
Created September 5, 2017 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sduff/456b8141937a903480d89d28e70815d9 to your computer and use it in GitHub Desktop.
Save sduff/456b8141937a903480d89d28e70815d9 to your computer and use it in GitHub Desktop.
Modify a Splunk Saved Search via Python, using Requests
import time # need for sleep
from xml.dom import minidom
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
base_url = 'https://localhost:8089'
username = 'admin'
password = 'changeme'
app = "search"
saved_search_name = "search_name"
new_spl = "index=*"
r = requests.get(base_url+"/servicesNS/admin/search/auth/login",
data = {'username':username,'password':password},
verify = False)
session_key = minidom.parseString(r.text).getElementsByTagName('sessionKey')[0].firstChild.nodeValue
print ("Session Key:", session_key)
r = requests.post(base_url + '/servicesNS/'+username+'/'+app+'/saved/searches/'+saved_search_name,
headers = { 'Authorization': ('Splunk %s' %session_key)},
data = {'search': new_spl},
verify = False)
print(r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment