Skip to content

Commit ed71949

Browse files
committed
more curl timeout support including for kvtore connectivity
1 parent 3a9648e commit ed71949

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

splunkconf-backup/bin/splunkconf-backup.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ function splunkconf_checkspace {
427427
METADATA_URL="http://metadata.google.internal/computeMetadata/v1"
428428
function check_cloud() {
429429
cloud_type=0
430-
response=$(curl -fs -m 5 -H "Metadata-Flavor: Google" ${METADATA_URL})
430+
response=$(curl -fs -m 5 --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H "Metadata-Flavor: Google" ${METADATA_URL})
431431
if [ $? -eq 0 ]; then
432432
debug_log 'GCP instance detected'
433433
cloud_type=2
@@ -1582,10 +1582,10 @@ if [ "$MODE" == "0" ] || [ "$MODE" == "kvdump" ] || [ "$MODE" == "kvstore" ] ||
15821582
MGMTURL=`${SPLUNK_HOME}/bin/splunk btool web list settings --debug | grep mgmtHostPort | grep -v \# | sed -r 's/.*=\s*([0-9\.:]+)/\1/' |tail -1`
15831583

15841584
# check pre backup
1585-
RES=`curl --silent -k https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" `
1585+
RES=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" `
15861586
debug_log "PREKVDUMP backup full kvstore status RES=$RES"
1587-
RES=`curl --silent -k https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep backupRestoreStatus | grep -i Ready`
1588-
RESREADY=`curl --silent -k https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep 'name="status"' | grep -i ready`
1587+
RES=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep backupRestoreStatus | grep -i Ready`
1588+
RESREADY=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep 'name="status"' | grep -i ready`
15891589
debug_log "PREKVDUMP kvstore status before launching backup RES=$RESi RESREADY=$RESREADY"
15901590
#debug_log "COUNTER=$COUNTER $MESSVER $MESS1 type=$TYPE object=${kvbackupmode} action=backup result=running "
15911591

@@ -1604,8 +1604,8 @@ if [ "$MODE" == "0" ] || [ "$MODE" == "kvdump" ] || [ "$MODE" == "kvstore" ] ||
16041604
# increase here if needed (ie take more time !)
16051605
# until either we do max try or combined result from kvstorebackup ready and status ready are ok
16061606
until [[ $COUNTER -lt 1 || -n "$RES2" ]]; do
1607-
RES=`curl --silent -k https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep backupRestoreStatus | grep -i Ready`
1608-
RESREADY=`curl --silent -k https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep 'name="status"' | grep -i ready`
1607+
RES=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep backupRestoreStatus | grep -i Ready`
1608+
RESREADY=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep 'name="status"' | grep -i ready`
16091609
if [[ -n "$RES" && -n "$RESREADY" ]]; then
16101610
RES2=$RES
16111611
else
@@ -1631,7 +1631,7 @@ if [ "$MODE" == "0" ] || [ "$MODE" == "kvdump" ] || [ "$MODE" == "kvstore" ] ||
16311631
# auto ie 0 or without value 1
16321632
debug_log "launching kvdump backup via REST API with archiveName=${KVARCHIVE} and pointInTime disabled"
16331633
fi
1634-
RES=`curl --silent -k https://${MGMTURL}/services/kvstore/backup/create -X post --header "Authorization: Splunk ${sessionkey}" -d"archiveName=${KVARCHIVE}" $OPTIONPOINTINTIME `
1634+
RES=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/backup/create -X post --header "Authorization: Splunk ${sessionkey}" -d"archiveName=${KVARCHIVE}" $OPTIONPOINTINTIME `
16351635

16361636
#echo_log "KVDUMP CREATE RES=$RES"
16371637
COUNTER=${KVSTOREREADYBACKUP}
@@ -1640,7 +1640,7 @@ if [ "$MODE" == "0" ] || [ "$MODE" == "kvdump" ] || [ "$MODE" == "kvstore" ] ||
16401640
# wait a bit (up to 20*10= 200s) for backup to complete, especially for big kvstore/busy env (io)
16411641
# increase here if needed (ie take more time !)
16421642
until [[ $COUNTER -lt 1 || -n "$RES" ]]; do
1643-
RES=`curl --silent -k https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep backupRestoreStatus | grep -i Ready`
1643+
RES=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep backupRestoreStatus | grep -i Ready`
16441644
#echo_log "RES=$RES"
16451645
debug_log "COUNTER=$COUNTER (max=${COUNTERMAX}) $MESSVER $MESS1 type=$TYPE object=${kvbackupmode} action=backup result=running info=postbackup"
16461646
let COUNTER-=1

splunkconf-backup/bin/splunkconf-purgebackup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function checklock() {
212212
METADATA_URL="http://metadata.google.internal/computeMetadata/v1"
213213
function check_cloud() {
214214
cloud_type=0
215-
response=$(curl -fs -m 5 -H "Metadata-Flavor: Google" ${METADATA_URL})
215+
response=$(curl -fs -m 5 --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H "Metadata-Flavor: Google" ${METADATA_URL})
216216
if [ $? -eq 0 ]; then
217217
debug_log 'GCP instance detected'
218218
cloud_type=2

splunkconf-backup/bin/splunkconf-restorebackup.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ elif ([[ "$MODE" == "0" ]] || [[ "$MODE" == "kvdump" ]] || [[ "$MODE" == "kvauto
525525
COUNTER=49
526526
RES=""
527527

528-
RESREADY=`curl --silent -k https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep 'name="status"' | grep -i ready`
528+
RESREADY=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep 'name="status"' | grep -i ready`
529529
debug_log "PREKVDUMP kvstore status before launching backup RES=$RESi RESREADY=$RESREADY"
530530
#debug_log "COUNTER=$COUNTER $MESSVER $MESS1 type=$TYPE object=${kvbackupmode} action=backup result=running "
531531

@@ -538,8 +538,8 @@ elif ([[ "$MODE" == "0" ]] || [[ "$MODE" == "kvdump" ]] || [[ "$MODE" == "kvauto
538538
# increase here if needed (ie take more time !)
539539
# until either we do max try or combined result from kvstorebackup ready and status ready are ok
540540
until [[ $COUNTER -lt 1 || -n "$RES2" ]]; do
541-
RES=`curl --silent -k https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep backupRestoreStatus | grep -i Ready`
542-
RESREADY=`curl --silent -k https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep 'name="status"' | grep -i ready`
541+
RES=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep backupRestoreStatus | grep -i Ready`
542+
RESREADY=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep 'name="status"' | grep -i ready`
543543
if [[ -n "$RES" && -n "$RESREADY" ]]; then
544544
RES2=$RES
545545
else
@@ -559,7 +559,7 @@ elif ([[ "$MODE" == "0" ]] || [[ "$MODE" == "kvdump" ]] || [[ "$MODE" == "kvauto
559559

560560
# we are restoring as the backup file has been pushed there by the recovery script
561561
MESS1="MGMTURL=${MGMTURL} KVARCHIVE=${KVARCHIVE}";
562-
RES=`curl --silent -k https://${MGMTURL}/services/kvstore/backup/restore -X post --header "Authorization: Splunk ${sessionkey}" -d"archiveName=${KVARCHIVE}"`
562+
RES=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/backup/restore -X post --header "Authorization: Splunk ${sessionkey}" -d"archiveName=${KVARCHIVE}"`
563563
echo_log "launching kvdump restore KVDUMP RESTORE RES=$RES"
564564
# if splunk cant find the file, it will outout sonething like that, which will be in the error message (but should not happen because -e check above)
565565
# <?xml version="1.0" encoding="UTF-8"?>
@@ -594,7 +594,7 @@ elif ([[ "$MODE" == "0" ]] || [[ "$MODE" == "kvdump" ]] || [[ "$MODE" == "kvauto
594594
# wait a bit (up to 20*10= 200s) for restore to complete, especially for big kvstore/busy env (io)
595595
# increase here if needed (ie take more time !)
596596
until [[ $COUNTER -lt 1 || -n "$RES" ]]; do
597-
RES=`curl --silent -k https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep backupRestoreStatus | grep -i Ready`
597+
RES=`curl --silent -k --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME https://${MGMTURL}/services/kvstore/status --header "Authorization: Splunk ${sessionkey}" | grep backupRestoreStatus | grep -i Ready`
598598
#echo_log "RES=$RES"
599599
echo_log "COUNTER=$COUNTER $MESSVER $MESS1 kvbackupmode=$kvbackupmode "
600600
let COUNTER-=1

0 commit comments

Comments
 (0)