Refactor alert script
This commit is contained in:
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user