Skip to content

Commit 0111016

Browse files
committed
Version 1.2.0
This version includes a few major changes: - `file_per_ko` mode, disabled by default, if enabled outputs 1 file per knowledge object instead of including all knowledge objects of a type within 1 file - `next_scheduled_time` attribute removed from savedsearches (this results in less unnnessary git commits) - code updated so that newlines are used in the json files, this makes the files stored in git more human readable and easier to see what changed between backups - support added for http/https based git repositories in addition to ssh-based repo's If you would like to use `file_per_ko` this will result in a lot more files in the git repository but this will make it easier to see the history of changes in each file Note that you must set `file_per_ko` to true in both the backup & restore for this to work as expected, also if you change the setting you will need to re-create or wipe the repo as the files are stored differently Updated all dashboards to include version="1.1" tag as required by new Splunk versions Updated to Splunk python SDK 1.1.16 This version fixes a bug introduced by 1.1.13, version 1.1.13 was removed from SplunkBase due to an error in the code
1 parent ece04c3 commit 0111016

14 files changed

+718
-195
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ There are also many online resources to help with learning git
165165
- proxy - optional, if supplied provides a proxy setting to use to access the srcURL (https proxy). Use https://user:password:[email protected]:3128 and the application will obtain the password for the entry "passwordinpasswordsconf". If password: is not used the password is used as per a normal proxy setting, for example https://user:[email protected]:3128
166166
- git_name - optional, if provided runs git config user.name to override the name used on this particular repository for git commits
167167
- git_email - optional, if provided runs git config user.email to override the email used on this particular repository for git commits
168+
"More settings"
169+
- git_branch - optional, sets the git branch to use, defaults to master
170+
- git_proxy - optional, if supplied provides a proxy setting to use to access the git repository (https proxy). Use https://user:password:[email protected]:3128 and the application will obtain the password for the entry 'passwordinpasswordsconf'. If password: is not used the password is used as per a normal proxy setting, for example https://user:[email protected]:3128
171+
- file_per_ko - optional, do you want one file per knowledge object? Or a combined file? Defaults to false (i.e. 1 large file for global dashboards in an app). Note that if you change this setting you will need to re-create or wipe the repository as the files are stored differently...Note this setting should match in both backup and restore modular inputs for a particular repo
172+
168173
"More settings"
169174
- interval - how often the backup should run, if not set the backup will only run on restart of the Splunk instance or when you save this configuration...
170175

@@ -182,6 +187,9 @@ There are also many online resources to help with learning git
182187
- git_command - optional, the location of the git command, this is mainly used on Windows where the git command may not be in the PATH of the user running Splunk
183188
- ssh_command - optional, the location of the ssh command, this is mainly used on Windows where the git command may not be in the PATH of the user running Splunk
184189
- proxy - optional, if supplied provides a proxy setting to use to access the destURL (https proxy). Use https://user:password:[email protected]:3128 and the application will obtain the password for the entry "passwordinpasswordsconf". If password: is not used the password is used as per a normal proxy setting, for example https://user:[email protected]:3128
190+
- git_branch - optional, sets the git branch to use, defaults to master
191+
- git_proxy - optional, if supplied provides a proxy setting to use to access the git repository (https proxy). Use https://user:password:[email protected]:3128 and the application will obtain the password for the entry 'passwordinpasswordsconf'. If password: is not used the password is used as per a normal proxy setting, for example https://user:[email protected]:3128
192+
- file_per_ko - optional, do you want one file per knowledge object? Or a combined file? Defaults to false (i.e. 1 large file for global dashboards in an app). Note that if you change this setting you will need to re-create or wipe the repository as the files are stored differently...Note this setting should match in both backup and restore modular inputs for a particular repo
185193

186194
"More settings"
187195
- interval - how often should the remote server be checked to see if a restore is required. If you are on-prem and using the dynamic restore dashboard you do not need to set an interval, if this is a cloud based system or using the non-dynamic dashboard this is the interval to check the remote server for if a restore needs to be run (i.e. how long it is between a user requesting a restore and this script checking/polling the remote system to run the restoration job)
@@ -266,6 +274,23 @@ To do this you will need to install Version Control For SplunkCloud on your Splu
266274
[SplunkVersionControlCloud github](https://github.com/gjanders/SplunkVersionControlCloud)
267275

268276
## Release Notes
277+
### 1.2.0
278+
This version includes a few major changes:
279+
- `file_per_ko` mode, disabled by default, if enabled outputs 1 file per knowledge object instead of including all knowledge objects of a type within 1 file
280+
- `next_scheduled_time` attribute removed from savedsearches (this results in less unnnessary git commits)
281+
- code updated so that newlines are used in the json files, this makes the files stored in git more human readable and easier to see what changed between backups
282+
- support added for http/https based git repositories in addition to ssh-based repo's
283+
284+
If you would like to use `file_per_ko` this will result in a lot more files in the git repository but this will make it easier to see the history of changes in each file
285+
286+
Note that you must set `file_per_ko` to true in both the backup & restore for this to work as expected, also if you change the setting you will need to re-create or wipe the repo as the files are stored differently
287+
288+
Updated all dashboards to include version="1.1" tag as required by new Splunk versions
289+
290+
Updated to Splunk python SDK 1.1.16
291+
292+
This version fixes a bug introduced by 1.1.13, version 1.1.13 was removed from SplunkBase due to an error in the code
293+
269294
### 1.1.13
270295
Updated saved search `Splunk Version Control Audit Query POST` with new regex
271296

README/inputs.conf.spec

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ srcPassword = <value>
88
gitTempDir = <value>
99
* location where to store the output of the script on the filesystem (note this directory will be deleted/re-created but the parent dir must exist)
1010
gitRepoURL = <value>
11-
* git repository URL to store the objects (SSH URL only)
11+
* git repository URL to store the objects
1212
sslVerify = <boolean>
1313
* Set to 'true' or 'false' to enable/disable SSL verification for REST requests to `srcUrl`. Set to a path to specify a file with valid CA. (https://2.python-requests.org/en/master/user/advanced/#ssl-cert-verification)
1414
noPrivate = <boolean>
@@ -43,6 +43,10 @@ git_email = <value>
4343
* If set this runs git config user.email '<value>' once the backup git repo is cloned
4444
git_branch = <value>
4545
* Sets the git branch to use, defaults to master
46+
git_proxy = <value>
47+
* If supplied provides a proxy setting to use to access the git repository (https proxy). Use https://user:password:[email protected]:3128 and the application will obtain the password for the entry 'passwordinpasswordsconf'. If password: is not used the password is used as per a normal proxy setting, for example https://user:[email protected]:3128</description>
48+
file_per_ko = <boolean>
49+
* Do you want one file per knowledge object? Or a combined file? Defaults to false (i.e. 1 large file for global dashboards in an app). Note that if you change this you will need to re-create or wipe the repository as the files are stored differently...Note this setting should match in both backup and restore modular inputs for a particular repo
4650

4751
[splunkversioncontrol_restore://<name>]
4852
destURL = <value>
@@ -54,10 +58,9 @@ destPassword = <value>
5458
gitTempDir = <value>
5559
* location where to store the output of the script on the filesystem (note this directory will be deleted/re-created but the parent dir must exist)
5660
gitRepoURL = <value>
57-
* git repository URL to store the objects (SSH URL only)
61+
* git repository URL to restore the objects from
5862
sslVerify = <boolean>
5963
* Set to 'true' or 'false' to enable/disable SSL verification for REST requests to `srcUrl`. Set to a path to specify a file with valid CA. (https://2.python-requests.org/en/master/user/advanced/#ssl-cert-verification)
60-
6164
auditLogsLookupBackTime = <value>
6265
* This is how far back the audit logs will be checked to ensure that a restore entry is valid, this should be set to your interval time or slightly more, defaults to -1h (use Splunk format)
6366
debugMode = <boolean>
@@ -76,3 +79,7 @@ proxy = <value>
7679
* If supplied provides a proxy setting to use to access the destURL (https proxy). Use https://user:password:[email protected]:3128 and the application will obtain the password for the entry 'passwordinpasswordsconf'. If password: is not used the password is used as per a normal proxy setting, for example https://user:[email protected]:3128
7780
git_branch = <value>
7881
* Sets the git branch to use, defaults to master
82+
git_proxy = <value>
83+
* If supplied provides a proxy setting to use to access the git repository (https proxy). Use https://user:password:[email protected]:3128 and the application will obtain the password for the entry 'passwordinpasswordsconf'. If password: is not used the password is used as per a normal proxy setting, for example https://user:[email protected]:3128</description>
84+
file_per_ko = <boolean>
85+
* Do you want one file per knowledge object? Or a combined file? Defaults to false (i.e. 1 large file for global dashboards in an app). Note that if you change this you will need to re-create or wipe the repository as the files are stored differently...Note this setting should match in both backup and restore modular inputs for a particular repo

bin/splunkversioncontrol_backup.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import sys
88
import xml.dom.minidom, xml.sax.saxutils
9+
import platform
910
from splunkversioncontrol_backup_class import SplunkVersionControlBackup
1011
from splunkversioncontrol_utility import runOSProcess, get_password
1112

@@ -45,7 +46,7 @@
4546
</arg>
4647
<arg name="gitRepoURL">
4748
<title>gitRepoURL</title>
48-
<description>git repository URL to store the objects (SSH URL only)</description>
49+
<description>git repository URL to store the objects</description>
4950
</arg>
5051
<arg name="sslVerify">
5152
<title>sslVerify</title>
@@ -136,6 +137,16 @@
136137
<description>Sets the git branch to use, defaults to master</description>
137138
<required_on_create>false</required_on_create>
138139
</arg>
140+
<arg name="git_proxy">
141+
<title>git_proxy</title>
142+
<description>If supplied provides a proxy setting to use to access the git repository (https proxy). Use https://user:password:[email protected]:3128 and the application will obtain the password for the entry 'passwordinpasswordsconf'. If password: is not used the password is used as per a normal proxy setting, for example https://user:[email protected]:3128</description>
143+
<required_on_create>false</required_on_create>
144+
</arg>
145+
<arg name="file_per_ko">
146+
<title>file_per_ko</title>
147+
<description>Do you want one file per knowledge object? Or a combined file? Defaults to false (i.e. 1 large file for global dashboards in an app)</description>
148+
<required_on_create>false</required_on_create>
149+
</arg>
139150
</args>
140151
</endpoint>
141152
</scheme>
@@ -266,12 +277,36 @@ def validate_arguments():
266277
sys.exit(5)
267278

268279
gitRepoURL = val_data['gitRepoURL']
269-
(stdout, stderr, res) = runOSProcess("%s ls-remote %s" % (git_command, gitRepoURL), logger)
280+
proxy_command = ""
281+
if gitRepoURL.find("http") == 0:
282+
gitRepoHTTP = True
283+
else:
284+
gitRepoHTTP = False
285+
286+
git_proxies = {}
287+
if 'git_proxy' in val_data:
288+
git_proxies["https"] = val_data['git_proxy']
289+
if git_proxies['https'].find("password:") != -1:
290+
start = git_proxies['https'].find("password:") + 9
291+
end = git_proxies['https'].find("@")
292+
logger.debug("Attempting to replace git_proxy=%s by subsituting=%s with a password" % (git_proxies['https'], git_proxies['https'][start:end]))
293+
temp_password = get_password(git_proxies['https'][start:end], session_key, logger)
294+
git_proxies['https'] = git_proxies['https'][0:start-9] + temp_password + git_proxies['https'][end:]
295+
296+
if gitRepoHTTP and len(git_proxies) > 0:
297+
logger.debug("Adding environment variable HTTPS_PROXY before git commands")
298+
proxy_command = "HTTPS_PROXY=" + git_proxies["https"]
299+
if platform.system() == "Windows":
300+
proxy_command = "set " + proxy_command + " & "
301+
else:
302+
proxy_command = "export " + proxy_command + " ; "
303+
304+
(stdout, stderr, res) = runOSProcess("%s %s ls-remote %s" % (proxy_command, git_command, gitRepoURL), logger)
270305
#If we didn't manage to ls-remote perhaps we just need to trust the fingerprint / this is the first run?
271-
if res == False:
306+
if res == False and not gitRepoHTTP:
272307
(stdout, stderrout, res) = runOSProcess(ssh_command + " -n -o \"BatchMode yes\" -o StrictHostKeyChecking=no " + gitRepoURL[:gitRepoURL.find(":")], logger)
273308
(stdout, stderr, res) = runOSProcess("%s ls-remote %s" % (git_command, gitRepoURL), logger)
274-
309+
275310
if res == False:
276311
print_error("Failed to validate the git repo URL, stdout of '%s', stderr of '%s'" % (stdout, stderr))
277312
sys.exit(6)

0 commit comments

Comments
 (0)