Refactor alert script

This commit is contained in:
dwrz
2023-02-02 15:40:25 +00:00
parent 0fa91246da
commit 7501d00d76
+19
View File
@@ -1,8 +1,27 @@
#!/usr/bin/env bash
# Devices to check -- if populated and up, no notifications are sent.
readonly DEVICES=()
readonly RECIPIENT="${NOTIFICATION_RECIPIENT}"
check_devices() {
for device in "${DEVICES[@]}"; do
if ping -c 1 -w 1 "${device}" &> "/dev/null"; then
return 0
fi
done
return 255
}
main() {
# If devices are present, don't notify.
if (( "${#DEVICES[@]}" )); then
if check_devices; then
exit 0
fi
fi
echo "${HOSTNAME}: motion detected at $(date '+%Y-%m-%dT%H:%M:%S%:z')." | \
mutt -s "${HOSTNAME}: Motion Detected" \
-- "${RECIPIENT}"