1
0
Fork 0
mirror of https://github.com/yavook/kiwi-backup.git synced 2024-12-04 03:53:01 +00:00

WEBHOOK_FAIL_URL

This commit is contained in:
Jörn-Michael Miehe 2022-10-20 17:12:29 +02:00
parent 04c3d543e8
commit 3501b598b4
3 changed files with 29 additions and 12 deletions

View file

@ -9,6 +9,7 @@ RUN set -ex; \
# duplicity software dependencies # duplicity software dependencies
apk --no-cache add \ apk --no-cache add \
ca-certificates \ ca-certificates \
curl \
gettext \ gettext \
gnupg \ gnupg \
lftp \ lftp \
@ -102,6 +103,7 @@ ENV \
OPTIONS_RMFULL="" \ OPTIONS_RMFULL="" \
OPTIONS_RMINCR="" \ OPTIONS_RMINCR="" \
WEBHOOK_URL="" \ WEBHOOK_URL="" \
WEBHOOK_FAIL_URL="" \
WEBHOOK_INSECURE="" \ WEBHOOK_INSECURE="" \
\ \
############## ##############

View file

@ -166,6 +166,9 @@ backup:
# Webhook to be pinged on action (use "%%MSG%%" as a placeholder for a message) # Webhook to be pinged on action (use "%%MSG%%" as a placeholder for a message)
WEBHOOK_URL: "" WEBHOOK_URL: ""
# Webhook to be pinged on failed action (use "%%MSG%%" as a placeholder for a message)
WEBHOOK_FAIL_URL: ""
# Allow self-signed certificates on webhook target # Allow self-signed certificates on webhook target
WEBHOOK_INSECURE: "0" WEBHOOK_INSECURE: "0"
``` ```

View file

@ -19,20 +19,32 @@ if [ -n "${GPG_PASSPHRASE}" ]; then
unset GPG_PASSPHRASE unset GPG_PASSPHRASE
fi fi
# run webhook # run start webhook
if [ -n "${WEBHOOK_URL}" ]; then curl_args=""
wget_args="" if [ "${WEBHOOK_INSECURE}" = "1" ]; then
if [ "${WEBHOOK_INSECURE}" = "1" ]; then curl_args="--insecure"
wget_args="--no-check-certificate" fi
fi
WEBHOOK_URL="$(echo "${WEBHOOK_URL}" | sed "s,%%MSG%%,running%20task%20${*},g" )" if [ -n "${WEBHOOK_URL}" ]; then
wget -O /dev/null ${wget_args} "${WEBHOOK_URL}" 1>/dev/null 2>/dev/null webhook_url="$(echo "${WEBHOOK_URL}" | sed "s,%%MSG%%,running%20task%20${*},g" )"
curl ${curl_args} "${webhook_url}" 1>/dev/null 2>/dev/null
fi fi
# hand over # hand over
set -ex set -ex
exec $( \ eval "$( \
"${this_dir}/build_command" \ "${this_dir}/build_command" \
"${@}" \ "${@}" \
) )"
exit_code="${?}"
# run finish webhook
if [ "${exit_code}" -eq "0" ] && [ -n "${WEBHOOK_URL}" ]; then
webhook_url="$(echo "${WEBHOOK_URL}" | sed "s,%%MSG%%,task%20${*}%20finished%20successfully,g" )"
curl ${curl_args} "${webhook_url}" 1>/dev/null 2>/dev/null
elif [ "${exit_code}" -ne "0" ] && [ -n "${WEBHOOK_URL}" ]; then
webhook_fail_url="$(echo "${WEBHOOK_FAIL_URL:-${WEBHOOK_URL}}" | sed "s,%%MSG%%,task%20${*}%20finished%20with%20status%20${exit_code},g" )"
curl ${curl_args} "${webhook_fail_url}" 1>/dev/null 2>/dev/null
fi