Custom notify hooks for acme.sh. See https://github.com/acmesh-official/acme.sh/wiki/notify.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
acme.sh-notify-hooks/gotify.sh

64 lines
1.6 KiB

#!/bin/bash
# Support Gotify webhooks
#GOTIFY_WEBHOOK_URL=""
#GOTIFY_TOKEN=""
gotify_send() {
_subject="$1"
_content="$2"
_statusCode="$3" # 0: success, 1: error 2($RENEW_SKIP): skipped
_debug "_statusCode" "$_statusCode"
GOTIFY_WEBHOOK_URL="${GOTIFY_WEBHOOK_URL:-$(_readaccountconf_mutable GOTIFY_WEBHOOK_URL)}"
if [ -z "$GOTIFY_WEBHOOK_URL" ]; then
GOTIFY_WEBHOOK_URL=""
_err "You didn't specify a Gotify webhook url GOTIFY_WEBHOOK_URL yet."
return 1
fi
_saveaccountconf_mutable GOTIFY_WEBHOOK_URL "$GOTIFY_WEBHOOK_URL"
GOTIFY_TOKEN="${GOTIFY_TOKEN:-$(_readaccountconf_mutable GOTIFY_TOKEN)}"
if [ -z "$GOTIFY_TOKEN" ]; then
GOTIFY_TOKEN=""
_err "You didn't specify a Gotify app token GOTIFY_TOKEN yet."
return 1
fi
_saveaccountconf_mutable GOTIFY_TOKEN "$GOTIFY_TOKEN"
export _H1="Content-Type: application/json"
_subject="$(printf "$_subject" | _json_encode)"
_content="$(printf "$_content" | _json_encode)"
case "$_statusCode" in
0)
_priority=4 # success - normal priority
;;
1)
_priority=8 # error - high priority
;;
2)
_priority=1 # skipped - low priority
;;
esac
_data="{\"title\": \"$_subject\", "
if [ -n "$_priority" ]; then
_data="$_data\"priority\": $_priority, "
fi
_data="$_data\"message\": \"$_content\"}"
_postURL="${GOTIFY_WEBHOOK_URL}/message?token=${GOTIFY_TOKEN}"
if _post "$_data" "$_postURL"; then
if ! _contains "$response" error; then
_info "gotify send success."
return 0
fi
fi
_err "gotify send error."
_err "$response"
return 1
}