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.

37 lines
1.1 KiB

  1. #!/bin/bash
  2. #Support Rocketchat webhooks
  3. #ROCKETCHAT_WEBHOOK_URL="https://xxxxx/hooks/xxxx"
  4. rocketchat_send() {
  5. _subject="$1"
  6. _content="$2"
  7. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  8. _debug "_statusCode" "$_statusCode"
  9. _hostname=`hostname -f`
  10. ROCKETCHAT_WEBHOOK_URL="${ROCKETCHAT_WEBHOOK_URL:-$(_readaccountconf_mutable ROCKETCHAT_WEBHOOK_URL)}"
  11. if [ -z "$ROCKETCHAT_WEBHOOK_URL" ]; then
  12. ROCKETCHAT_WEBHOOK_URL=""
  13. _err "You didn't specify a webhook URL yet."
  14. _err "Please check documentation here : https://docs.rocket.chat/administrator-guides/integrations"
  15. return 1
  16. fi
  17. _saveaccountconf_mutable ROCKETCHAT_WEBHOOK_URL "$ROCKETCHAT_WEBHOOK_URL"
  18. export _H1="Content-Type: application/json"
  19. _content="$(printf "*%s*\n%s" "$_subject on $_hostname" "$_content" | _json_encode)"
  20. _data="{\"text\": \"$_content\" }"
  21. response="$(_post "$_data" "$ROCKETCHAT_WEBHOOK_URL")"
  22. if [ "$?" = "0" ] && _contains "$response" "true"; then
  23. _info "rocketchat send success."
  24. return 0
  25. fi
  26. _err "rocketchat send error."
  27. _err "$response"
  28. return 1
  29. }