Add file notification channel

This commit is contained in:
Matthew Oleksowicz 2025-08-14 00:28:42 -04:00
parent 37f33d7a06
commit 6af9ff3eb8
5 changed files with 41 additions and 6 deletions

2
.gitignore vendored
View file

@ -7,3 +7,5 @@
regctl
# ignore snooze file
snooze.list
# ignore updates file
updates_available.txt

View file

@ -32,7 +32,7 @@
## All commented values are examples only. Modify as needed.
##
## Uncomment the line below and specify the notification channels you wish to enable in a space separated string
# NOTIFY_CHANNELS="apprise discord DSM generic HA gotify matrix ntfy pushbullet pushover slack smtp telegram"
# NOTIFY_CHANNELS="apprise discord DSM file generic HA gotify matrix ntfy pushbullet pushover slack smtp telegram"
#
## Uncomment the line below and specify the number of seconds to delay notifications to enable snooze
# SNOOZE_SECONDS=86400

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
VERSION="v0.7.0"
# ChangeNotes: Snooze bugfix, added auth support to ntfy.sh and sendmail support to SMTP
VERSION="v0.7.1"
# ChangeNotes: Call send_notification even when no updates are available to write to file (if enabled) and clean up snooze
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
@ -507,6 +507,8 @@ if [[ -n ${GotUpdates[*]:-} ]]; then
if [[ -s "$ScriptWorkDir/urls.list" ]] && [[ "$PrintReleaseURL" == true ]]; then releasenotes; else Updates=("${GotUpdates[@]}"); fi
[[ "$AutoMode" == false ]] && list_options || printf "%s\n" "${Updates[@]}"
[[ "$Notify" == true ]] && { exec_if_exists_or_fail send_notification "${GotUpdates[@]}" || printf "\nCould not source notification function.\n"; }
else
[[ "$Notify" == true ]] && [[ ! -s "${ScriptWorkDir}/notify.sh" ]] && { exec_if_exists_or_fail send_notification "${GotUpdates[@]}" || printf "\nCould not source notification function.\n"; }
fi
# Optionally get updates if there's any

View file

@ -0,0 +1,12 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
NOTIFY_FILE_VERSION="v0.1"
#
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
# If you instead wish make your own modifications, make a copy in the same directory as the main dockcheck.sh script.
trigger_file_notification() {
NotifyFile="${ScriptWorkDir}/updates_available.txt"
echo "${MessageBody}" > ${NotifyFile}
}

View file

@ -114,6 +114,23 @@ send_notification() {
UpdNotifyCount="${#Updates[@]}"
fi
if [[ "${enabled_notify_channels[@]}" == *"file"* ]]; then
UpdToString=$( printf '%s, ' "${Updates[@]}" )
UpdToString="${UpdToString%, }"
if [[ -z "${UpdToString}" ]]; then
UpdToString="None"
fi
printf "\nSending file notification\n"
printf -v MessageBody "${UpdToString}"
exec_if_exists_or_fail trigger_file_notification || \
printf "Attempted to send notification to channel file, but the function was not found. Make sure notify_file.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory.\n"
remove_channel file
fi
NotifyError=false
if [[ "${UpdNotifyCount}" -gt 0 ]]; then
@ -238,9 +255,11 @@ notify_update_notification() {
printf -v MessageBody "Notify templates on $FromHost with updates available:\n${UpdToString}\n"
for channel in "${enabled_notify_channels[@]}"; do
printf "Sending notify template update notification - ${channel}\n"
exec_if_exists_or_fail trigger_${channel}_notification || \
printf "Attempted to send notification to channel ${channel}, but the function was not found. Make sure notify_${channel}.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory.\n"
if [[ ! "${channel}" == "file" ]]; then
printf "Sending notify template update notification - ${channel}\n"
exec_if_exists_or_fail trigger_${channel}_notification || \
printf "Attempted to send notification to channel ${channel}, but the function was not found. Make sure notify_${channel}.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory.\n"
fi
done
[[ -n "${snooze}" ]] && [[ "${NotifyError}" == "false" ]] && update_snooze "${NotifyUpdates[@]}"