Skip to content

Commit 304cb56

Browse files
authored
Merge pull request #4929 from jeromecst/master
Add notification support for ntfy.sh
2 parents bd48c99 + a3612f5 commit 304cb56

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

notify/ntfy.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env sh
2+
3+
# support ntfy
4+
5+
#NTFY_URL="https://ntfy.sh"
6+
#NTFY_TOPIC="xxxxxxxxxxxxx"
7+
8+
ntfy_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+
16+
NTFY_URL="${NTFY_URL:-$(_readaccountconf_mutable NTFY_URL)}"
17+
if [ "$NTFY_URL" ]; then
18+
_saveaccountconf_mutable NTFY_URL "$NTFY_URL"
19+
fi
20+
21+
NTFY_TOPIC="${NTFY_TOPIC:-$(_readaccountconf_mutable NTFY_TOPIC)}"
22+
if [ "$NTFY_TOPIC" ]; then
23+
_saveaccountconf_mutable NTFY_TOPIC "$NTFY_TOPIC"
24+
fi
25+
26+
_data="${_subject}. $_content"
27+
response="$(_post "$_data" "$NTFY_URL/$NTFY_TOPIC" "" "POST" "")"
28+
29+
if [ "$?" = "0" ] && _contains "$response" "expires"; then
30+
_info "ntfy event fired success."
31+
return 0
32+
fi
33+
34+
_err "ntfy event fired error."
35+
_err "$response"
36+
return 1
37+
}

0 commit comments

Comments
 (0)