From 7501d00d76df45911be409bd02aedff305c3bd2f Mon Sep 17 00:00:00 2001 From: dwrz Date: Thu, 2 Feb 2023 15:39:47 +0000 Subject: [PATCH] Refactor alert script --- scripts/alert | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/alert b/scripts/alert index f5db72b..5091e71 100755 --- a/scripts/alert +++ b/scripts/alert @@ -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}"