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