Skip to content

Commit 3a9648e

Browse files
committed
add timeout for curl command to speed up backup for on prem with firewalls
1 parent 66cf0e0 commit 3a9648e

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

splunkconf-backup/bin/splunkconf-backup.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ exec > /tmp/splunkconf-backup-debug.log 2>&1
149149
# 20251007 move init delay after variable initialization just before backups
150150
# 20251007 fix regression on BACKUPSTATE and BACKUPKV flag support to disable specific backups
151151
# 20251215 remove version check for kvdump, assuming always version at minimum 7.1
152+
# 20251215 add timeout for curl command to speed up backup for on prem with firewalls
152153

153-
VERSION="20251215a"
154+
VERSION="20251215b"
154155

155156
###### BEGIN default parameters
156157
# dont change here, use the configuration file to override them
@@ -189,6 +190,10 @@ umask 027
189190
# group can access backup (should be splunk group)
190191
# other should not access backups
191192

193+
# set timeout to avoid very long timeout when calling curl to autodetect AWS (for on prem with firewalls droping it)
194+
CURLCONNECTTIMEOUT=10
195+
CURLMAXTIME=60
196+
192197
# we always do relative backup but if ever you want the old way, change mode below to abs
193198
# recovery part support both mode
194199
# du to recent tar behavior related to exclusion it is better to use rel mode
@@ -453,11 +458,11 @@ function check_cloud() {
453458
# but this is almost certainly overkill for this purpose (and the above
454459
# checks of "EC2" prefixes have a higher false positive potential, anyway).
455460
# imdsv2 support : TOKEN should exist if inside AWS even if not enforced
456-
TOKEN=`curl --silent --show-error -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 900"`
461+
TOKEN=`curl --silent --show-error --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 900"`
457462
if [ -z ${TOKEN+x} ]; then
458463
# TOKEN NOT SET , NOT inside AWS
459464
cloud_type=0
460-
elif $(curl --silent -m 5 -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/dynamic/instance-identity/document | grep -q availabilityZone) ; then
465+
elif $(curl --silent -m 5 --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/dynamic/instance-identity/document | grep -q availabilityZone) ; then
461466
debug_log 'AWS instance detected'
462467
cloud_type=1
463468
fi
@@ -989,10 +994,10 @@ if [ $CHECK -ne 0 ]; then
989994
if [[ "cloud_type" -eq 1 ]]; then
990995
# aws
991996
# setting up token (IMDSv2)
992-
TOKEN=`curl --silent --show-error -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 900"`
997+
TOKEN=`curl --silent --show-error --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 900"`
993998
# lets get the s3splunkinstall from instance tags
994-
INSTANCE_ID=`curl --silent --show-error -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id `
995-
REGION=`curl --silent --show-error -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/.$//' `
999+
INSTANCE_ID=`curl --silent --show-error --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id `
1000+
REGION=`curl --silent --show-error --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/.$//' `
9961001

9971002
# we put store tags in instance-tags file-> we will use this later on
9981003
aws ec2 describe-tags --region $REGION --filter "Name=resource-id,Values=$INSTANCE_ID" --output=text | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/[[:space:]]*=[[:space:]]*/=/' | sed -r 's/TAGS\t(.*)\t.*\t.*\t(.*)/\1="\2"/' | grep -E "^splunk" > $INSTANCEFILE

splunkconf-backup/bin/splunkconf-checkbackup.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ exec > /tmp/splunkconf-checkbackup-debug.log 2>&1
1313
# 20230202 fix typos and false positive in check
1414
# 20230913 add debug code for local conf inclusion
1515
# 20240629 replace direct var inclusion with loading function logic
16+
# 20251215 add timeout for curl command to speed up backup for on prem with firewalls
1617

17-
VERSION="20240629a"
18+
VERSION="20251215a"
1819

1920
###### BEGIN default parameters
2021
# dont change here, use the configuration file to override them
@@ -45,6 +46,9 @@ unset NODE_PATH
4546
unset PYTHONPATH
4647
#env
4748

49+
# set timeout to avoid very long timeout when calling curl to autodetect AWS (for on prem with firewalls droping it)
50+
CURLCONNECTTIMEOUT=10
51+
CURLMAXTIME=60
4852

4953
#### purge parameters
5054

splunkconf-backup/bin/splunkconf-purgebackup.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ exec > /tmp/splunkconf-purgebackup-debug.log 2>&1
6161
# 20250917 update load setting with regex version (same as for backup)
6262
# 20251007 resync load settings with updated regex
6363
# 20251215 add mode=purge to have more consistent logging
64+
# 20251215 add timeout for curl command to speed up backup for on prem with firewalls
6465

65-
VERSION="20251215a"
66+
67+
VERSION="20251215b"
6668

6769
###### BEGIN default parameters
6870
# dont change here, use the configuration file to override them
@@ -82,6 +84,11 @@ cd ..
8284
#SPLUNK_HOME="/opt/splunk"
8385
SPLUNK_HOME=`cd ../../..;pwd`
8486

87+
88+
# set timeout to avoid very long timeout when calling curl to autodetect AWS (for on prem with firewalls droping it)
89+
CURLCONNECTTIMEOUT=10
90+
CURLMAXTIME=60
91+
8592
#### purge parameters
8693

8794
##### LOCAL
@@ -236,11 +243,11 @@ function check_cloud() {
236243
# but this is almost certainly overkill for this purpose (and the above
237244
# checks of "EC2" prefixes have a higher false positive potential, anyway).
238245
# imdsv2 support : TOKEN should exist if inside AWS even if not enforced
239-
TOKEN=`curl --silent --show-error -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 900"`
246+
TOKEN=`curl --silent --show-error --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 900"`
240247
if [ -z ${TOKEN+x} ]; then
241248
# TOKEN NOT SET , NOT inside AWS
242249
cloud_type=0
243-
elif $(curl --silent -m 5 -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/dynamic/instance-identity/document | grep -q availabilityZone) ; then
250+
elif $(curl --silent -m 5 --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/dynamic/instance-identity/document | grep -q availabilityZone) ; then
244251
debug_log 'AWS instance detected'
245252
cloud_type=1
246253
fi

splunkconf-backup/bin/splunkconf-restorebackup.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ exec > /tmp/splunkconf-restore-debug.log 2>&1
8080
# 20251202 align load settings with backup version
8181
# 20251215 remove version check for kvdump, assuming always version at minimum 7.1
8282
# 20251215 add backup dir creation to avoid error and delay du to check disk space not working correctly
83+
# 20251215 add timeout for curl command to speed up backup for on prem with firewalls
8384

84-
VERSION="20251215a"
85+
VERSION="20251215b"
8586

8687
###### BEGIN default parameters
8788
# dont change here, use the configuration file to override them
@@ -114,6 +115,10 @@ unset PYTHONPATH
114115
#env
115116

116117

118+
# set timeout to avoid very long timeout when calling curl to autodetect AWS (for on prem with firewalls droping it)
119+
CURLCONNECTTIMEOUT=10
120+
CURLMAXTIME=60
121+
117122
# FIXME , get it automatically from splunk-launch.conf
118123
SPLUNK_DB="${SPLUNK_HOME}/var/lib/splunk"
119124

0 commit comments

Comments
 (0)