94 lines
1.6 KiB
Bash
Executable File
94 lines
1.6 KiB
Bash
Executable File
#!/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
|