Skip to content

Commit 58669cc

Browse files
committed
- splunkversioncontrol_utility.py - additional logging for errors
- `splunkversioncontrol_backup.py` - `splunkversioncontrol_backup_class.py` - `splunkversioncontrol_restore.py` - `splunkversioncontrol_rest_restore.py` - `splunkversioncontrol_restore_class.py` Modified to use the REST API search/jobs v2 endpoint
1 parent 231d486 commit 58669cc

8 files changed

+23
-11
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,18 @@ As of October 2022, there are still no signs of version control within the Splun
326326
- [Search Head Backup](https://splunkbase.splunk.com/app/6438) - backup to an index, works in Splunk Cloud
327327

328328
## Release Notes
329+
### 1.2.14
330+
- `splunkversioncontrol_utility.py` - additional logging for errors
331+
332+
- `splunkversioncontrol_backup.py`
333+
- `splunkversioncontrol_backup_class.py`
334+
- `splunkversioncontrol_restore.py`
335+
- `splunkversioncontrol_rest_restore.py`
336+
- `splunkversioncontrol_restore_class.py`
337+
338+
Modified to use the REST API search/jobs v2 endpoint
339+
340+
329341
### 1.2.13
330342
- `splunkversioncontrol_restore_class.py` - updated to show a message if the app in question does not exist
331343

bin/splunkversioncontrol_backup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def validate_arguments():
312312

313313
#Run a sanity check and make sure we can connect into the remote Splunk instance
314314
if not useLocalAuth:
315-
url = val_data['srcURL'] + "/servicesNS/nobody/%s/search/jobs/export?search=makeresults" % (appName)
315+
url = val_data['srcURL'] + "/servicesNS/nobody/%s/search/v2/jobs/export" % (appName)
316316
srcUsername = val_data['srcUsername']
317317
srcPassword = val_data['srcPassword']
318318
if srcPassword.find("password:") == 0:
@@ -330,7 +330,7 @@ def validate_arguments():
330330

331331
try:
332332
logger.debug("Running query against URL %s with username %s proxies_length=%s sslVerify=%s" % (url, srcUsername, len(proxies), sslVerify))
333-
res = requests.get(url, auth=(srcUsername, srcPassword), verify=sslVerify, proxies=proxies)
333+
res = requests.post(url, auth=(srcUsername, srcPassword), verify=sslVerify, proxies=proxies, data={"search": "| makeresults"})
334334
logger.debug("End query against URL %s with username %s" % (url, srcUsername))
335335

336336
if (res.status_code != requests.codes.ok):

bin/splunkversioncontrol_backup_class.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,11 +1094,11 @@ def logStats(self, successList, type, app):
10941094
def without_keys(self, d, keys):
10951095
return {x: d[x] for x in d if x not in keys}
10961096

1097-
#Run a Splunk query via the search/jobs endpoint
1097+
#Run a Splunk query via the search/v2/jobs endpoint
10981098
def runSearchJob(self, query, app_context=None, earliest=None, latest=None):
10991099
if not app_context:
11001100
app_context = self.appName
1101-
url = self.splunk_rest + "/servicesNS/-/%s/search/jobs" % (app_context)
1101+
url = self.splunk_rest + "/servicesNS/-/%s/search/v2/jobs" % (app_context)
11021102
logger.debug("i=\"%s\" Running requests.post() on url=%s with user=%s query=\"%s\", proxies_length=%s, sslVerify=%s, earliest=%s, latest=%s" % (self.stanzaName, url, self.srcUsername, query, len(self.proxies), self.sslVerify, earliest, latest))
11031103
data = { "search" : query, "output_mode" : "json", "exec_mode" : "oneshot" }
11041104

bin/splunkversioncontrol_rest_restore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ def handle_POST(self):
278278

279279
self.runHttpRequest(url, headers, None, 'delete', 'wiping kvstore splunkversioncontrol_rest_restore_status after completed run', sslVerify=sslVerify)
280280

281-
#Run a Splunk query via the search/jobs endpoint
281+
#Run a Splunk query via the search/v2/jobs endpoint
282282
def runSearchJob(self, url, appname, headers, auth, username, earliest_time, sslVerify=False):
283-
url = url + "/servicesNS/-/%s/search/jobs" % (appname)
283+
url = url + "/servicesNS/-/%s/search/v2/jobs" % (appname)
284284
query = "savedsearch \"Splunk Version Control Audit Query POST\" username=\"%s\" | stats count | where count>0" % (username)
285285
logger.debug("Running requests.post() on url=%s query=\"%s\"" % (url, query))
286286
data = { "search" : query, "output_mode" : "json", "exec_mode" : "oneshot", "earliest_time" : earliest_time }

bin/splunkversioncontrol_restore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def validate_arguments():
237237

238238
#Run a sanity check and make sure we can connect into the remote Splunk instance
239239
if not useLocalAuth:
240-
url = val_data['destURL'] + "/servicesNS/nobody/%s/search/jobs/export?search=makeresults" % (appName)
240+
url = val_data['destURL'] + "/servicesNS/nobody/%s/search/v2/jobs/export?search=makeresults" % (appName)
241241
destUsername = val_data['destUsername']
242242
destPassword = val_data['destPassword']
243243

bin/splunkversioncontrol_restore_class.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,9 +1228,9 @@ def automaticLookups(self, app, name, scope, username, restore_as_user, admin_le
12281228
def without_keys(self, d, keys):
12291229
return {x: d[x] for x in d if x not in keys}
12301230

1231-
#Run a Splunk query via the search/jobs endpoint
1231+
#Run a Splunk query via the search/v2/jobs endpoint
12321232
def runSearchJob(self, query, earliest_time="-1h"):
1233-
url = self.splunk_rest + "/servicesNS/-/%s/search/jobs" % (self.appName)
1233+
url = self.splunk_rest + "/servicesNS/-/%s/search/v2/jobs" % (self.appName)
12341234
logger.debug("i=\"%s\" Running requests.post() on url=%s with user=%s query=\"%s\" proxies_length=%s" % (self.stanza_name, url, self.destUsername, query, len(self.proxies)))
12351235
data = { "search" : query, "output_mode" : "json", "exec_mode" : "oneshot", "earliest_time" : earliest_time }
12361236

bin/splunkversioncontrol_utility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def runOSProcess(command, logger, timeout=60, shell=True):
4343
return "", "timeout after %s seconds" % (timeout), False
4444
else:
4545
if proc.returncode != 0:
46-
logger.debug("OS process exited with non-zero code of %s, for command %s" % (proc.returncode, command))
46+
logger.debug("OS process exited with non-zero code of %s, for command %s, stdout %s, stderr %s" % (proc.returncode, command, stdout, stderr))
4747
res = False
4848
else:
4949
logger.debug("OS process exited with zero code, for command %s" % (command))

default/app.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ label = SplunkVersionControl
1212
[launcher]
1313
author = Gareth Anderson
1414
description = Version Control software for Splunk instances (backup/restore from git)
15-
version = 1.2.13
15+
version = 1.2.14
1616

1717
[package]
1818
id = SplunkVersionControl

0 commit comments

Comments
 (0)