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.

40 lines
936 B

6 years ago
  1. #!/usr/bin/env sh
  2. #Support Slack webhooks
  3. #SLACK_WEBHOOK_URL=""
  4. slack_send() {
  5. _subject="$1"
  6. _content="$2"
  7. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  8. _debug "_statusCode" "$_statusCode"
  9. SLACK_WEBHOOK_URL="${SLACK_WEBHOOK_URL:-$(_readaccountconf_mutable SLACK_WEBHOOK_URL)}"
  10. if [ -z "$SLACK_WEBHOOK_URL" ]; then
  11. SLACK_WEBHOOK_URL=""
  12. _err "You didn't specify a Slack webhook url SLACK_WEBHOOK_URL yet."
  13. return 1
  14. fi
  15. _saveaccountconf_mutable SLACK_WEBHOOK_URL "$SLACK_WEBHOOK_URL"
  16. export _H1="Content-Type: application/json"
  17. _content="$(echo "$_subject: $_content" | _json_encode)"
  18. _data="{\"text\": \"$_content\"}"
  19. echo "$_content"
  20. echo "$_data"
  21. if _post "$_data" "$SLACK_WEBHOOK_URL"; then
  22. # shellcheck disable=SC2154
  23. if [ -z "$response" ]; then
  24. _info "slack send sccess."
  25. return 0
  26. fi
  27. fi
  28. _err "slack send error."
  29. _err "$response"
  30. return 1
  31. }