Compare commits

...

3 Commits

Author SHA1 Message Date
Dustin 658c370f5c Install nut-notify script in container image
ContainerImages/nut/pipeline/head This commit looks good Details
2024-01-19 17:33:31 -06:00
Dustin c13ac75995 nut-notify: Remove everything except notifications
Shutdown automation will behandled by `upsmon` running on each physical
machine.  This code never worked anyway.
2024-01-19 17:32:37 -06:00
Dustin 77b701ffc0 nut-notify: Initial import
This is the `nut-notify` script as it existed on the original UPS server
(*serial0.pyrocufflink.blue*).
2024-01-19 17:29:51 -06:00
2 changed files with 95 additions and 0 deletions

View File

@ -8,4 +8,6 @@ RUN --mount=type=cache,target=/var/cache \
COPY start.sh / COPY start.sh /
COPY nut-notify.sh /usr/local/libexec/nut-notify
CMD ["/start.sh"] CMD ["/start.sh"]

93
nut-notify.sh Executable file
View File

@ -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