mirror of
https://github.com/plantroon/acme.sh.git
synced 2024-12-21 12:41:41 +00:00
add slack notify
This commit is contained in:
parent
7625d66259
commit
73bbe25d26
@ -3,6 +3,8 @@
|
||||
#Support Slack webhooks
|
||||
|
||||
#SLACK_WEBHOOK_URL=""
|
||||
#SLACK_CHANNEL=""
|
||||
#SLACK_USERNAME=""
|
||||
|
||||
slack_send() {
|
||||
_subject="$1"
|
||||
@ -18,23 +20,36 @@ slack_send() {
|
||||
fi
|
||||
_saveaccountconf_mutable SLACK_WEBHOOK_URL "$SLACK_WEBHOOK_URL"
|
||||
|
||||
SLACK_CHANNEL="${SLACK_CHANNEL:-$(_readaccountconf_mutable SLACK_CHANNEL)}"
|
||||
if [ -n "$SLACK_CHANNEL" ]; then
|
||||
_saveaccountconf_mutable SLACK_CHANNEL "$SLACK_CHANNEL"
|
||||
fi
|
||||
|
||||
SLACK_USERNAME="${SLACK_USERNAME:-$(_readaccountconf_mutable SLACK_USERNAME)}"
|
||||
if [ -n "$SLACK_USERNAME" ]; then
|
||||
_saveaccountconf_mutable SLACK_USERNAME "$SLACK_USERNAME"
|
||||
fi
|
||||
|
||||
export _H1="Content-Type: application/json"
|
||||
|
||||
_content="$(echo "$_subject: $_content" | _json_encode)"
|
||||
_data="{\"text\": \"$_content\"}"
|
||||
|
||||
echo "$_content"
|
||||
echo "$_data"
|
||||
_content="$(printf "*%s*\n%s" "$_subject" "$_content" | _json_encode)"
|
||||
_data="{\"text\": \"$_content\", "
|
||||
if [ -n "$SLACK_CHANNEL" ]; then
|
||||
_data="$_data\"channel\": \"$SLACK_CHANNEL\", "
|
||||
fi
|
||||
if [ -n "$SLACK_USERNAME" ]; then
|
||||
_data="$_data\"username\": \"$SLACK_USERNAME\", "
|
||||
fi
|
||||
_data="$_data\"mrkdwn\": \"true\"}"
|
||||
|
||||
if _post "$_data" "$SLACK_WEBHOOK_URL"; then
|
||||
# shellcheck disable=SC2154
|
||||
if [ -z "$response" ]; then
|
||||
_info "slack send sccess."
|
||||
if [ "$response" = "ok" ]; then
|
||||
_info "slack send success."
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
_err "slack send error."
|
||||
_err "$response"
|
||||
return 1
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user