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.

62 lines
1.6 KiB

  1. #!/usr/bin/env sh
  2. #Support Gotify
  3. #GOTIFY_URL="https://gotify.example.com"
  4. #GOTIFY_TOKEN="123456789ABCDEF"
  5. #optional
  6. #GOTIFY_PRIORITY=0
  7. # subject content statusCode
  8. gotify_send() {
  9. _subject="$1"
  10. _content="$2"
  11. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  12. _debug "_subject" "$_subject"
  13. _debug "_content" "$_content"
  14. _debug "_statusCode" "$_statusCode"
  15. GOTIFY_URL="${GOTIFY_URL:-$(_readaccountconf_mutable GOTIFY_URL)}"
  16. if [ -z "$GOTIFY_URL" ]; then
  17. GOTIFY_URL=""
  18. _err "You didn't specify the gotify server url GOTIFY_URL."
  19. return 1
  20. fi
  21. _saveaccountconf_mutable GOTIFY_URL "$GOTIFY_URL"
  22. GOTIFY_TOKEN="${GOTIFY_TOKEN:-$(_readaccountconf_mutable GOTIFY_TOKEN)}"
  23. if [ -z "$GOTIFY_TOKEN" ]; then
  24. GOTIFY_TOKEN=""
  25. _err "You didn't specify the gotify token GOTIFY_TOKEN."
  26. return 1
  27. fi
  28. _saveaccountconf_mutable GOTIFY_TOKEN "$GOTIFY_TOKEN"
  29. GOTIFY_PRIORITY="${GOTIFY_PRIORITY:-$(_readaccountconf_mutable GOTIFY_PRIORITY)}"
  30. if [ -z "$GOTIFY_PRIORITY" ]; then
  31. GOTIFY_PRIORITY=0
  32. else
  33. _saveaccountconf_mutable GOTIFY_PRIORITY "$GOTIFY_PRIORITY"
  34. fi
  35. export _H1="X-Gotify-Key: ${GOTIFY_TOKEN}"
  36. export _H2="Content-Type: application/json"
  37. _content=$(echo "$_content" | _json_encode)
  38. _subject=$(echo "$_subject" | _json_encode)
  39. _data="{\"title\": \"${_subject}\", \"message\": \"${_content}\", \"priority\": ${GOTIFY_PRIORITY}}"
  40. response="$(_post "${_data}" "${GOTIFY_URL}/message" "" "POST" "application/json")"
  41. if [ "$?" != "0" ]; then
  42. _err "Failed to send message"
  43. _err "$response"
  44. return 1
  45. fi
  46. _debug2 response "$response"
  47. return 0
  48. }