diff --git a/README.md b/README.md index ddef012..ab1d4da 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,12 @@ ___ ## :bell: Changelog +- **v0.5.0**: Rewritten notify logic - all templates are adjusted and should be migrated! + - Copy the custom settings from your current template to the new version of the same template. + - Look into, copy and customize the `urls.list` file if that's of interest. + - Other changes: + - Added Discord notify template. + - Verbosity changed of `regctl`. - **v0.4.9**: Added a function to enrich the notify-message with release note URLs. See [Release notes addon](https://github.com/mag37/dockcheck#date-release-notes-addon-to-notifications) - **v0.4.8**: Rewrote prune logic to not prompt with options `-a|-y` or `-n`. Auto prune with `-p`. - **v0.4.7**: Notification Template changes to gotify(new!), DSM(improved), SMTP(deprecation alternative). @@ -117,7 +123,7 @@ Further additions are welcome - suggestions or PR! ### :date: Release notes addon to Notifications There's a function to use a lookup-file to add release note URL's to the notification message. -Copy the notify_templates/`urls.list` file to the script directory and modify it as necessary, it will be used automatically if it's there. +Copy the notify_templates/`urls.list` file to the script directory, it will be used automatically if it's there. Modify it as necessary, the names of interest in the left column needs to match your container names. The output of the notification will look something like this: ``` Containers on hostname with updates available: diff --git a/dockcheck.sh b/dockcheck.sh index d3f5780..ffb7a21 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERSION="v0.4.9" -### ChangeNotes: Added a function to enrich the notify-message with release note URLs. See README. +VERSION="v0.5.0" +### ChangeNotes: Rewritten notify logic - all templates adjusted, transfer your current settings to a new template! See README. Github="https://github.com/mag37/dockcheck" RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh" @@ -126,7 +126,7 @@ choosecontainers() { } datecheck() { - ImageDate=$($regbin image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 ) + ImageDate=$($regbin -v error image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 ) ImageAge=$(( ( $(date +%s) - $(date -d "$ImageDate" +%s) )/86400 )) if [ "$ImageAge" -gt "$DaysOld" ] ; then return 0 @@ -149,12 +149,12 @@ progress_bar() { ### Function to add user-provided urls to releasenotes releasenotes() { - for update in ${Updates[@]}; do + for update in ${GotUpdates[@]}; do found=false while read -r container url; do - [[ $update == $container ]] && printf "%s -> %s\n" "$update" "$url" && found=true + [[ $update == $container ]] && Updates+=("$update -> $url") && found=true done < "$ScriptWorkDir"/urls.list - [[ $found == false ]] && printf "%s -> url missing\n" "$update" || continue + [[ $found == false ]] && Updates+=("$update -> url missing") || continue done } @@ -249,7 +249,7 @@ for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}') LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}') # Checking for errors while setting the variable: - if RegHash=$(${t_out} $regbin image digest --list "$RepoUrl" 2>&1) ; then + if RegHash=$(${t_out} $regbin -v error image digest --list "$RepoUrl" 2>&1) ; then if [[ "$LocalHash" = *"$RegHash"* ]] ; then NoUpdates+=("$i") else diff --git a/notify_templates/notify_DSM.sh b/notify_templates/notify_DSM.sh index 1c74c11..d9a0cd9 100644 --- a/notify_templates/notify_DSM.sh +++ b/notify_templates/notify_DSM.sh @@ -9,7 +9,7 @@ MSMTP=$(which msmtp) SSMTP=$(which ssmtp) -if [ -n "$MSMPT" ] ; then +if [ -n "$MSMTP" ] ; then MailPkg=$MSMTP elif [ -n "$SSMTP" ] ; then MailPkg=$SSMTP @@ -18,8 +18,8 @@ else fi send_notification() { -Updates=("$@") -[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" ) +[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") +UpdToString=$( printf '%s\\n' "${Updates[@]}" ) FromHost=$(hostname) CfgFile="/usr/syno/etc/synosmtp.conf" @@ -36,6 +36,8 @@ SenderMail=${SenderMail:-$(grep 'eventmail1' $CfgFile | sed -n 's/.*"\([^"]*\)". printf "\nSending email notification.\n" +printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n\n$UpdToString" + $MailPkg $SendMailTo << __EOF From: "$SenderName" <$SenderMail> date:$(date -R) @@ -44,10 +46,7 @@ Subject: $SubjectTag Updates available on $FromHost Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit -The following containers on $FromHost have updates available: - -$UpdToString - +$MessageBody From $SenderName __EOF } diff --git a/notify_templates/notify_apprise.sh b/notify_templates/notify_apprise.sh index b3c0219..8663d43 100644 --- a/notify_templates/notify_apprise.sh +++ b/notify_templates/notify_apprise.sh @@ -5,20 +5,15 @@ # Modify to fit your setup - if API, set AppriseURL to your Apprise ip/domain. send_notification() { -Updates=("$@") -[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" ) +[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") +UpdToString=$( printf '%s\\n' "${Updates[@]}" ) FromHost=$(hostname) printf "\nSending Apprise notification\n" MessageTitle="$FromHost - updates available." # Setting the MessageBody variable here. -read -d '\n' MessageBody << __EOF -Containers on $FromHost with updates available: - -$UpdToString - -__EOF +printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString" # Modify to fit your setup: apprise -vv -t "$MessageTitle" -b "$MessageBody" \ diff --git a/notify_templates/notify_discord.sh b/notify_templates/notify_discord.sh new file mode 100644 index 0000000..9bbf64b --- /dev/null +++ b/notify_templates/notify_discord.sh @@ -0,0 +1,25 @@ +### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. +# +# Copy/rename this file to notify.sh to enable the notification snippet. +# Required receiving services must already be set up. +# Modify to fit your setup - set DiscordWebhookUrl + +send_notification() { + [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") + UpdToString=$( printf '%s\\n' "${Updates[@]}" ) + + echo "$UpdToString" + FromHost=$(hostname) + + # platform specific notification code would go here + printf "\nSending Discord notification\n" + + # Setting the MessageBody variable here. + MessageBody="🐋 Containers on $FromHost with updates available: \n$UpdToString" + + # Modify to fit your setup: + DiscordWebhookUrl="PasteYourFullDiscordWebhookURL" + + MsgBody="{\"username\":\"$FromHost\",\"content\":\"$MessageBody\"}" + curl -sS -o /dev/null --fail -X POST -H "Content-Type: application/json" -d "$MsgBody" "$DiscordWebhookUrl" + diff --git a/notify_templates/notify_generic.sh b/notify_templates/notify_generic.sh index 9ff6226..e74d806 100644 --- a/notify_templates/notify_generic.sh +++ b/notify_templates/notify_generic.sh @@ -4,11 +4,13 @@ # generic sample, the "Hello World" of notification addons send_notification() { - Updates=("$@") - [ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" ) + [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") + UpdToString=$( printf '%s\\n' "${Updates[@]}" ) + FromHost=$(hostname) # platform specific notification code would go here printf "\n%bGeneric notification addon:%b" "$c_green" "$c_reset" - printf "\nThe following docker containers on %s need to be updated:\n%s\n" "$FromHost" "$UpdToString" + printf "\nThe following docker containers on %s need to be updated:\n" "$FromHost" + printf "$UpdToString" } diff --git a/notify_templates/notify_gotify.sh b/notify_templates/notify_gotify.sh index 5590ea2..b88f597 100644 --- a/notify_templates/notify_gotify.sh +++ b/notify_templates/notify_gotify.sh @@ -5,8 +5,8 @@ # Modify to fit your setup - set GotifyUrl and GotifyToken. send_notification() { - Updates=("$@") - [ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" ) + [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") + UpdToString=$( printf '%s\\n' "${Updates[@]}" ) FromHost=$(hostname) # platform specific notification code would go here @@ -14,7 +14,7 @@ send_notification() { # Setting the MessageTitle and MessageBody variable here. MessageTitle="${FromHost} - updates available." - MessageBody="Containers on ${FromHost} with updates available: ${UpdToString}" + printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString" # Modify to fit your setup: GotifyToken="Your Gotify token here" diff --git a/notify_templates/notify_matrix.sh b/notify_templates/notify_matrix.sh index b9af93a..acbcb34 100644 --- a/notify_templates/notify_matrix.sh +++ b/notify_templates/notify_matrix.sh @@ -5,8 +5,8 @@ # Modify to fit your setup - set MatrixServer, Room_id and AccessToken send_notification() { - Updates=("$@") - [ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" ) + [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") + UpdToString=$( printf '%s\\n' "${Updates[@]}" ) FromHost=$(hostname) # platform specific notification code would go here diff --git a/notify_templates/notify_ntfy-sh.sh b/notify_templates/notify_ntfy-sh.sh index dc9ded7..867dcaa 100644 --- a/notify_templates/notify_ntfy-sh.sh +++ b/notify_templates/notify_ntfy-sh.sh @@ -5,20 +5,15 @@ # Use your unique Topic Name in the URL below. send_notification() { -Updates=("$@") -[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" ) +[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") +UpdToString=$( printf '%s\\n' "${Updates[@]}" ) FromHost=$(hostname) printf "\nSending ntfy.sh notification\n" MessageTitle="$FromHost - updates available." # Setting the MessageBody variable here. -read -d '\n' MessageBody << __EOF -Containers on $FromHost with updates available: - -$UpdToString - -__EOF +printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString" # Modify to fit your setup: NtfyUrl="ntfy.sh/YourUniqueTopicName" diff --git a/notify_templates/notify_pushbullet.sh b/notify_templates/notify_pushbullet.sh index c422ad8..a07b604 100644 --- a/notify_templates/notify_pushbullet.sh +++ b/notify_templates/notify_pushbullet.sh @@ -6,8 +6,8 @@ # Modify to fit your setup - set Url and Token. send_notification() { -Updates=("$@") -[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" ) +[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") +UpdToString=$( printf '%s\\n' "${Updates[@]}" ) FromHost=$(hostname) # platform specific notification code would go here @@ -15,7 +15,7 @@ printf "\nSending pushbullet notification\n" MessageTitle="$FromHost - updates available." # Setting the MessageBody variable here. -MessageBody="Containers on $FromHost with updates available: $UpdToString" +printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString" # Modify to fit your setup: PushUrl="https://api.pushbullet.com/v2/pushes" diff --git a/notify_templates/notify_pushover.sh b/notify_templates/notify_pushover.sh index 85182b8..51cf036 100644 --- a/notify_templates/notify_pushover.sh +++ b/notify_templates/notify_pushover.sh @@ -6,8 +6,8 @@ # Modify to fit your setup - set Url and Token. send_notification() { - Updates=("$@") - [ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" ) + [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") + UpdToString=$( printf '%s\\n' "${Updates[@]}" ) FromHost=$(hostname) # platform specific notification code would go here @@ -15,7 +15,7 @@ send_notification() { MessageTitle="$FromHost - updates available." # Setting the MessageBody variable here. - MessageBody="Containers on $FromHost with updates available: $UpdToString" + printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString" # Modify to fit your setup: PushoverUrl="https://api.pushover.net/1/messages.json" diff --git a/notify_templates/notify_smtp.sh b/notify_templates/notify_smtp.sh index c6f3ba2..4d98afd 100644 --- a/notify_templates/notify_smtp.sh +++ b/notify_templates/notify_smtp.sh @@ -17,8 +17,8 @@ else fi send_notification() { -Updates=("$@") -[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" ) +[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") +UpdToString=$( printf '%s\\n' "${Updates[@]}" ) FromHost=$(hostname) # User variables: @@ -28,6 +28,8 @@ SubjectTag="dockcheck" printf "\nSending email notification.\n" +printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n\n$UpdToString" + $MailPkg $SendMailTo << __EOF From: "$FromHost" <$SendMailFrom> date:$(date -R) @@ -36,9 +38,7 @@ Subject: [$SubjectTag] Updates available on $FromHost Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit -The following containers on $FromHost have updates available: - -$UpdToString +$MessageBody __EOF } diff --git a/notify_templates/notify_telegram.sh b/notify_templates/notify_telegram.sh index 6183ccb..4772149 100644 --- a/notify_templates/notify_telegram.sh +++ b/notify_templates/notify_telegram.sh @@ -5,8 +5,8 @@ # Modify to fit your setup - set TelegramChatId and TelegramToken. send_notification() { - Updates=("$@") - [ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" ) + [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") + UpdToString=$( printf '%s\\n' "${Updates[@]}" ) FromHost=$(hostname) # platform specific notification code would go here