Skip to content

Commit e2bdd24

Browse files
committed
update load setting for purge with sed regex version
1 parent d446bba commit e2bdd24

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

splunkconf-backup/bin/splunkconf-backup.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ exec > /tmp/splunkconf-backup-debug.log 2>&1
138138
# 20241101 change regex to pcre regex for conf file matching and improve it to catch variables with number and url like values
139139
# 20241101 initial support for allowing point in time option to kvstore (this change recovery so we need other changes)
140140
# 20241103 change var to KVSTOREPOINTINTIMEMODE
141+
# 20250917 add more debug logging for conf file loading
141142

142-
VERSION="20241103a"
143+
VERSION="20250917a"
143144

144145
###### BEGIN default parameters
145146
# dont change here, use the configuration file to override them
@@ -592,18 +593,18 @@ function checklock() {
592593
fi
593594
}
594595

595-
596596
function load_settings_from_file () {
597597
FI=$1
598598
if [ -e "$FI" ]; then
599+
debug_log "loading settings for file $FI"
599600
# to match empty line or comment line
600601
regclass2="^(#|\[)"
601602
# Read the file line by line, remove spaces then create a variable if start by splunk
602603
while read -r line; do
603604
if [[ "${line}" =~ $regclass2 ]]; then
604-
debug_log "comment line or stanza line with line=$line"
605+
debug_log "form: comment line or stanza line with line=$line"
605606
elif [ -z "${line-unset}" ]; then
606-
debug_log "empty line"
607+
debug_log "form : empty line"
607608
elif [[ $(echo "$line" | sed -nE 's/([a-zA-Z0-9_]+)\s*=\s*"?([a-zA-Z0-9_:/\.\-]+)"?/\1 \2/p') ]]; then
608609
# sed -E turn PCRE like syntax
609610
read -r var_name var_value <<< "$(echo "$line" | sed -nE 's/([a-zA-Z0-9_]+)\s*=\s*"?([a-zA-Z0-9_:/\.\-]+)"?/\1 \2/p')"
@@ -614,6 +615,7 @@ function load_settings_from_file () {
614615
debug_log "KO:invalid form line=$line"
615616
fi
616617
done < $FI
618+
debug_log "end of loading settings for file $FI"
617619
else
618620
debug_log "file $FI is not present"
619621
fi

splunkconf-backup/bin/splunkconf-purgebackup.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ exec > /tmp/splunkconf-purgebackup-debug.log 2>&1
5858
# 20240629 replace direct var inclusion with loading function logic
5959
# 20240701 add debugmode flag as arg to splunkconf-backup-helper
6060
# 20230702 add more ec2 tag support taken from backup part
61+
# 20250917 update load setting with regex version (same as for backup)
6162

62-
VERSION="20240702a"
63+
VERSION="20250917a"
6364

6465
###### BEGIN default parameters
6566
# dont change here, use the configuration file to override them
@@ -247,24 +248,26 @@ function check_cloud() {
247248
function load_settings_from_file () {
248249
FI=$1
249250
if [ -e "$FI" ]; then
250-
regclass="([a-zA-Z]+)[[:space:]]*=[[:space:]]*\"{0,1}([a-zA-Z0-9_\-]+)\"{0,1}"
251+
debug_log "loading settings for file $FI"
252+
# to match empty line or comment line
251253
regclass2="^(#|\[)"
252254
# Read the file line by line, remove spaces then create a variable if start by splunk
253255
while read -r line; do
254256
if [[ "${line}" =~ $regclass2 ]]; then
255-
debug_log "comment line or stanza line with line=$line"
257+
debug_log "form: comment line or stanza line with line=$line"
256258
elif [ -z "${line-unset}" ]; then
257-
debug_log "empty line"
258-
elif [[ "${line}" =~ $regclass ]]; then
259-
var_name=${BASH_REMATCH[1]}
260-
var_value=${BASH_REMATCH[2]}
259+
debug_log "form : empty line"
260+
elif [[ $(echo "$line" | sed -nE 's/([a-zA-Z0-9_]+)\s*=\s*"?([a-zA-Z0-9_:/\.\-]+)"?/\1 \2/p') ]]; then
261+
# sed -E turn PCRE like syntax
262+
read -r var_name var_value <<< "$(echo "$line" | sed -nE 's/([a-zA-Z0-9_]+)\s*=\s*"?([a-zA-Z0-9_:/\.\-]+)"?/\1 \2/p')"
261263
# Dynamically create the variable with its value
262264
declare -g "$var_name=$var_value"
263-
debug_log "OK:form ok, start with splunk setting $var_name=$var_value, $var_name=${!var_name}"
265+
debug_log "OK:form ok, start with splunk setting $var_name=$var_value, var_name=${var_name}."
264266
else
265267
debug_log "KO:invalid form line=$line"
266268
fi
267269
done < $FI
270+
debug_log "end of loading settings for file $FI"
268271
else
269272
debug_log "file $FI is not present"
270273
fi

splunkconf-backup/default/app.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[install]
66
is_configured = 0
7-
build = 1.9.2
7+
build = 1.9.3
88

99
[ui]
1010
is_visible = 1
@@ -13,11 +13,11 @@ label = SplunkConf Backup
1313
[launcher]
1414
author = Splunkworks , Splunk
1515
description = This app does regular automated Splunk backups for configuration files, kvstore, state locally and to a optional remote location (nas or cloud storage)
16-
version = 1.9.2
16+
version = 1.9.3
1717

1818
[id]
1919
name = splunkconf-backup
20-
version = 1.9.2
20+
version = 1.9.3
2121

2222
[triggers]
2323
# # Do not force a restart of Splunk Enterprise for state changes of MyApp

src/apps/splunkconf-backup.tar.gz

356 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)