Compare commits
3 Commits
9798d402ba
...
658c370f5c
Author | SHA1 | Date |
---|---|---|
|
658c370f5c | |
|
c13ac75995 | |
|
77b701ffc0 |
|
@ -8,4 +8,6 @@ RUN --mount=type=cache,target=/var/cache \
|
|||
|
||||
COPY start.sh /
|
||||
|
||||
COPY nut-notify.sh /usr/local/libexec/nut-notify
|
||||
|
||||
CMD ["/start.sh"]
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
#!/bin/sh
|
||||
# vim: set ts=4 sts=4 sw=4 et :
|
||||
|
||||
MESSAGE="$1"
|
||||
|
||||
|
||||
handle_online() {
|
||||
notify_ntfy high white_check_mark,electric_plug
|
||||
}
|
||||
|
||||
handle_onbatt() {
|
||||
notify_ntfy high warning,battery
|
||||
}
|
||||
|
||||
handle_lowbatt() {
|
||||
notify_ntfy max warning,battery
|
||||
}
|
||||
|
||||
handle_commok() {
|
||||
notify_ntfy high white_check_mark
|
||||
}
|
||||
|
||||
handle_commbad() {
|
||||
notify_ntfy high warning
|
||||
}
|
||||
|
||||
handle_replbatt() {
|
||||
notify_ntfy default warning,battery
|
||||
}
|
||||
|
||||
handle_nocomm() {
|
||||
notify_ntfy high warning
|
||||
}
|
||||
|
||||
handle_unknown() {
|
||||
printf 'Unknown notification type %s for UPS %s: %s' \
|
||||
"${NOTIFYTYPE}" \
|
||||
"${UPSNAME}" \
|
||||
"${MESSAGE}" \
|
||||
| log -p daemon.notice
|
||||
}
|
||||
|
||||
log() {
|
||||
logger --id=$$ -t "${0##*/}" "$@"
|
||||
}
|
||||
|
||||
notify_ntfy() {
|
||||
priority="${1:-default}"
|
||||
tags="${2}"
|
||||
|
||||
curl -fsSL https://ntfy.pyrocufflink.blue/alerts \
|
||||
-o /dev/null \
|
||||
-H 'Content-Type: text/plain' \
|
||||
-H "Priority: ${priority}" \
|
||||
-H "Tags: ${tags}" \
|
||||
-d "${MESSAGE}"
|
||||
}
|
||||
|
||||
|
||||
printf '%s running as %d %s\n' "${0##*/}" "$(id -u)" "$(whoami)" \
|
||||
| log -p daemon.info
|
||||
printf '%s %s %s\n' "${UPSNAME}" "${NOTIFYTYPE}" "${MESSAGE}" \
|
||||
| log -p daemon.info
|
||||
|
||||
PATH=/usr/bin:/bin:/usr/sbin:/sbin
|
||||
export PATH
|
||||
|
||||
case "${NOTIFYTYPE}" in
|
||||
ONLINE)
|
||||
handle_online
|
||||
;;
|
||||
ONBATT)
|
||||
handle_onbatt
|
||||
;;
|
||||
LOWBATT)
|
||||
handle_lowbatt
|
||||
;;
|
||||
COMMOK)
|
||||
handle_commok
|
||||
;;
|
||||
COMMBAD)
|
||||
handle_commbad
|
||||
;;
|
||||
REPLBATT)
|
||||
handle_replbatt
|
||||
;;
|
||||
NOCOMM)
|
||||
handle_nocomm
|
||||
;;
|
||||
*)
|
||||
handle_unknown
|
||||
;;
|
||||
esac
|
Loading…
Reference in New Issue