@@ -205,6 +205,10 @@ zed_notify()
205
205
[ " ${rv} " -eq 0 ] && num_success=$(( num_success + 1 ))
206
206
[ " ${rv} " -eq 1 ] && num_failure=$(( num_failure + 1 ))
207
207
208
+ zed_notify_ntfy " ${subject} " " ${pathname} " ; rv=$?
209
+ [ " ${rv} " -eq 0 ] && num_success=$(( num_success + 1 ))
210
+ [ " ${rv} " -eq 1 ] && num_failure=$(( num_failure + 1 ))
211
+
208
212
[ " ${num_success} " -gt 0 ] && return 0
209
213
[ " ${num_failure} " -gt 0 ] && return 1
210
214
return 2
@@ -527,6 +531,100 @@ zed_notify_pushover()
527
531
}
528
532
529
533
534
+ # zed_notify_ntfy (subject, pathname)
535
+ #
536
+ # Send a notification via Ntfy.sh <https://ntfy.sh/>.
537
+ # The ntfy topic (ZED_NTFY_TOPIC) identifies the topic that the notification
538
+ # will be sent to Ntfy.sh server. The ntfy url (ZED_NTFY_URL) defines the
539
+ # self-hosted or provided hosted ntfy service location. The ntfy access token
540
+ # <https://docs.ntfy.sh/publish/#access-tokens> (ZED_NTFY_ACCESS_TOKEN) reprsents an
541
+ # access token that could be used if a topic is read/write protected. If a
542
+ # topic can be written to publicaly, a ZED_NTFY_ACCESS_TOKEN is not required.
543
+ #
544
+ # Requires curl and sed executables to be installed in the standard PATH.
545
+ #
546
+ # References
547
+ # https://docs.ntfy.sh
548
+ #
549
+ # Arguments
550
+ # subject: notification subject
551
+ # pathname: pathname containing the notification message (OPTIONAL)
552
+ #
553
+ # Globals
554
+ # ZED_NTFY_TOPIC
555
+ # ZED_NTFY_ACCESS_TOKEN (OPTIONAL)
556
+ # ZED_NTFY_URL
557
+ #
558
+ # Return
559
+ # 0: notification sent
560
+ # 1: notification failed
561
+ # 2: not configured
562
+ #
563
+ zed_notify_ntfy ()
564
+ {
565
+ local subject=" $1 "
566
+ local pathname=" ${2:- " /dev/null" } "
567
+ local msg_body
568
+ local msg_out
569
+ local msg_err
570
+
571
+ [ -n " ${ZED_NTFY_TOPIC} " ] || return 2
572
+ local url=" ${ZED_NTFY_URL:- " https://ntfy.sh" } /${ZED_NTFY_TOPIC} "
573
+
574
+ if [ ! -r " ${pathname} " ]; then
575
+ zed_log_err " ntfy cannot read \" ${pathname} \" "
576
+ return 1
577
+ fi
578
+
579
+ zed_check_cmd " curl" " sed" || return 1
580
+
581
+ # Read the message body in.
582
+ #
583
+ msg_body=" $( cat " ${pathname} " ) "
584
+
585
+ if [ -z " ${msg_body} " ]
586
+ then
587
+ msg_body=$subject
588
+ subject=" "
589
+ fi
590
+
591
+ # Send the POST request and check for errors.
592
+ #
593
+ if [ -n " ${ZED_NTFY_ACCESS_TOKEN} " ]; then
594
+ msg_out=" $( \
595
+ curl \
596
+ -u " :${ZED_NTFY_ACCESS_TOKEN} " \
597
+ -H " Title: ${subject} " \
598
+ -d " ${msg_body} " \
599
+ -H " Priority: high" \
600
+ " ${url} " \
601
+ 2> /dev/null \
602
+ ) " ; rv=$?
603
+ else
604
+ msg_out=" $( \
605
+ curl \
606
+ -H " Title: ${subject} " \
607
+ -d " ${msg_body} " \
608
+ -H " Priority: high" \
609
+ " ${url} " \
610
+ 2> /dev/null \
611
+ ) " ; rv=$?
612
+ fi
613
+ if [ " ${rv} " -ne 0 ]; then
614
+ zed_log_err " curl exit=${rv} "
615
+ return 1
616
+ fi
617
+ msg_err=" $( echo " ${msg_out} " \
618
+ | sed -n -e ' s/.*"errors" *:.*\[\(.*\)\].*/\1/p' ) "
619
+ if [ -n " ${msg_err} " ]; then
620
+ zed_log_err " ntfy \" ${msg_err} " \"
621
+ return 1
622
+ fi
623
+ return 0
624
+ }
625
+
626
+
627
+
530
628
# zed_rate_limit (tag, [interval])
531
629
#
532
630
# Check whether an event of a given type [tag] has already occurred within the
0 commit comments