From ab3aaf1140cb2a06e1700ce22773ba8c5802aeb7 Mon Sep 17 00:00:00 2001 From: yoyoma2 Date: Mon, 1 Jan 2024 13:46:09 -0500 Subject: [PATCH 1/6] add a sample a DSM notification addon --- dockcheck.sh | 3 +++ notify_DSM.sh | 25 +++++++++++++++++++++++++ notify_generic.sh | 12 ++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 notify_DSM.sh create mode 100644 notify_generic.sh diff --git a/dockcheck.sh b/dockcheck.sh index 1d822a7..a797d99 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -14,6 +14,8 @@ ScriptWorkDir="$(dirname "$ScriptPath")" LatestRelease="$(curl -s -r 0-50 $RawUrl | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')" LatestChanges="$(curl -s -r 0-200 $RawUrl | sed -n "/ChangeNotes/s/### ChangeNotes: //p")" +[ -s $ScriptWorkDir/notify.sh ] && source $ScriptWorkDir/notify.sh + ### Help Function: Help() { echo "Syntax: dockcheck.sh [OPTION] [part of name to filter]" @@ -232,6 +234,7 @@ fi if [[ -n ${GotUpdates[*]} ]] ; then printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset" [[ -z "$AutoUp" ]] && options || printf "%s\n" "${GotUpdates[@]}" + [[ $(type -t send_notification) == function ]] && send_notification ${GotUpdates[@]} fi ### Optionally get updates if there's any diff --git a/notify_DSM.sh b/notify_DSM.sh new file mode 100644 index 0000000..bfb8cac --- /dev/null +++ b/notify_DSM.sh @@ -0,0 +1,25 @@ +# copy/rename this file to notify.sh to enable email notifications on synology DSM + +send_notification() { + +# change this to your usual destination for synology DSM notification emails +SendMailTo=me@mydomain.com +FromHost=$(hostname) + +printf "\nSending email notification\n" + +ssmtp $SendMailTo << __EOF +From: "$FromHost" <$SendMailTo> +date:$(date -R) +To: <$SendMailTo> +Subject: [diskstation] Some docker packages need to be updated +Content-Type: text/plain; charset=UTF-8; format=flowed +Content-Transfer-Encoding: 7bit + +The following docker packages on $FromHost need to be updated: + +$@ + + From $FromHost +__EOF +} \ No newline at end of file diff --git a/notify_generic.sh b/notify_generic.sh new file mode 100644 index 0000000..3276334 --- /dev/null +++ b/notify_generic.sh @@ -0,0 +1,12 @@ +# copy/rename this file to notify.sh to enable email/text notifications +# generic sample, the "Hello World" of notification addons + +send_notification() { + +FromHost=$(hostname) + +# platform specific notification code would go here +printf "\n%bGeneric notification addon:%b" "$c_green" "$c_reset" +printf "\nThe following docker packages on $FromHost need to be updated:\n$@\n" + +} \ No newline at end of file From 3f56af0c8a69337e9a0b500e1b3032e3311cfa78 Mon Sep 17 00:00:00 2001 From: mag37 Date: Wed, 3 Jan 2024 10:57:00 +0100 Subject: [PATCH 2/6] Update notify_generic.sh Set the passed in array to a variable. Made a printable string with newlines. Edited formatting some. --- notify_generic.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/notify_generic.sh b/notify_generic.sh index 3276334..2ef1d98 100644 --- a/notify_generic.sh +++ b/notify_generic.sh @@ -2,11 +2,11 @@ # generic sample, the "Hello World" of notification addons send_notification() { + Updates=("$@") + UpdToString=$( printf "%s\n" "${Updates[@]}" ) + FromHost=$(hostname) -FromHost=$(hostname) - -# platform specific notification code would go here -printf "\n%bGeneric notification addon:%b" "$c_green" "$c_reset" -printf "\nThe following docker packages on $FromHost need to be updated:\n$@\n" - -} \ No newline at end of file + # platform specific notification code would go here + printf "\n%bGeneric notification addon:%b" "$c_green" "$c_reset" + printf "\nThe following docker packages on %s need to be updated:\n%s\n" "$FromHost" "$UpdToString" +} From 342ff271ca9bf8a355366344c0c83662c949ce96 Mon Sep 17 00:00:00 2001 From: mag37 Date: Wed, 3 Jan 2024 11:01:41 +0100 Subject: [PATCH 3/6] Update notify_DSM.sh Added the passed array to a variable. Created printable string with newlines. --- notify_DSM.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/notify_DSM.sh b/notify_DSM.sh index bfb8cac..e6d6916 100644 --- a/notify_DSM.sh +++ b/notify_DSM.sh @@ -1,7 +1,8 @@ # copy/rename this file to notify.sh to enable email notifications on synology DSM send_notification() { - +Updates=("$@") +UpdToString=$( printf "%s\n" "${Updates[@]}" ) # change this to your usual destination for synology DSM notification emails SendMailTo=me@mydomain.com FromHost=$(hostname) @@ -18,8 +19,9 @@ Content-Transfer-Encoding: 7bit The following docker packages on $FromHost need to be updated: -$@ +"$UpdToString" + +From $FromHost - From $FromHost __EOF -} \ No newline at end of file +} From e15a8e9dbf5b0ef5d7380b6187de8eac9883b5f8 Mon Sep 17 00:00:00 2001 From: mag37 Date: Wed, 3 Jan 2024 11:06:37 +0100 Subject: [PATCH 4/6] Update notify_DSM.sh Added disclaimer + some more info --- notify_DSM.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/notify_DSM.sh b/notify_DSM.sh index e6d6916..e5283e1 100644 --- a/notify_DSM.sh +++ b/notify_DSM.sh @@ -1,4 +1,6 @@ -# copy/rename this file to notify.sh to enable email notifications on synology DSM +### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. +# Copy/rename this file to notify.sh to enable email notifications on synology DSM +# Modify to your liking - changing SendMailTo and Subject and content. send_notification() { Updates=("$@") From fc7b2888f1764cf4c3fda60eb39d10c0cfa6c109 Mon Sep 17 00:00:00 2001 From: mag37 Date: Wed, 3 Jan 2024 11:07:08 +0100 Subject: [PATCH 5/6] Update notify_generic.sh Added disclaimer. --- notify_generic.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notify_generic.sh b/notify_generic.sh index 2ef1d98..789930b 100644 --- a/notify_generic.sh +++ b/notify_generic.sh @@ -1,4 +1,5 @@ -# copy/rename this file to notify.sh to enable email/text notifications +### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. +# Copy/rename this file to notify.sh to enable email/text notifications # generic sample, the "Hello World" of notification addons send_notification() { From 2e620cd2c0dc2e246f33f6613aeddbe0cc761b22 Mon Sep 17 00:00:00 2001 From: yoyoma2 Date: Wed, 3 Jan 2024 12:41:18 -0500 Subject: [PATCH 6/6] final tweaks to notification addons --- notify_DSM.sh | 8 ++++---- notify_generic.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/notify_DSM.sh b/notify_DSM.sh index e5283e1..e2b3f2d 100644 --- a/notify_DSM.sh +++ b/notify_DSM.sh @@ -15,15 +15,15 @@ ssmtp $SendMailTo << __EOF From: "$FromHost" <$SendMailTo> date:$(date -R) To: <$SendMailTo> -Subject: [diskstation] Some docker packages need to be updated +Subject: [diskstation] Some docker containers need to be updated Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit -The following docker packages on $FromHost need to be updated: +The following docker containers on $FromHost need to be updated: -"$UpdToString" +$UpdToString -From $FromHost + From $FromHost __EOF } diff --git a/notify_generic.sh b/notify_generic.sh index 789930b..7c52c33 100644 --- a/notify_generic.sh +++ b/notify_generic.sh @@ -9,5 +9,5 @@ send_notification() { # platform specific notification code would go here printf "\n%bGeneric notification addon:%b" "$c_green" "$c_reset" - printf "\nThe following docker packages on %s need to be updated:\n%s\n" "$FromHost" "$UpdToString" + printf "\nThe following docker containers on %s need to be updated:\n%s\n" "$FromHost" "$UpdToString" }